Skip to content

Commit e96c325

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

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
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 need an HTTP client to use a remote manifest. 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function __construct(string $manifestPath, HttpClientInterface $httpClien
3838
{
3939
$this->manifestPath = $manifestPath;
4040
$this->httpClient = $httpClient;
41+
42+
if (null === $this->httpClient && 0 === strpos(parse_url($this->manifestPath, \PHP_URL_SCHEME), 'http')) {
43+
throw new \LogicException(sprintf('The "%s" class need an HTTP client to use a remote manifest. Try running "composer require symfony/http-client".', self::class));
44+
}
4145
}
4246

4347
/**

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