Exception
2 years ago
Node
2 years ago
Parser
2 years ago
XPath
2 years ago
CssSelectorConverter.php
2 years ago
index.php
2 years ago
CssSelectorConverter.php
32 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\Shortcut\ClassParser; |
| 5 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\Shortcut\ElementParser; |
| 6 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\Shortcut\EmptyStringParser; |
| 7 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\Shortcut\HashParser; |
| 8 | use MailPoetVendor\Symfony\Component\CssSelector\XPath\Extension\HtmlExtension; |
| 9 | use MailPoetVendor\Symfony\Component\CssSelector\XPath\Translator; |
| 10 | class CssSelectorConverter |
| 11 | { |
| 12 | private $translator; |
| 13 | private $cache; |
| 14 | private static $xmlCache = []; |
| 15 | private static $htmlCache = []; |
| 16 | public function __construct(bool $html = \true) |
| 17 | { |
| 18 | $this->translator = new Translator(); |
| 19 | if ($html) { |
| 20 | $this->translator->registerExtension(new HtmlExtension($this->translator)); |
| 21 | $this->cache =& self::$htmlCache; |
| 22 | } else { |
| 23 | $this->cache =& self::$xmlCache; |
| 24 | } |
| 25 | $this->translator->registerParserShortcut(new EmptyStringParser())->registerParserShortcut(new ElementParser())->registerParserShortcut(new ClassParser())->registerParserShortcut(new HashParser()); |
| 26 | } |
| 27 | public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::') |
| 28 | { |
| 29 | return $this->cache[$prefix][$cssExpr] ?? ($this->cache[$prefix][$cssExpr] = $this->translator->cssToXPath($cssExpr, $prefix)); |
| 30 | } |
| 31 | } |
| 32 |