8000 Send HTTP request to download the manifest only when necessary. The a… · symfony/symfony@fa279bd · GitHub
[go: up one dir, main page]

Skip to content

Commit fa279bd

Browse files
committed
Send HTTP request to download the manifest only when necessary. The async/lazy mecanism must be explicit if an optimisation is necessary.
1 parent c94b2d5 commit fa279bd

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/Symfony/Component/Asset/VersionStrategy/RemoteJsonManifestVersionStrategy.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
namespace Symfony\Component\Asset\VersionStrategy;
1313

14-
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
1514
use Symfony\Contracts\HttpClient\HttpClientInterface;
16-
use Symfony\Contracts\HttpClient\ResponseInterface;
1715

1816
/**
1917
* Reads the versioned path of an asset from a remote JSON manifest file.
@@ -29,21 +27,16 @@
2927
class RemoteJsonManifestVersionStrategy implements VersionStrategyInterface
3028
{
3129
private $manifestData;
32-
33-
/**
34-
* @var ResponseInterface
35-
*/
36-
private $httpResponse;
30+
private $manifestUrl;
31+
private $httpClient;
3732

3833
/**
3934
* @param string $manifestUrl Absolute URL to the manifest file
4035
*/
4136
public function __construct(string $manifestUrl, HttpClientInterface $httpClient)
4237
{
43-
$this->httpResponse = $httpClient->request('GET', $manifestUrl, [
44-
'headers' => ['accept' => 'application/json'],
45-
'buffer' => true,
46-
]);
38+
$this->manifestUrl = $manifestUrl;
39+
$this->httpClient = $httpClient;
4740
}
4841

4942
/**
@@ -64,11 +57,10 @@ public function applyVersion(string $path)
6457
private function getManifestPath(string $path): ?string
6558
{
6659
if (null === $this->manifestData) {
67-
try {
68-
$this->manifestData = $this->httpResponse->toArray();
69-
} catch (ExceptionInterface $e) {
70-
throw new \RuntimeException(sprintf('Error loading asset manifest from URL "%s"', $this->httpResponse->getInfo()['url']), 0, $e);
71-
}
60+
$this->manifestData = $this->httpClient->request('GET', $this->manifestUrl, [
61+
'headers' => ['accept' => 'application/json'],
62+
'buffer' => true,
63+
])->toArray();
7264
}
7365

7466
return $this->manifestData[$path] ?? null;

0 commit comments

Comments
 (0)
0