wp-user-avatar
/
third-party
/
vendor
/
symfony
/
css-selector
/
Parser
/
Shortcut
/
ElementParser.php
ClassParser.php
2 months ago
ElementParser.php
2 months ago
EmptyStringParser.php
2 months ago
HashParser.php
2 months ago
ElementParser.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace ProfilePressVendor\Symfony\Component\CssSelector\Parser\Shortcut; |
| 12 | |
| 13 | use ProfilePressVendor\Symfony\Component\CssSelector\Node\ElementNode; |
| 14 | use ProfilePressVendor\Symfony\Component\CssSelector\Node\SelectorNode; |
| 15 | use ProfilePressVendor\Symfony\Component\CssSelector\Parser\ParserInterface; |
| 16 | /** |
| 17 | * CSS selector element parser shortcut. |
| 18 | * |
| 19 | * This component is a port of the Python cssselect library, |
| 20 | * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. |
| 21 | * |
| 22 | * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> |
| 23 | * |
| 24 | * @internal |
| 25 | */ |
| 26 | class ElementParser implements ParserInterface |
| 27 | { |
| 28 | /** |
| 29 | * {@inheritdoc} |
| 30 | */ |
| 31 | public function parse(string $source): array |
| 32 | { |
| 33 | // Matches an optional namespace, required element or `*` |
| 34 | // $source = 'testns|testel'; |
| 35 | // $matches = array (size=3) |
| 36 | // 0 => string 'testns|testel' (length=13) |
| 37 | // 1 => string 'testns' (length=6) |
| 38 | // 2 => string 'testel' (length=6) |
| 39 | if (preg_match('/^(?:([a-z]++)\|)?([\w-]++|\*)$/i', trim($source), $matches)) { |
| 40 | return [new SelectorNode(new ElementNode($matches[1] ?: null, $matches[2]))]; |
| 41 | } |
| 42 | return []; |
| 43 | } |
| 44 | } |
| 45 |