diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php index db889670c251c..eb25977ec8a72 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php @@ -77,7 +77,7 @@ ->abstract() ->args([ abstract_arg('manifest path'), - service('http_client'), + service('http_client')->nullOnInvalid(), ]) ->set('assets.remote_json_manifest_version_strategy', RemoteJsonManifestVersionStrategy::class) diff --git a/src/Symfony/Component/Asset/Tests/VersionStrategy/JsonManifestVersionStrategyTest.php b/src/Symfony/Component/Asset/Tests/VersionStrategy/JsonManifestVersionStrategyTest.php index b62a802beba2c..57f1618dda30c 100644 --- a/src/Symfony/Component/Asset/Tests/VersionStrategy/JsonManifestVersionStrategyTest.php +++ b/src/Symfony/Component/Asset/Tests/VersionStrategy/JsonManifestVersionStrategyTest.php @@ -61,6 +61,14 @@ public function testManifestFileWithBadJSONThrowsException(JsonManifestVersionSt $strategy->getVersion('main.js'); } + public function testRemoteManifestFileWithoutHttpClient() + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage(sprintf('The "%s" class needs an HTTP client to use a remote manifest. Try running "composer require symfony/http-client".', JsonManifestVersionStrategy::class)); + + new JsonManifestVersionStrategy('https://cdn.example.com/manifest.json'); + } + public function provideValidStrategies() { yield from $this->provideStrategies('manifest-valid.json'); diff --git a/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php b/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php index b0ea4d1b95843..e72cdc1f174a6 100644 --- a/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php +++ b/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php @@ -38,6 +38,10 @@ public function __construct(string $manifestPath, HttpClientInterface $httpClien { $this->manifestPath = $manifestPath; $this->httpClient = $httpClient; + + if (null === $this->httpClient && 0 === strpos(parse_url($this->manifestPath, \PHP_URL_SCHEME), 'http')) { + 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)); + } } /**