feat: modify the each function of class elements
This commit is contained in:
parent
52bbdeae14
commit
b3d84cf057
@ -114,7 +114,6 @@ use phpQueryObject;
|
||||
* @method Elements removeClass($className)
|
||||
* @method Elements toggleClass($className)
|
||||
* @method Elements _empty()
|
||||
* @method Elements each($callback,$param1=null,$param2=null,$param3=null)
|
||||
* @method Elements callback($callback, $param1 = null, $param2 = null, $param3 = null)
|
||||
* @method string data($key, $value = null)
|
||||
* @method Elements removeData($key)
|
||||
@ -133,7 +132,6 @@ use phpQueryObject;
|
||||
* @method Elements dumpTree($html, $title)
|
||||
* @method dumpDie()
|
||||
*/
|
||||
|
||||
class Elements
|
||||
{
|
||||
/**
|
||||
@ -175,21 +173,12 @@ class Elements
|
||||
*/
|
||||
public function each(callable $callback)
|
||||
{
|
||||
$break = false;
|
||||
$this->elements->each(function ($dom) use ($callback, &$break) {
|
||||
if ( ! $dom || $break) {
|
||||
return;
|
||||
foreach ($this->elements as $key => $element) {
|
||||
$break = $callback(new self(pq($element)), $key);
|
||||
if ($break === false) {
|
||||
break;
|
||||
}
|
||||
$orig = $dom;
|
||||
$dom = new Elements(pq($dom));
|
||||
if (false === call_user_func($callback, $dom)) {
|
||||
$dom = $orig;
|
||||
$break = true;
|
||||
} else {
|
||||
$dom = $dom->getDOMDocument();
|
||||
}
|
||||
unset($orig);
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user