/** * Return all sibling pages before this one until matching the one specified * * @param Page $page * @param string|Page $selector May either be a selector string or Page to stop at. Results will not include this. * @param string $filter Optional selector string to filter matched pages by * @param PageArray|null $siblings Optional PageArray of siblings to use instead of all from the page. * @return PageArray * */ public function prevUntil(Page $page, $selector = '', $filter = '', PageArray $siblings = null) { if (is_null($siblings)) { $siblings = $page->parent()->children(); } else { if (!$siblings->has($page)) { $siblings->add($page); } } $siblings = $this->prevAll($page, '', $siblings); $all = new PageArray(); $stop = false; foreach ($siblings->reverse() as $sibling) { if (is_string($selector) && strlen($selector)) { if (ctype_digit("{$selector}") && $sibling->id == $selector) { $stop = true; } else { if ($sibling->matches($selector)) { $stop = true; } } } else { if (is_int($selector)) { if ($sibling->id == $selector) { $stop = true; } } else { if ($selector instanceof Page && $sibling->id == $selector->id) { $stop = true; } } } if ($stop) { break; } $all->prepend($sibling); } if (strlen($filter)) { $all->filter($filter); } return $all; }