Skip to content

Commit ce00298

Browse files
committed
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 cdbc32a commit ce00298

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)
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