getFileResponses($tags); } /** * Get the response from the file if available. * * @param array $tags * * @return array|null */ protected function getFileResponses(array $tags) { // avoid "holes" in the keys of the filtered array, by using array_values on the filtered array $responseFileTags = array_values( array_filter($tags, function ($tag) { return $tag instanceof Tag && strtolower($tag->getName()) === 'responsefile'; }) ); if (empty($responseFileTags)) { return; } return array_map(function (Tag $responseFileTag) { preg_match('/^(\d{3})?\s?([\s\S]*)$/', $responseFileTag->getContent(), $result); $status = $result[1] ?: 200; $content = $result[2] ? file_get_contents(storage_path($result[2]), true) : '{}'; return new JsonResponse(json_decode($content, true), (int) $status); }, $responseFileTags); } }