Skip to content

Commit 7bdfccf

Browse files
bug #57533 [FrameworkBundle] Throw runtime exception when trying to use asset-mapper while http-client is disabled (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] Throw runtime exception when trying to use asset-mapper while http-client is disabled | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Replaces #57219 and #57073 Commits ------- df133a9 [FrameworkBundle] Throw runtime exception when trying to use asset-mapper while http-client is disabled
2 parents 28ad602 + df133a9 commit 7bdfccf

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public function load(array $configs, ContainerBuilder $container)
349349
throw new LogicException('AssetMapper support cannot be enabled as the AssetMapper component is not installed. Try running "composer require symfony/asset-mapper".');
350350
}
351351

352-
$this->registerAssetMapperConfiguration($config['asset_mapper'], $container, $loader, $this->readConfigEnabled('assets', $container, $config['assets']));
352+
$this->registerAssetMapperConfiguration($config['asset_mapper'], $container, $loader, $this->readConfigEnabled('assets', $container, $config['assets']), $this->readConfigEnabled('http_client', $container, $config['http_client']));
353353
} else {
354354
$container->removeDefinition('cache.asset_mapper');
355355
}
@@ -1330,12 +1330,14 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
13301330
}
13311331
}
13321332

1333-
private function registerAssetMapperConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader, bool $assetEnabled): void
1333+
private function registerAssetMapperConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader, bool $assetEnabled, bool $httpClientEnabled): void
13341334
{
13351335
$loader->load('asset_mapper.php');
13361336

1337-
if (!$assetEnabled) {
1338-
$container->removeDefinition('asset_mapper.asset_package');
1337+
if (!$httpClientEnabled) {
1338+
$container->register('asset_mapper.http_client', HttpClientInterface::class)
1339+
->addTag('container.error')
1340+
->addError('You cannot use the AssetMapper integration since the HttpClient component is not enabled. Try enabling the "framework.http_client" config option.');
13391341
}
13401342

13411343
$paths = $config['paths'];

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
])
5555
->alias(AssetMapperInterface::class, 'asset_mapper')
5656

57+
->alias('asset_mapper.http_client', 'http_client')
58+
5759
->set('asset_mapper.mapped_asset_factory', MappedAssetFactory::class)
5860
->args([
5961
service('asset_mapper.public_assets_path_resolver'),
@@ -197,7 +199,7 @@
197199
])
198200

199201
->set('asset_mapper.importmap.resolver', JsDelivrEsmResolver::class)
200-
->args([service('http_client')])
202+
->args([service('asset_mapper.http_client')])
201203

202204
->set('asset_mapper.importmap.renderer', ImportMapRenderer::class)
203205
->args([
@@ -212,12 +214,12 @@
212214
->set('asset_mapper.importmap.auditor', ImportMapAuditor::class)
213215
->args([
214216
service('asset_mapper.importmap.config_reader'),
215-
service('http_client'),
217+
service('asset_mapper.http_client'),
216218
])
217219
->set('asset_mapper.importmap.update_checker', ImportMapUpdateChecker::class)
218220
->args([
219221
service('asset_mapper.importmap.config_reader'),
220-
service('http_client'),
222+
service('asset_mapper.http_client'),
221223
])
222224

223225
->set('asset_mapper.importmap.command.require', ImportMapRequireCommand::class)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy