/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/AssetMapper/MapperAwareAssetPackage.php
62 строки
2 KB
Eissa Soubhi
[AssetMapper] Include the front controller in dev asset URLs
11 авг 2026, 11:33
11 авг 2026, 11:33
c5d90e0
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\AssetMapper; use Symfony\Component\Asset\PackageInterface; use Symfony\Component\HttpFoundation\RequestStack; /** * Decorates asset packages to support resolving assets from the asset mapper. * * @author Ryan Weaver <ryan@symfonycasts.com> */ final class MapperAwareAssetPackage implements PackageInterface { private readonly ?string $devServerPrefix; /** * @param string|null $devServerPublicPrefix The public prefix served by AssetMapperDevServerSubscriber, null when it is disabled */ public function __construct( private readonly PackageInterface $innerPackage, private readonly AssetMapperInterface $assetMapper, private readonly ?RequestStack $requestStack = null, ?string $devServerPublicPrefix = null, ) { $this->devServerPrefix = null === $devServerPublicPrefix ? null : '/'.trim($devServerPublicPrefix, '/').'/'; } public function getVersion(string $path): string { return $this->innerPackage->getVersion($path); } public function getUrl(string $path): string { $publicPath = $this->assetMapper->getPublicPath($path); if ($publicPath) { $path = ltrim($publicPath, '/'); } if (null !== $this->devServerPrefix && str_starts_with('/'.$path, $this->devServerPrefix)) { // the dev server serves those assets through the kernel, so the front controller must be part of the URL $request = $this->requestStack?->getMainRequest(); $frontController = $request ? trim(substr($request->getBaseUrl(), \strlen($request->getBasePath())), '/') : ''; if ('' !== $frontController) { $path = $frontController.'/'.$path; } } return $this->innerPackage->getUrl($path); } }