Skip to content

Commit 76e185f

Browse files
committed
[Asset] Fix JsonManifest when there is no dependency on HttpClient
1 parent d093475 commit 76e185f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
->abstract()
7878
->args([
7979
abstract_arg('manifest path'),
80-
service('http_client'),
80+
service('http_client')->nullOnInvalid(),
8181
])
8282

8383
->set('assets.remote_json_manifest_version_strategy', RemoteJsonManifestVersionStrategy::class)

src/Symfony/Component/Asset/Tests/VersionStrategy/JsonManifestVersionStrategyTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public function testManifestFileWithBadJSONThrowsException(JsonManifestVersionSt
6161
$strategy->getVersion('main.js');
6262
}
6363

64+
public function testRemoteManifestFileWithoutHttpClient()
65+
{
66+
$this->expectException(\LogicException::class);
67+
$this->expectExceptionMessage(sprintf('The "%s" class requires the "HttpClient" component. Try running "composer require symfony/http-client".', JsonManifestVersionStrategy::class));
68+
69+
new JsonManifestVersionStrategy('https://cdn.example.com/manifest.json');
70+
}
71+
6472
public function provideValidStrategies()
6573
{
6674
yield from $this->provideStrategies('manifest-valid.json');

src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
3737
public function __construct(string $manifestPath, HttpClientInterface $httpClient = null)
3838
{
3939
$this->manifestPath = $manifestPath;
40-
$this->httpClient = $httpClient;
40+
41+
if (0 === strpos(parse_url($this->manifestPath, \PHP_URL_SCHEME), 'http')) {
42+
if (null === $httpClient) {
43+
throw new \LogicException(sprintf('The "%s" class requires the "HttpClient" component. Try running "composer require symfony/http-client".', self::class));
44+
}
45+
46+
$this->httpClient = $httpClient;
47+
}
4148
}
4249

4350
/**
@@ -58,7 +65,7 @@ public function applyVersion(string $path)
5865
private function getManifestPath(string $path): ?string
5966
{
6067
if (null === $this->manifestData) {
61-
if (null !== $this->httpClient && 0 === strpos(parse_url($this->manifestPath, \PHP_URL_SCHEME), 'http')) {
68+
if (null !== $this->httpClient) {
6269
try {
6370
$this->manifestData = $this->httpClient->request('GET', $this->manifestPath, [
6471
'headers' => ['accept' => 'application/json'],

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