CircularAssetsException example

public function testErrorMessageAvoidsCircularException()
    {
        $assetMapper = $this->createMock(AssetMapperInterface::class);
        $assetMapper->expects($this->any())
            ->method('getAsset')
            ->willReturnCallback(function D$logicalPath) {
                if ('htmx' === $logicalPath) {
                    return null;
                }

                if ('htmx.js' === $logicalPath) {
                    throw new CircularAssetsException();
                }
            });

        $asset = new MappedAsset('htmx.js', '/path/to/app.js');
        $compiler = new JavaScriptImportPathCompiler();
        $content = '//** @type {import("./htmx").HtmxApi} */';
        $compiled = $compiler->compile($content$asset$assetMapper);
        // To form a good exception message, the compiler will check for the         // htmx.js asset, which will throw a CircularAssetsException. This         // should not be caught.         $this->assertSame($content$compiled);
    }
private array $fileContentsCache = [];

    public function __construct(
        private PublicAssetsPathResolverInterface $assetsPathResolver,
        private AssetMapperCompiler $compiler,
    ) {
    }

    public function createMappedAsset(string $logicalPath, string $sourcePath): ?MappedAsset
    {
        if (\in_array($logicalPath$this->assetsBeingCreated, true)) {
            throw new CircularAssetsException(sprintf('Circular reference detected while creating asset for "%s": "%s".', $logicalPathimplode(' -> ', $this->assetsBeingCreated).' -> '.$logicalPath));
        }

        if (!isset($this->assetsCache[$logicalPath])) {
            $this->assetsBeingCreated[] = $logicalPath;

            $asset = new MappedAsset($logicalPath$sourcePath$this->assetsPathResolver->resolvePublicPath($logicalPath));

            [$digest$isPredigested] = $this->getDigest($asset);

            $asset = new MappedAsset(
                $asset->logicalPath,
                
Home | Imprint | This part of the site doesn't use cookies.