Skip to content

Commit 66b57c9

Browse files
committed
feature symfony#57073 [AssetMapper][FrameworkBundle] Do not require http_client service (ruudk)
This PR was submitted for the 6.4 branch but it was merged into the 7.2 branch instead. Discussion ---------- [AssetMapper][FrameworkBundle] Do not require `http_client` service | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? |no | Deprecations? |no | Issues | | License | MIT This makes it possible to use AssetMapper with `http_client` disabled on the framework. It will automatically instantiate the required HttpClient. Example: ```php $configurator->extension( 'framework', [ 'http_client' => [ 'enabled' => false, ], 'asset_mapper' => [ 'paths' => [ 'assets/', ], ], ] ); ``` This fixes the following problems: > The service "asset_mapper.importmap.resolver" has a dependency on a non-existent service "http_client". > The service "asset_mapper.importmap.auditor" has a dependency on a non-existent service "http_client". > The service "asset_mapper.importmap.update_checker" has a dependency on a non-existent service "http_client". Commits ------- b5e39ec Do not require `http_client` service
2 parents 3bdbb07 + b5e39ec commit 66b57c9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
])
198198

199199
->set('asset_mapper.importmap.resolver', JsDelivrEsmResolver::class)
200-
->args([service('http_client')])
200+
->args([service('http_client')->nullOnInvalid()])
201201

202202
->set('asset_mapper.importmap.renderer', ImportMapRenderer::class)
203203
->args([
@@ -212,12 +212,12 @@
212212
->set('asset_mapper.importmap.auditor', ImportMapAuditor::class)
213213
->args([
214214
service('asset_mapper.importmap.config_reader'),
215-
service('http_client'),
215+
service('http_client')->nullOnInvalid(),
216216
])
217217
->set('asset_mapper.importmap.update_checker', ImportMapUpdateChecker::class)
218218
->args([
219219
service('asset_mapper.importmap.config_reader'),
220-
service('http_client'),
220+
service('http_client')->nullOnInvalid(),
221221
])
222222

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

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111

1212
namespace Symfony\Component\AssetMapper\ImportMap;
1313

14+
use Symfony\Component\HttpClient\HttpClient;
1415
use Symfony\Contracts\HttpClient\HttpClientInterface;
1516

1617
class ImportMapUpdateChecker
1718
{
1819
private const URL_PACKAGE_METADATA = 'https://registry.npmjs.org/%s';
1920

21+
private readonly HttpClientInterface $httpClient;
22+
2023
public function __construct(
2124
private readonly ImportMapConfigReader $importMapConfigReader,
22-
private readonly HttpClientInterface $httpClient,
25+
?HttpClientInterface $httpClient = null,
2326
) {
27+
$this->httpClient = $httpClient ?? HttpClient::create();
2428
}
2529

2630
/**

0 commit comments

Comments
 (0)