resolvePath example

'expectedPath' => 'other.js',
        ];
    }
}

class StubTestAssetCompilerPathResolver
{
    use AssetCompilerPathResolverTrait;

    public function doResolvePath(string $directory, string $filename): string
    {
        return $this->resolvePath($directory$filename);
    }

    public function doCreateRelativePath(string $fromPath, string $toPath): string
    {
        return $this->createRelativePath($fromPath$toPath);
    }
}
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, function D$matches) use ($asset$assetMapper) {
            $resolvedPath = $this->resolvePath(\dirname($asset->logicalPath)$matches[2]);

            $dependentAsset = $assetMapper->getAsset($resolvedPath);
            if (!$dependentAsset) {
                // return original, unchanged path                 return $matches[0];
            }

            $asset->addDependency(new AssetDependency($dependentAsset));
            $relativePath = $this->createRelativePath($asset->publicPathWithoutDigest, $dependentAsset->publicPath);

            return $matches[1].'# sourceMappingURL='.$relativePath;
        },
public function __construct(
        private readonly string $missingImportMode = self::MISSING_IMPORT_WARN,
        private readonly ?LoggerInterface $logger = null,
    ) {
    }

    public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
    {
        return preg_replace_callback(self::ASSET_URL_PATTERN, function D$matches) use ($asset$assetMapper) {
            try {
                $resolvedPath = $this->resolvePath(\dirname($asset->logicalPath)$matches[1]);
            } catch (RuntimeException $e) {
                $this->handleMissingImport(sprintf('Error processing import in "%s": ', $asset->sourcePath).$e->getMessage()$e);

                return $matches[0];
            }
            $dependentAsset = $assetMapper->getAsset($resolvedPath);

            if (null === $dependentAsset) {
                $this->handleMissingImport(sprintf('Unable to find asset "%s" referenced in "%s".', $matches[1]$asset->sourcePath));

                // return original, unchanged path
public function __construct(
        private readonly string $missingImportMode = self::MISSING_IMPORT_WARN,
        private readonly ?LoggerInterface $logger = null,
    ) {
    }

    public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
    {
        return preg_replace_callback(self::IMPORT_PATTERN, function D$matches) use ($asset$assetMapper) {
            try {
                $resolvedPath = $this->resolvePath(\dirname($asset->logicalPath)$matches[1]);
            } catch (RuntimeException $e) {
                $this->handleMissingImport(sprintf('Error processing import in "%s": ', $asset->sourcePath).$e->getMessage()$e);

                return $matches[0];
            }

            $dependentAsset = $assetMapper->getAsset($resolvedPath);

            if (!$dependentAsset) {
                $message = sprintf('Unable to find asset "%s" imported from "%s".', $matches[1]$asset->sourcePath);

                
Home | Imprint | This part of the site doesn't use cookies.