Skip to content

Commit daab726

Browse files
committed
4268: Updated fixture loader to allow loading from local files
1 parent aa718b7 commit daab726

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Fixtures/FixtureLoader.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ public function process(string $indexName, string $url): void
6262
*/
6363
private function download(string $url): array
6464
{
65+
// Load from local file if using "file" URL scheme.
66+
if (preg_match('~^file://(?<path>/.+)$~', $url, $matches)) {
67+
$path = $matches['path'];
68+
if (!is_readable($path)) {
69+
throw new \HttpException('Unable to download fixture data');
70+
}
71+
$data = json_decode(file_get_contents($path), true);
72+
if (empty($data)) {
73+
throw new \HttpException('Unable to download fixture data');
74+
}
75+
76+
return $data;
77+
}
78+
6579
$response = $this->httpClient->request('GET', $url);
6680

6781
if (Response::HTTP_OK !== $response->getStatusCode()) {

0 commit comments

Comments
 (0)