/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/AssetMapper/Compiler/SourceMappingUrlsCompiler.php
49 строк
2 KB
Dariusz Ruminski
PHP CS Fixer: enable static_lambda
19 дек 2025, 11:33
19 дек 2025, 11:33
3274fbc
Код
Авторство
О чём код?
<?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\Compiler; use Symfony\Component\AssetMapper\AssetMapperInterface; use Symfony\Component\AssetMapper\MappedAsset; use Symfony\Component\Filesystem\Path; /** * Rewrites already-existing source map URLs to their final digested path. * * Originally sourced from https://github.com/rails/propshaft/blob/main/lib/propshaft/compiler/source_mapping_urls.rb */ final class SourceMappingUrlsCompiler implements AssetCompilerInterface { private const SOURCE_MAPPING_PATTERN = '{^(//|/\*)# sourceMappingURL=(.+\.map)}m'; public function supports(MappedAsset $asset): bool { return \in_array($asset->publicExtension, ['css', 'js'], true); } public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string { return preg_replace_callback(self::SOURCE_MAPPING_PATTERN, static function ($matches) use ($asset, $assetMapper) { $resolvedPath = Path::join(\dirname($asset->sourcePath), $matches[2]); $dependentAsset = $assetMapper->getAssetFromSourcePath($resolvedPath); if (!$dependentAsset) { // return original, unchanged path return $matches[0]; } $asset->addDependency($dependentAsset); $relativePath = Path::makeRelative($dependentAsset->publicPath, \dirname($asset->publicPathWithoutDigest)); return $matches[1].'# sourceMappingURL='.$relativePath; }, $content); } }