Skip to content

Commit 6306e73

Browse files
committed
DomQuery:: supports :scope
1 parent c118637 commit 6306e73

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/Framework/DomQuery.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ public static function fromXml(string $xml): self
6666
*/
6767
public function find(string $selector): array
6868
{
69-
$base = str_starts_with($selector, '>') ? 'self' : 'descendant';
70-
return $this->xpath($base . '::' . self::css2xpath($selector));
69+
return str_starts_with($selector, ':scope')
70+
? $this->xpath('self::' . self::css2xpath(substr($selector, 6)))
71+
: $this->xpath('descendant::' . self::css2xpath($selector));
7172
}
7273

7374

tests/Framework/DomQuery.fromXml.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Assert::type(DomQuery::class, $results[0]);
3232
Assert::type(DomQuery::class, $results[1]);
3333

3434
// children
35-
$results = $dom->find('> item');
35+
$results = $dom->find(':scope > item');
3636
Assert::count(2, $results);
3737

3838
// has

0 commit comments

Comments
 (0)