11
11
12
12
namespace Symfony \Component \Asset \VersionStrategy ;
13
13
14
+ use Symfony \Component \HttpClient \HttpClient ;
14
15
use Symfony \Contracts \HttpClient \Exception \DecodingExceptionInterface ;
15
16
use Symfony \Contracts \HttpClient \HttpClientInterface ;
16
17
28
29
class JsonManifestVersionStrategy implements VersionStrategyInterface
29
30
{
30
31
private $ manifestPath ;
32
+ private $ manifestUrl ;
31
33
private $ manifestData ;
32
34
private $ httpClient ;
33
35
@@ -37,7 +39,16 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
37
39
public function __construct (string $ manifestPath , HttpClientInterface $ httpClient = null )
38
40
{
39
41
$ 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
+ }
41
52
}
42
53
43
54
/**
@@ -58,9 +69,9 @@ public function applyVersion(string $path)
58
69
private function getManifestPath (string $ path ): ?string
59
70
{
60
71
if (null === $ this ->manifestData ) {
61
- if (null !== $ this ->httpClient && 0 === strpos ( parse_url ( $ this -> manifestPath , \ PHP_URL_SCHEME ), ' http ' ) ) {
72
+ if (null !== $ this ->manifestUrl ) {
62
73
try {
63
- $ this ->manifestData = $ this ->httpClient ->request ('GET ' , $ this ->manifestPath , [
74
+ $ this ->manifestData = $ this ->httpClient ->request ('GET ' , $ this ->manifestUrl , [
64
75
'headers ' => ['accept ' => 'application/json ' ],
65
76
])->toArray ();
66
77
} catch (DecodingExceptionInterface $ e ) {
0 commit comments