Skip to content

Commit 97ee09e

Browse files
committed
4268: Updated fixture loader to allow loading from local files
1 parent b6b8c31 commit 97ee09e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ ElasticSearch.
5757
> [!TIP]
5858
> Use `task fixtures:load` to load all fixtures into Elasticsearch.
5959
60+
<!-- Ignore MD028/no-blanks-blockquote Blank line inside blockquote (cf.
61+
https://github.com/DavidAnson/markdownlint/issues/263) -->
62+
6063
> [!CAUTION]
6164
> If the `task fixtures:load` command (or any `bin/console app:fixtures:load` incantation) fails with an error like
6265
>

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)