Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4821b0e

Browse filesBrowse files
committed
[Asset] Fix JsonManifest when there is no dependency on HttpClient
1 parent d093475 commit 4821b0e
Copy full SHA for 4821b0e

File tree

Expand file treeCollapse file tree

2 files changed

+11
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-3
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php
+1-1Lines 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/VersionStrategy/JsonManifestVersionStrategy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Asset\VersionStrategy;
1313

14+
use Symfony\Component\HttpClient\HttpClient;
1415
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
1516
use Symfony\Contracts\HttpClient\HttpClientInterface;
1617

@@ -37,7 +38,14 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
3738
public function __construct(string $manifestPath, HttpClientInterface $httpClient = null)
3839
{
3940
$this->manifestPath = $manifestPath;
40-
$this->httpClient = $httpClient;
41+
42+
if (0 === strpos(parse_url($this->manifestPath, \PHP_URL_SCHEME), 'http')) {
43+
if (null === $this->httpClient && !class_exists(HttpClient::class)) {
44+
throw new \LogicException(sprintf('The "%s" class requires the "HttpClient" component. Try running "composer require symfony/http-client".', self::class));
45+
}
46+
47+
$this->httpClient = $httpClient ?? HttpClient::create();
48+
}
4149
}
4250

4351
/**
@@ -58,7 +66,7 @@ public function applyVersion(string $path)
5866
private function getManifestPath(string $path): ?string
5967
{
6068
if (null === $this->manifestData) {
61-
if (null !== $this->httpClient && 0 === strpos(parse_url($this->manifestPath, \PHP_URL_SCHEME), 'http')) {
69+
if (null !== $this->httpClient) {
6270
try {
6371
$this->manifestData = $this->httpClient->request('GET', $this->manifestPath, [
6472
'headers' => ['accept' => 'application/json'],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.