diff --git a/composer.json b/composer.json index 350a34d..dee45ea 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": ">=5.6", + "php": ">=7.4", "myclabs/deep-copy": "^1.8", "ext-json": "*" }, @@ -33,6 +33,6 @@ "Nahid\\JsonQ\\Tests\\": "tests/" } }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/helpers/qarray.php b/helpers/qarray.php index 1dc2c20..cf1e550 100644 --- a/helpers/qarray.php +++ b/helpers/qarray.php @@ -6,20 +6,7 @@ if (!function_exists('convert_to_array')) { function convert_to_array($data) { - if (!is_array($data) && ! $data instanceof QueryEngine) { - return [$data]; - } - - $new_data = []; - foreach ($data as $key => $map) { - if ($map instanceof QueryEngine) { - $new_data[$key] = convert_to_array($map); - } else { - $new_data[$key] = $map; - } - } - - return $new_data; + return \Nahid\QArray\Utilities::toArray($data); } } @@ -30,12 +17,6 @@ function convert_to_array($data) */ function qarray($data = []) { - if (!is_array($data)) { - $data = []; - } - - $instance = ArrayQuery::getInstance(); - - return $instance->collect($data); + return \Nahid\QArray\Utilities::qarray($data); } } \ No newline at end of file diff --git a/src/QueryEngine.php b/src/QueryEngine.php index c59a119..4d41198 100644 --- a/src/QueryEngine.php +++ b/src/QueryEngine.php @@ -615,7 +615,7 @@ public function sortBy($column, $order = 'asc') */ public function sort($order = 'asc') { - $this->_data = convert_to_array($this->_data); + $this->_data = Utilities::toArray($this->_data); if ($order == 'desc') { rsort($this->_data); @@ -834,7 +834,7 @@ public function toArray() { $this->prepare(); $maps = $this->_data; - return convert_to_array($maps); + return Utilities::toArray($maps); } /** diff --git a/src/Utilities.php b/src/Utilities.php new file mode 100644 index 0000000..1155be3 --- /dev/null +++ b/src/Utilities.php @@ -0,0 +1,35 @@ + $map) { + if ($map instanceof QueryEngine) { + $new_data[$key] = self::toArray($map); + } else { + $new_data[$key] = $map; + } + } + + return $new_data; + } + + public static function qarray($data = []) + { + if (!is_array($data)) { + $data = []; + } + + $instance = ArrayQuery::getInstance(); + + return $instance->collect($data); + } +} \ No newline at end of file