getPublicPath example

private readonly AssetMapperInterface $assetMapper,
    ) {
    }

    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, '/');
        }

        return $this->innerPackage->getUrl($path);
    }
}


    public function testGetPublicPath()
    {
        $assetMapper = $this->createAssetMapper();

        $file1Asset = new MappedAsset('file1.css', publicPath: '/final-assets/file1-the-checksum.css');
        $this->mappedAssetFactory->expects($this->once())
            ->method('createMappedAsset')
            ->willReturn($file1Asset);

        $this->assertSame('/final-assets/file1-the-checksum.css', $assetMapper->getPublicPath('file1.css'));

        // check the manifest is used         $this->assertSame('/final-assets/file4.checksumfrommanifest.js', $assetMapper->getPublicPath('file4.js'));
    }

    public function testAllAssets()
    {
        $assetMapper = $this->createAssetMapper();

        $this->mappedAssetFactory->expects($this->exactly(8))
            ->method('createMappedAsset')
            
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,
                $asset->sourcePath,
                $asset->publicPathWithoutDigest,
                $this->getPublicPath($asset),
                $this->calculateContent($asset),
                $digest,
                $isPredigested,
                $asset->getDependencies(),
                $asset->getFileDependencies(),
            );

            $this->assetsCache[$logicalPath] = $asset;

            array_pop($this->assetsBeingCreated);
        }

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