Laravel 9:如何扩展UrlGenerator核心类



我试图扩展UrlGenerator类,以便添加自定义temporaryTenantSignedRoute,然后像这样使用它:

Url::temporaryTenantSignedRoute(...)

我创建了一个类CustomUrlGenerator:

<?php
namespace DomainSharedSupport;
use IlluminateSupportArr;
use IlluminateRoutingUrlGenerator;
class CustomUrlGenerator extends UrlGenerator
{ 
public function temporaryTenantSignedRoute($name, $expiration, $parameters = [], $absolute = true)
{
return $this->tenantSignedRoute($name, $parameters, $expiration, $absolute);
}   
public function tenantSignedRoute($name, $parameters = [], $expiration = null, $absolute = true)
{
$this->ensureSignedRouteParametersAreNotReserved(
$parameters = Arr::wrap($parameters)
);
if ($expiration) {
$parameters = $parameters + ['expires' => $this->availableAt($expiration)];
}
ksort($parameters);
$key = call_user_func($this->keyResolver);
return tenant_route(tenant()->domain, $name, $parameters + [
'signature' => hash_hmac('sha256', tenant_route(tenant()->domain, $name, $parameters, $absolute), $key),
], $absolute);
}
}

我在AppServiceProvider中注册了它,像这样:

$this->app->bind(UrlGenerator::class, CustomUrlGenerator::class);

但是它不工作!请帮忙好吗?由于

适合我

$this->app->extend('url', function (IlluminateRoutingUrlGenerator $urlGenerator) {
return new AppHelpersUrlGenerator(
$this->app->make('router')->getRoutes(),
$urlGenerator->getRequest(),
$this->app->make('config')->get('app.asset_url')
);
});

相关内容

  • 没有找到相关文章

最新更新