Skip to content

[FrameworkBundle] Throw runtime exception when trying to use asset-mapper while http-client is disabled #57533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function load(array $configs, ContainerBuilder $container)
throw new LogicException('AssetMapper support cannot be enabled as the AssetMapper component is not installed. Try running "composer require symfony/asset-mapper".');
}

$this->registerAssetMapperConfiguration($config['asset_mapper'], $container, $loader, $this->readConfigEnabled('assets', $container, $config['assets']));
$this->registerAssetMapperConfiguration($config['asset_mapper'], $container, $loader, $this->readConfigEnabled('assets', $container, $config['assets']), $this->readConfigEnabled('http_client', $container, $config['http_client']));
} else {
$container->removeDefinition('cache.asset_mapper');
}
Expand Down Expand Up @@ -1330,12 +1330,14 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
}
}

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

if (!$assetEnabled) {
$container->removeDefinition('asset_mapper.asset_package');
Comment on lines -1337 to -1338
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this just broke something on 6.4. I'm having this error : The service "asset_mapper.asset_package" has a dependency on a non-existent service "assets._default_package".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #57589

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

$paths = $config['paths'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
])
->alias(AssetMapperInterface::class, 'asset_mapper')

->alias('asset_mapper.http_client', 'http_client')

->set('asset_mapper.mapped_asset_factory', MappedAssetFactory::class)
->args([
service('asset_mapper.public_assets_path_resolver'),
Expand Down Expand Up @@ -197,7 +199,7 @@
])

->set('asset_mapper.importmap.resolver', JsDelivrEsmResolver::class)
->args([service('http_client')])
->args([service('asset_mapper.http_client')])

->set('asset_mapper.importmap.renderer', ImportMapRenderer::class)
->args([
Expand All @@ -212,12 +214,12 @@
->set('asset_mapper.importmap.auditor', ImportMapAuditor::class)
->args([
service('asset_mapper.importmap.config_reader'),
service('http_client'),
service('asset_mapper.http_client'),
])
->set('asset_mapper.importmap.update_checker', ImportMapUpdateChecker::class)
->args([
service('asset_mapper.importmap.config_reader'),
service('http_client'),
service('asset_mapper.http_client'),
])

->set('asset_mapper.importmap.command.require', ImportMapRequireCommand::class)
Expand Down
Loading