wp-user-avatar
/
third-party
/
vendor
/
symfony
/
css-selector
/
Parser
/
Shortcut
/
ClassParser.php
ClassParser.php
2 months ago
ElementParser.php
2 months ago
EmptyStringParser.php
2 months ago
HashParser.php
2 months ago
ClassParser.php
47 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\ClassNode; |
| 14 | use ProfilePressVendor\Symfony\Component\CssSelector\Node\ElementNode; |
| 15 | use ProfilePressVendor\Symfony\Component\CssSelector\Node\SelectorNode; |
| 16 | use ProfilePressVendor\Symfony\Component\CssSelector\Parser\ParserInterface; |
| 17 | /** |
| 18 | * CSS selector class parser shortcut. |
| 19 | * |
| 20 | * This component is a port of the Python cssselect library, |
| 21 | * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. |
| 22 | * |
| 23 | * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> |
| 24 | * |
| 25 | * @internal |
| 26 | */ |
| 27 | class ClassParser implements ParserInterface |
| 28 | { |
| 29 | /** |
| 30 | * {@inheritdoc} |
| 31 | */ |
| 32 | public function parse(string $source): array |
| 33 | { |
| 34 | // Matches an optional namespace, optional element, and required class |
| 35 | // $source = 'test|input.ab6bd_field'; |
| 36 | // $matches = array (size=4) |
| 37 | // 0 => string 'test|input.ab6bd_field' (length=22) |
| 38 | // 1 => string 'test' (length=4) |
| 39 | // 2 => string 'input' (length=5) |
| 40 | // 3 => string 'ab6bd_field' (length=11) |
| 41 | if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+\.([\w-]++)$/i', trim($source), $matches)) { |
| 42 | return [new SelectorNode(new ClassNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3]))]; |
| 43 | } |
| 44 | return []; |
| 45 | } |
| 46 | } |
| 47 |