|
8 | 8 | use Elastic\Elasticsearch\Exception\MissingParameterException;
|
9 | 9 | use Elastic\Elasticsearch\Exception\ServerResponseException;
|
10 | 10 | use Symfony\Component\HttpFoundation\Response;
|
| 11 | +use Symfony\Component\HttpKernel\Exception\HttpException; |
| 12 | +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
11 | 13 | use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
12 | 14 | use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
13 | 15 | use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
@@ -58,14 +60,28 @@ public function process(string $indexName, string $url): void
|
58 | 60 | * @throws RedirectionExceptionInterface
|
59 | 61 | * @throws ServerExceptionInterface
|
60 | 62 | * @throws TransportExceptionInterface
|
61 |
| - * @throws \HttpException |
| 63 | + * @throws HttpException |
62 | 64 | */
|
63 | 65 | private function download(string $url): array
|
64 | 66 | {
|
| 67 | + // Load from local file if using "file" URL scheme. |
| 68 | + if (preg_match('~^file://(?<path>/.+)$~', $url, $matches)) { |
| 69 | + $path = $matches['path']; |
| 70 | + if (!is_readable($path)) { |
| 71 | + throw new NotFoundHttpException('Unable to download fixture data'); |
| 72 | + } |
| 73 | + $data = json_decode(file_get_contents($path), true); |
| 74 | + if (empty($data)) { |
| 75 | + throw new NotFoundHttpException('Unable to download fixture data'); |
| 76 | + } |
| 77 | + |
| 78 | + return $data; |
| 79 | + } |
| 80 | + |
65 | 81 | $response = $this->httpClient->request('GET', $url);
|
66 | 82 |
|
67 | 83 | if (Response::HTTP_OK !== $response->getStatusCode()) {
|
68 |
| - throw new \HttpException('Unable to download fixture data'); |
| 84 | + throw new NotFoundHttpException('Unable to download fixture data'); |
69 | 85 | }
|
70 | 86 |
|
71 | 87 | return $response->toArray();
|
|
0 commit comments