10000 bug #50294 [AssetMapper] Normalizing logicalPath to a getter like all… · symfony/symfony@46db9fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 46db9fb

Browse files
committed
bug #50294 [AssetMapper] Normalizing logicalPath to a getter like all other properties (weaverryan)
This PR was merged into the 6.3 branch. Discussion ---------- [AssetMapper] Normalizing logicalPath to a getter like all other properties | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | I'd say yes | New feature? | no | Deprecations? | no | Tickets | None | License | MIT | Doc PR | Still TODO Hi! In the original AssetMapper PR, I had one gone back and forth in `MappedAsset` using public properties vs getter methods. I eventually settled on getter methods, but I missed `$logicalPath`. This makes that consistent with the rest of the class, instead of being an odd exception. Commits ------- c3a0f5e [AssetMapper] Normalizing logicalPath to a getter like all other properties
2 parents 725fac4 + c3a0f5e commit 46db9fb

13 files changed

+25
-20
lines changed

src/Symfony/Component/AssetMapper/AssetMapper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function getPublicPath(string $logicalPath): ?string
131131
private function getDigest(MappedAsset $asset): array
132132
{
133133
// check for a pre-digested file
134-
if (1 === preg_match(self::PREDIGESTED_REGEX, $asset->logicalPath, $matches)) {
134+
if (1 === preg_match(self::PREDIGESTED_REGEX, $asset->getLogicalPath(), $matches)) {
135135
return [$matches[1], true];
136136
}
137137

@@ -143,14 +143,14 @@ private function getDigest(MappedAsset $asset): array
143143

144144
private function calculateContent(MappedAsset $asset): string
145145
{
146-
if (isset($this->fileContentsCache[$asset->logicalPath])) {
147-
return $this->fileContentsCache[$asset->logicalPath];
146+
if (isset($this->fileContentsCache[$asset->getLogicalPath()])) {
147+
return $this->fileContentsCache[$asset->getLogicalPath()];
148148
}
149149

150150
$content = file_get_contents($asset->getSourcePath());
151151
$content = $this->compiler->compile($content, $asset, $this);
152152

153-
$this->fileContentsCache[$asset->logicalPath] = $content;
153+
$this->fileContentsCache[$asset->getLogicalPath()] = $content;
154154

155155
return $content;
156156
}

src/Symfony/Component/AssetMapper/Command/AssetMapperCompileCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function createManifestAndWriteFiles(SymfonyStyle $io, string $publicDir
129129
}
130130

131131
$this->filesystem->dumpFile($targetPath, $asset->getContent());
132-
$manifest[$asset->logicalPath] = $asset->getPublicPath();
132+
$manifest[$asset->getLogicalPath()] = $asset->getPublicPath();
133133
}
134134
ksort($manifest);
135135

src/Symfony/Component/AssetMapper/Command/DebugAssetMapperCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7070

7171
$rows = [];
7272
foreach ($allAssets as $asset) {
73-
$logicalPath = $asset->logicalPath;
73+
$logicalPath = $asset->getLogicalPath();
7474
$sourcePath = $this->relativizePath($asset->getSourcePath());
7575

7676
if (!$input->getOption('full')) {

src/Symfony/Component/AssetMapper/Compiler/CssAssetUrlCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(private readonly bool $strictMode = true)
3535
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
3636
{
3737
return preg_replace_callback(self::ASSET_URL_PATTERN, function ($matches) use ($asset, $assetMapper) {
38-
$resolvedPath = $this->resolvePath(\dirname($asset->logicalPath), $matches[1]);
38+
$resolvedPath = $this->resolvePath(\dirname($asset->getLogicalPath()), $matches[1]);
3939
$dependentAsset = $assetMapper->getAsset($resolvedPath);
4040

4141
if (null === $dependentAsset) {

src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(private readonly bool $strictMode = true)
3535
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
3636
{
3737
return preg_replace_callback(self::IMPORT_PATTERN, function ($matches) use ($asset, $assetMapper) {
38-
$resolvedPath = $this->resolvePath(\dirname($asset->logicalPath), $matches[1]);
38+
$resolvedPath = $this->resolvePath(\dirname($asset->getLogicalPath()), $matches[1]);
3939

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

src/Symfony/Component/AssetMapper/Compiler/SourceMappingUrlsCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function supports(MappedAsset $asset): bool
3535
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
3636
{
3737
return preg_replace_callback(self::SOURCE_MAPPING_PATTERN, function ($matches) use ($asset, $assetMapper) {
38-
$resolvedPath = $this->resolvePath(\dirname($asset->logicalPath), $matches[2]);
38+
$resolvedPath = $this->resolvePath(\dirname($asset->getLogicalPath()), $matches[2]);
3939

4040
$dependentAsset = $assetMapper->getAsset($resolvedPath);
4141
if (!$dependentAsset) {

src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private function requirePackages(array $packagesToRequire, array &$importMapEntr
281281

282282
throw new \LogicException(sprintf('The package was downloaded to "%s", but this path does not appear to be in any of your asset paths.', $vendorPath));
283283
}
284-
$path = $mappedAsset->logicalPath;
284+
$path = $mappedAsset->getLogicalPath();
285285
}
286286

287287
$newEntry = new ImportMapEntry($importName, $path, $url, $download, $preload);
@@ -395,7 +395,7 @@ private function convertEntriesToImports(array $entries): array
395395
$dependencyImportMapEntries = array_map(function (AssetDependency $dependency) {
396396
return new ImportMapEntry(
397397
$dependency->asset->getPublicPathWithoutDigest(),
398-
$dependency->asset->logicalPath,
398+
$dependency->asset->getLogicalPath(),
399399
preload: !$dependency->isLazy,
400400
);
401401
}, $dependencies);

src/Symfony/Component/AssetMapper/MappedAsset.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ final class MappedAsset
3232
/** @var AssetDependency[] */
3333
private array $dependencies = [];
3434

35-
public function __construct(public readonly string $logicalPath)
35+
public function __construct(private readonly string $logicalPath)
3636
{
3737
}
3838

39+
public function getLogicalPath(): string
40+
{
41+
return $this->logicalPath;
42+
}
43+
3944
public function getPublicPath(): string
4045
{
4146
return $this->publicPath;

src/Symfony/Component/AssetMapper/Tests/AssetMapperTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testGetAsset()
3030
$this->assertNull($assetMapper->getAsset('non-existent.js'));
3131

3232
$asset = $assetMapper->getAsset('file2.js');
33-
$this->assertSame('file2.js', $asset->logicalPath);
33+
$this->assertSame('file2.js', $asset->getLogicalPath());
3434
$this->assertMatchesRegularExpression('/^\/final-assets\/file2-[a-zA-Z0-9]{7,128}\.js$/', $asset->getPublicPath());
3535
$this->assertSame('/final-assets/file2.js', $asset->getPublicPathWithoutDigest());
3636
}
@@ -39,7 +39,7 @@ public function testGetAssetRespectsPreDigestedPaths()
3939
{
4040
$assetMapper = $this->createAssetMapper();
4141
$asset = $assetMapper->getAsset('already-abcdefVWXYZ0123456789.digested.css');
42-
$this->assertSame('already-abcdefVWXYZ0123456789.digested.css', $asset->logicalPath);
42+
$this->assertSame('already-abcdefVWXYZ0123456789.digested.css', $asset->getLogicalPath());
4343
$this->assertSame('/final-assets/already-abcdefVWXYZ0123456789.digested.css', $asset->getPublicPath());
4444
// for pre-digested files, the digest *is* part of the public path
4545
$this->assertSame('/final-assets/already-abcdefVWXYZ0123456789.digested.css', $asset->getPublicPathWithoutDigest());
@@ -73,7 +73,7 @@ public function testGetAssetFromFilesystemPath()
7373
{
7474
$assetMapper = $this->createAssetMapper();
7575
$asset = $assetMapper->getAssetFromSourcePath(__DIR__.'/fixtures/dir1/file1.css');
76-
$this->assertSame('file1.css', $asset->logicalPath);
76+
$this->assertSame('file1.css', $asset->getLogicalPath());
7777
}
7878

7979
public function testGetAssetWithContentBasic()
@@ -124,7 +124,7 @@ public function supports(MappedAsset $asset): bool
124124

125125
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
126126
{
127-
if ('subdir/file6.js' === $asset->logicalPath) {
127+
if ('subdir/file6.js' === $asset->getLogicalPath()) {
128128
return $content.'/* compiled */';
129129
}
130130

src/Symfony/Component/AssetMapper/Tests/Compiler/CssAssetUrlCompilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCompile(string $sourceLogicalName, string $input, string $ex
2828
$asset = new MappedAsset($sourceLogicalName);
2929
$asset->setPublicPathWithoutDigest('/assets/'.$sourceLogicalName);
3030
$this->assertSame($expectedOutput, $compiler->compile($input, $asset, $this->createAssetMapper()));
31-
$assetDependencyLogicalPaths = array_map(fn (AssetDependency $dependency) => $dependency->asset->logicalPath, $asset->getDependencies());
31+
$assetDependencyLogicalPaths = array_map(fn (AssetDependency $dependency) => $dependency->asset->getLogicalPath(), $asset->getDependencies());
3232
$this->assertSame($expectedDependencies, $assetDependencyLogicalPaths);
3333
}
3434

src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testCompile(string $sourceLogicalName, string $input, array $exp
3131
$this->assertSame($input, $compiler->compile($input, $asset, $this->createAssetMapper()));
3232
$actualDependencies = [];
3333
foreach ($asset->getDependencies() as $dependency) {
34-
$actualDependencies[$dependency->asset->logicalPath] = $dependency->isLazy;
34+
$actualDependencies[$dependency->asset->getLogicalPath()] = $dependency->isLazy;
3535
}
3636
$this->assertEquals($expectedDependencies, $actualDependencies);
3737
}

src/Symfony/Component/AssetMapper/Tests/Compiler/SourceMappingUrlsCompilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testCompile(string $sourceLogicalName, string $input, string $ex
5656
$asset = new MappedAsset($sourceLogicalName);
5757
$asset->setPublicPathWithoutDigest('/assets/'.$sourceLogicalName);
5858
$this->assertSame($expectedOutput, $compiler->compile($input, $asset, $assetMapper));
59-
$assetDependencyLogicalPaths = array_map(fn (AssetDependency $dependency) => $dependency->asset->logicalPath, $asset->getDependencies());
59+
$assetDependencyLogicalPaths = array_map(fn (AssetDependency $dependency) => $dependency->asset->getLogicalPath(), $asset->getDependencies());
6060
$this->assertSame($expectedDependencies, $assetDependencyLogicalPaths);
6161
}
6262

src/Symfony/Component/AssetMapper/Tests/MappedAssetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testGetLogicalPath()
2020
{
2121
$asset = new MappedAsset('foo.css');
2222

23-
$this->assertSame('foo.css', $asset->logicalPath);
23+
$this->assertSame('foo.css', $asset->getLogicalPath());
2424
}
2525

2626
public function testGetPublicPath()

0 commit comments

Comments
 (0)
0