From bc5691092b25cc99161192442b71f5a650a22ac4 Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Sun, 3 Nov 2024 10:52:11 +0600 Subject: [PATCH 1/2] added static utilities --- helpers/qarray.php | 23 ++--------------------- src/Utilities.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 src/Utilities.php 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/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 From 02c33687d5981ab9720368b11a06d98d43e373d0 Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Sun, 3 Nov 2024 11:05:32 +0600 Subject: [PATCH 2/2] fixed helper issue --- src/QueryEngine.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); } /**