| @@ 12-40 (lines=29) @@ | ||
| 9 | /** |
|
| 10 | * Get a response from from a file in the docblock ( @responseFile ). |
|
| 11 | */ |
|
| 12 | class ResponseFileStrategy |
|
| 13 | { |
|
| 14 | public function __invoke(Route $route, array $tags, array $routeProps) |
|
| 15 | { |
|
| 16 | return $this->getFileResponse($tags); |
|
| 17 | } |
|
| 18 | ||
| 19 | /** |
|
| 20 | * Get the response from the file if available. |
|
| 21 | * |
|
| 22 | * @param array $tags |
|
| 23 | * |
|
| 24 | * @return mixed |
|
| 25 | */ |
|
| 26 | protected function getFileResponse(array $tags) |
|
| 27 | { |
|
| 28 | $responseFileTags = array_filter($tags, function ($tag) { |
|
| 29 | return $tag instanceof Tag && strtolower($tag->getName()) == 'responsefile'; |
|
| 30 | }); |
|
| 31 | if (empty($responseFileTags)) { |
|
| 32 | return; |
|
| 33 | } |
|
| 34 | $responseFileTag = array_first($responseFileTags); |
|
| 35 | ||
| 36 | $json = json_decode(Storage::get($responseFileTag->getContent()), true); |
|
| 37 | ||
| 38 | return response()->json($json); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 11-37 (lines=27) @@ | ||
| 8 | /** |
|
| 9 | * Get a response from the docblock ( @response ). |
|
| 10 | */ |
|
| 11 | class ResponseTagStrategy |
|
| 12 | { |
|
| 13 | public function __invoke(Route $route, array $tags, array $routeProps) |
|
| 14 | { |
|
| 15 | return $this->getDocBlockResponse($tags); |
|
| 16 | } |
|
| 17 | ||
| 18 | /** |
|
| 19 | * Get the response from the docblock if available. |
|
| 20 | * |
|
| 21 | * @param array $tags |
|
| 22 | * |
|
| 23 | * @return mixed |
|
| 24 | */ |
|
| 25 | protected function getDocBlockResponse(array $tags) |
|
| 26 | { |
|
| 27 | $responseTags = array_filter($tags, function ($tag) { |
|
| 28 | return $tag instanceof Tag && strtolower($tag->getName()) == 'response'; |
|
| 29 | }); |
|
| 30 | if (empty($responseTags)) { |
|
| 31 | return; |
|
| 32 | } |
|
| 33 | $responseTag = array_first($responseTags); |
|
| 34 | ||
| 35 | return response()->json(json_decode($responseTag->getContent(), true)); |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||