8000 bug #39865 [Asset] Fix JsonManifest when there is no dependency on Ht… · symfony/symfony@2941951 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2941951

Browse files
committed
bug #39865 [Asset] Fix JsonManifest when there is no dependency on HttpClient (maxhelias)
This PR was merged into the 5.3-dev branch. Discussion ---------- [Asset] Fix JsonManifest when there is no dependency on HttpClient | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | yes | New feature? |no | Deprecations? |no | Tickets | - | License | MIT | Doc PR | - Recently on my project, I don't have any more dependency on HttpClient and the tests on the 5.x I have this error : <img width="678" alt="Capture d’écran 2021-01-17 à 14 26 16" src="https://user-images.githubusercontent.com/12966574/104844393-45a7d180-58d0-11eb-870b-ad4b7b78d092.png"> ~~I think this should also be the case for the RemoteJsonManifestVersionStrategy but I don't have a use case to try it.~~ It's related to #39484 Commits ------- e0e691a [Asset] Fix JsonManifest when there is no dependency on HttpClient
2 parents d093475 + e0e691a commit 2941951

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