|
@@ -20,7 +20,7 @@ class UseResponseFileTag extends Strategy
|
|
* @param array $routeRules
|
|
* @param array $routeRules
|
|
* @param array $context
|
|
* @param array $context
|
|
*
|
|
*
|
|
- * @throws \Exception
|
|
|
|
|
|
+ * @throws \Exception If the response file does not exist
|
|
*
|
|
*
|
|
* @return array|null
|
|
* @return array|null
|
|
*/
|
|
*/
|
|
@@ -55,8 +55,13 @@ class UseResponseFileTag extends Strategy
|
|
|
|
|
|
$responses = array_map(function (Tag $responseFileTag) {
|
|
$responses = array_map(function (Tag $responseFileTag) {
|
|
preg_match('/^(\d{3})?\s?([\S]*[\s]*?)(\{.*\})?$/', $responseFileTag->getContent(), $result);
|
|
preg_match('/^(\d{3})?\s?([\S]*[\s]*?)(\{.*\})?$/', $responseFileTag->getContent(), $result);
|
|
|
|
+ $relativeFilePath = trim($result[2]);
|
|
|
|
+ $filePath = storage_path($relativeFilePath);
|
|
|
|
+ if (!file_exists($filePath)) {
|
|
|
|
+ throw new \Exception('@responseFile ' . $relativeFilePath . ' does not exist');
|
|
|
|
+ }
|
|
$status = $result[1] ?: 200;
|
|
$status = $result[1] ?: 200;
|
|
- $content = $result[2] ? file_get_contents(storage_path(trim($result[2])), true) : '{}';
|
|
|
|
|
|
+ $content = $result[2] ? file_get_contents($filePath, true) : '{}';
|
|
$json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
|
|
$json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
|
|
$merged = array_merge(json_decode($content, true), json_decode($json, true));
|
|
$merged = array_merge(json_decode($content, true), json_decode($json, true));
|
|
|
|
|