8000 Do not require `http_client` service · symfony/symfony@b5e39ec · GitHub
[go: up one dir, main page]

Skip to content

Commit b5e39ec

Browse files
ruudkfabpot
authored andcommitted
Do not require http_client service
This makes it possible to use AssetMapper with `http_client` disabled on the framework. Example: ```php $configurator->extension( 'framework', [ 'http_client' => [ 'enabled' => false, ], 'asset_mapper' => [ 'paths' => [ 'assets/', ], ], ] ); ```
1 parent 3bdbb07 commit b5e39ec

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
serv 8000 ice('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)
0