8000 Changing arg order - eases cross-version compat · symfony/symfony@df81762 · GitHub
[go: up one dir, main page]

Skip to content

Commit df81762

Browse files
committed
Changing arg order - eases cross-version compat
1 parent a340568 commit df81762

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,8 @@ private function registerAssetMapperConfiguration(array $config, ContainerBuilde
13001300
$container->removeDefinition('asset_mapper.dev_server_subscriber');
13011301
} else {
13021302
$container->getDefinition('asset_mapper.dev_server_subscriber')
1303-
->setArgument(2, $config['public_prefix'])
1304-
->setArgument(3, $config['extensions']);
1303+
->setArgument(1, $config['public_prefix'])
1304+
->setArgument(2, $config['extensions']);
13051305
}
13061306

13071307
$container->getDefinition('asset_mapper.compiler.css_asset_url_compiler')

src/Symfony/Bundle/FrameworkBundle/Resources/config/asset_mapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
->set('asset_mapper.dev_server_subscriber', AssetMapperDevServerSubscriber::class)
8282
->args([
8383
service('asset_mapper'),
84-
service('cache.asset_mapper'),
8584
abstract_arg('asset public prefix'),
8685
abstract_arg('extensions map'),
86+
service('cache.asset_mapper'),
8787
])
8888
->tag('kernel.event_subscriber', ['event' => RequestEvent::class])
8989

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testAssetMapper()
8282
$this->assertSame('/assets_path/', $definition->getArgument(1));
8383

8484
$definition = $container->getDefinition('asset_mapper.dev_server_subscriber');
85-
$this->assertSame(['zip' => 'application/zip'], $definition->getArgument(3));
85+
$this->assertSame(['zip' => 'application/zip'], $definition->getArgument(2));
8686

8787
$definition = $container->getDefinition('asset_mapper.importmap.renderer');
8888
$this->assertSame(['data-turbo-track' => 'reload'], $definition->getArgument(3));

src/Symfony/Component/AssetMapper/AssetMapperDevServerSubscriber.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ final class AssetMapperDevServerSubscriber implements EventSubscriberInterface
103103

104104
public function __construct(
105105
private readonly AssetMapperInterface $assetMapper,
106-
private readonly CacheItemPoolInterface $cacheMapCache,
107106
string $publicPrefix = '/assets/',
108107
array $extensionsMap = [],
108+
private readonly ?CacheItemPoolInterface $cacheMapCache = null,
109109
) {
110110
$this->publicPrefix = rtrim($publicPrefix, '/').'/';
111111
$this->extensionsMap = array_merge(self::EXTENSIONS_MAP, $extensionsMap);
@@ -159,11 +159,14 @@ private function getMediaType(string $path): ?string
159159

160160
private function findAssetFromCache(string $pathInfo): ?MappedAsset
161161
{
162-
$cachedAsset = $this->cacheMapCache->getItem(hash('xxh128', $pathInfo));
163-
$asset = $cachedAsset->isHit() ? $this->assetMapper->getAsset($cachedAsset->get()) : null;
162+
$cachedAsset = null;
163+
if (null !== $this->cacheMapCache) {
164+
$cachedAsset = $this->cacheMapCache->getItem(hash('xxh128', $pathInfo));
165+
$asset = $cachedAsset->isHit() ? $this->assetMapper->getAsset($cachedAsset->get()) : null;
164166

165-
if (null !== $asset && $asset->getPublicPath() === $pathInfo) {
166-
return $asset;
167+
if (null !== $asset && $asset->getPublicPath() === $pathInfo) {
168+
return $asset;
169+
}
167170
}
168171

169172
// we did not find a match
@@ -179,8 +182,10 @@ private function findAssetFromCache(string $pathInfo): ?MappedAsset
179182
return null;
180183
}
181184

182-
$cachedAsset->set($asset->getLogicalPath());
183-
$this->cacheMapCache->save($cachedAsset);
185+
if (null !== $cachedAsset) {
186+
$cachedAsset->set($asset->getLogicalPath());
187+
$this->cacheMapCache->save($cachedAsset);
188+
}
184189

185190
return $asset;
186191
}

0 commit comments

Comments
 (0)
0