[Asset] Fix JsonManifest when there is no dependency on HttpClient

This commit is contained in:
Maxime Hélias 2021-01-17 14:25:31 +01:00
parent d093475ce5
commit e0e691a074
3 changed files with 13 additions and 1 deletions

View File

@ -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)

View File

@ -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');

View File

@ -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));
}
}
/**