ClassParser.php
2 years ago
ElementParser.php
2 years ago
EmptyStringParser.php
2 years ago
HashParser.php
2 years ago
index.php
2 years ago
ClassParser.php
25 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\Parser\Shortcut; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\CssSelector\Node\ClassNode; |
| 5 | use MailPoetVendor\Symfony\Component\CssSelector\Node\ElementNode; |
| 6 | use MailPoetVendor\Symfony\Component\CssSelector\Node\SelectorNode; |
| 7 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\ParserInterface; |
| 8 | class ClassParser implements ParserInterface |
| 9 | { |
| 10 | public function parse(string $source) : array |
| 11 | { |
| 12 | // Matches an optional namespace, optional element, and required class |
| 13 | // $source = 'test|input.ab6bd_field'; |
| 14 | // $matches = array (size=4) |
| 15 | // 0 => string 'test|input.ab6bd_field' (length=22) |
| 16 | // 1 => string 'test' (length=4) |
| 17 | // 2 => string 'input' (length=5) |
| 18 | // 3 => string 'ab6bd_field' (length=11) |
| 19 | if (\preg_match('/^(?:([a-z]++)\\|)?+([\\w-]++|\\*)?+\\.([\\w-]++)$/i', \trim($source), $matches)) { |
| 20 | return [new SelectorNode(new ClassNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3]))]; |
| 21 | } |
| 22 | return []; |
| 23 | } |
| 24 | } |
| 25 |