-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from veewee/reader-matchers
Provide better reader matchers
- Loading branch information
Showing
39 changed files
with
1,689 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Reader\Matcher; | ||
|
||
use Closure; | ||
use Psl\Iter; | ||
use VeeWee\Xml\Reader\Node\NodeSequence; | ||
|
||
/** | ||
* @param list<callable(NodeSequence): bool> $matchers | ||
* | ||
* @return \Closure(NodeSequence): bool | ||
*/ | ||
function any(callable ... $matchers): Closure | ||
{ | ||
return static fn (NodeSequence $sequence): bool => Iter\any( | ||
$matchers, | ||
/** | ||
* @param callable(NodeSequence): bool $matcher | ||
*/ | ||
static fn (callable $matcher): bool => $matcher($sequence) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Reader\Matcher; | ||
|
||
use Closure; | ||
use VeeWee\Xml\Reader\Node\AttributeNode; | ||
use VeeWee\Xml\Reader\Node\NodeSequence; | ||
use function Psl\Iter\any; | ||
|
||
/** | ||
* @return \Closure(NodeSequence): bool | ||
*/ | ||
function attribute_local_name(string $localName): Closure | ||
{ | ||
return static function (NodeSequence $sequence) use ($localName): bool { | ||
return any( | ||
$sequence->current()->attributes(), | ||
static fn (AttributeNode $attribute): bool => $attribute->localName() === $localName | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Reader\Matcher; | ||
|
||
use Closure; | ||
use VeeWee\Xml\Reader\Node\AttributeNode; | ||
use VeeWee\Xml\Reader\Node\NodeSequence; | ||
use function Psl\Iter\any; | ||
|
||
/** | ||
* @return \Closure(NodeSequence): bool | ||
*/ | ||
function attribute_local_value(string $localName, string $value): Closure | ||
{ | ||
return static function (NodeSequence $sequence) use ($localName, $value): bool { | ||
return any( | ||
$sequence->current()->attributes(), | ||
static fn (AttributeNode $attribute): bool => $attribute->localName() === $localName && $attribute->value() === $value | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Reader\Matcher; | ||
|
||
use Closure; | ||
use VeeWee\Xml\Reader\Node\AttributeNode; | ||
use VeeWee\Xml\Reader\Node\NodeSequence; | ||
use function Psl\Iter\any; | ||
|
||
/** | ||
* @return \Closure(NodeSequence): bool | ||
*/ | ||
function attribute_name(string $name): Closure | ||
{ | ||
return static function (NodeSequence $sequence) use ($name): bool { | ||
return any( | ||
$sequence->current()->attributes(), | ||
static fn (AttributeNode $attribute): bool => $attribute->name() === $name | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Reader\Matcher; | ||
|
||
use Closure; | ||
use VeeWee\Xml\Reader\Node\AttributeNode; | ||
use VeeWee\Xml\Reader\Node\NodeSequence; | ||
use function Psl\Iter\any; | ||
|
||
/** | ||
* @return \Closure(NodeSequence): bool | ||
*/ | ||
function attribute_value(string $name, string $value): Closure | ||
{ | ||
return static function (NodeSequence $sequence) use ($name, $value): bool { | ||
return any( | ||
$sequence->current()->attributes(), | ||
static fn (AttributeNode $attribute): bool => $attribute->name() === $name && $attribute->value() === $value | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Reader\Matcher; | ||
|
||
use Closure; | ||
use VeeWee\Xml\Reader\Node\NodeSequence; | ||
|
||
/** | ||
* @return \Closure(NodeSequence): bool | ||
*/ | ||
function document_element(): Closure | ||
{ | ||
return static function (NodeSequence $sequence): bool { | ||
return !$sequence->parent(); | ||
}; | ||
} |
Oops, something went wrong.