diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php index db889670c2..eb25977ec8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php @@ -77,7 +77,7 @@ return static function (ContainerConfigurator $container) { ->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 b62a802beb..57f1618dda 100644 --- a/src/Symfony/Component/Asset/Tests/VersionStrategy/JsonManifestVersionStrategyTest.php +++ b/src/Symfony/Component/Asset/Tests/VersionStrategy/JsonManifestVersionStrategyTest.php @@ -61,6 +61,14 @@ class JsonManifestVersionStrategyTest extends TestCase $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 b0ea4d1b95..e72cdc1f17 100644 --- a/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php +++ b/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php @@ -38,6 +38,10 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface { $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)); + } } /**