33 lines
749 B
PHP
33 lines
749 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Lib\Sitemap;
|
|
|
|
use Illuminate\Support\Facades\Route;
|
|
use League\Uri\Contracts\UriInterface;
|
|
use League\Uri\Uri;
|
|
use Uwil\SitemapGenerator\Contracts\RouteLocalizerInterface;
|
|
|
|
final readonly class PrefixedRouteLocalizer implements RouteLocalizerInterface
|
|
{
|
|
private const string DEFAULT_LOCALE = 'fr';
|
|
|
|
public function canBeUsed(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function getLocalizedUrl(string $locale, string $routeName): ?UriInterface
|
|
{
|
|
$name = $locale === self::DEFAULT_LOCALE
|
|
? $routeName
|
|
: $locale . '.' . $routeName;
|
|
|
|
if (! Route::has($name)) {
|
|
return null;
|
|
}
|
|
|
|
return Uri::new(route($name));
|
|
}
|
|
}
|