From 8b38ceaa05c6d92355637e300dec15dcdab21474 Mon Sep 17 00:00:00 2001 From: Mehedi Hasan Nahid Date: Fri, 18 Oct 2019 00:53:33 +0600 Subject: [PATCH] fixed: issue-49 --- src/JsonQueriable.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/JsonQueriable.php b/src/JsonQueriable.php index 514818b..b514083 100644 --- a/src/JsonQueriable.php +++ b/src/JsonQueriable.php @@ -193,7 +193,7 @@ protected function isMultiArray($arr) * * @param string $value * @param bool $isReturnMap - * + * * @return bool|array */ public function isJson($value, $isReturnMap = false) @@ -201,13 +201,13 @@ public function isJson($value, $isReturnMap = false) if (is_array($value) || is_object($value)) { return false; } - + $data = json_decode($value, true); if (json_last_error() !== JSON_ERROR_NONE) { return false; } - + return $isReturnMap ? $data : true; } @@ -300,11 +300,11 @@ protected function getDataFromFile($file, $type = 'application/json') $context = stream_context_create($opts); $data = file_get_contents($file, 0, $context); $json = $this->isJson($data, true); - + if (!$json) { throw new InvalidJsonException(); } - + return $json; } @@ -331,6 +331,8 @@ protected function getFromNested($map, $node) $path = explode('.', $node); foreach ($path as $val) { + if (!is_array($map)) return $map; + if (!array_key_exists($val, $map)) { $terminate = true; break; @@ -379,10 +381,10 @@ protected function processConditions() if (!method_exists(Condition::class, $function)) { throw new ConditionNotAllowedException("Exception: $function condition not allowed"); } - + $function = [Condition::class, $function]; } - + $value = $this->getFromNested($val, $rule['key']); $return = $value instanceof ValueNotFound ? false : call_user_func_array($function, [$value, $rule['value']]); $tmp &= $return;