Explorar o código

Added ability to replace json key values

Ability to replace json key value pair with specified values in the response tag
NWANZE FRANKLIN %!s(int64=6) %!d(string=hai) anos
pai
achega
7567eb2049
Modificáronse 1 ficheiros con 5 adicións e 5 borrados
  1. 5 5
      src/Tools/ResponseStrategies/ResponseFileStrategy.php

+ 5 - 5
src/Tools/ResponseStrategies/ResponseFileStrategy.php

@@ -44,12 +44,12 @@ class ResponseFileStrategy
         }
 
         return 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);
             $status = $result[1] ?: 200;
-            $content = $result[2] ? file_get_contents(storage_path($result[2]), true) : '{}';
-
-            return new JsonResponse(json_decode($content, true), (int) $status);
+            $content = $result[2] ? file_get_contents(storage_path(trim($result[2])), true) : '{}';
+            $json = isset($result[3]) ? preg_replace("/'/", "\"", $result[3]) : "{}";
+            $merged = array_merge(json_decode($content, true), json_decode($json, true));
+            return new JsonResponse($merged, (int) $status);
         }, $responseFileTags);
     }
 }