Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

/**
Expand Down