From 40db9c6ada1506ff56e8f4e4ec0832abb01da7bf Mon Sep 17 00:00:00 2001 From: sunhao Date: Thu, 27 Mar 2025 16:13:03 +0800 Subject: [PATCH] * [misc] fix zin hook query()->first/last() not work. --- lib/zin/core/command.class.php | 6 ++++-- lib/zin/core/node.class.php | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/zin/core/command.class.php b/lib/zin/core/command.class.php index 9d8577b4f7..41bf33d851 100644 --- a/lib/zin/core/command.class.php +++ b/lib/zin/core/command.class.php @@ -173,8 +173,9 @@ class command return $list; } - public static function first(array $nodes, string|array|object $selectors) + public static function first(array $nodes, string|array|object|null $selectors = null) { + if($selectors === null) return reset($nodes); foreach($nodes as $node) { $result = $node->findFirst($selectors); @@ -183,8 +184,9 @@ class command return array(); } - public static function last(array $nodes, string|array|object $selectors) + public static function last(array $nodes, string|array|object|null $selectors = null) { + if($selectors === null) return end($nodes); foreach($nodes as $node) { $result = $node->findLast($selectors); diff --git a/lib/zin/core/node.class.php b/lib/zin/core/node.class.php index 29915cb06e..d7ed3105cd 100644 --- a/lib/zin/core/node.class.php +++ b/lib/zin/core/node.class.php @@ -176,13 +176,13 @@ class node implements \JsonSerializable public function findFirst(string|array|object $selectors): ?node { $results = $this->find($selectors, true); - return empty($results) ? null : $results[0]; + return empty($results) ? null : reset($results); } public function findLast(string|array|object $selectors): ?node { $results = $this->find($selectors, true, true); - return empty($results) ? null : $results[0]; + return empty($results) ? null : reset($results); } public function prop(array|string $name, mixed $defaultValue = null): mixed