8000 [Asset] Fix JsonManifest when there is no dependency on HttpClient · symfony/symfony@9fc7f35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fc7f35

Browse files
committed
[Asset] Fix JsonManifest when there is no dependency on HttpClient
1 parent d093475 commit 9fc7f35

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines 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

Lines changed: 14 additions & 3 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

@@ -28,6 +29,7 @@
2829
class JsonManifestVersionStrategy implements VersionStrategyInterface
2930
{
3031
private $manifestPath;
32+
private $manifestUrl;
3133
private $manifestData;
3234
private $httpClient;
3335

@@ -37,7 +39,16 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
3739
public function __construct(string $manifestPath, HttpClientInterface $httpClient = null)
3840
{
3941
$this->manifestPath = $manifestPath;
40-
$this->httpClient = $httpClient;
42+
43+
if (0 === strpos(parse_url($this->manifestPath, \PHP_URL_SCHEME), 'http')) {
44+
$this->manifestUrl = $manifestPath;
45+
46+
if (null === $this->httpClient && !class_exists(HttpClient::class)) {
47+
throw new \LogicException(sprintf('The "%s" class requires the "HttpClient" component. Try running "composer require symfony/http-client".', self::class));
48+
}
49+
50+
$this->httpClient = $httpClient ?? HttpClient::create();
51+
}
4152
}
4253

4354
/**
@@ -58,9 +69,9 @@ public function applyVersion(string $path)
5869
private function getManifestPath(string $path): ?string
5970
{
6071
if (null === $this->manifestData) {
61-
if (null !== $this->httpClient && 0 === strpos(parse_url($this->manifestPath, \PHP_URL_SCHEME), 'http')) {
72+
if (null !== $this->manifestUrl) {
6273
try {
63-
$this->manifestData = $this->httpClient->request('GET', $this->manifestPath, [
74+
$this->manifestData = $this->httpClient->request('GET', $this->manifestUrl, [
6475
'headers' => ['accept' => 'application/json'],
6576
])->toArray();
6677
} catch (DecodingExceptionInterface $e) {

0 commit comments

Comments
 (0)
0