PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.2
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Libraries / Symfony / CssSelector / CssSelectorConverter.php

CssSelectorConverter.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.2, at back/Libraries/Symfony/CssSelector/CssSelectorConverter.php

72 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * version 5.3.0 modified by acyba
5 *
6 * This file is part of the Symfony package.
7 *
8 * (c) Fabien Potencier <[email protected]>
9 *
10 * For the full copyright and license information, please view the LICENSE
11 * file that was distributed with this source code.
12 */
13
14 namespace AcyMailing\Libraries\Symfony\CssSelector;
15
16 use AcyMailing\Libraries\Symfony\CssSelector\Parser\Shortcut\ClassParser;
17 use AcyMailing\Libraries\Symfony\CssSelector\Parser\Shortcut\ElementParser;
18 use AcyMailing\Libraries\Symfony\CssSelector\Parser\Shortcut\EmptyStringParser;
19 use AcyMailing\Libraries\Symfony\CssSelector\Parser\Shortcut\HashParser;
20 use AcyMailing\Libraries\Symfony\CssSelector\XPath\Extension\HtmlExtension;
21 use AcyMailing\Libraries\Symfony\CssSelector\XPath\Translator;
22
23 /**
24 * CssSelectorConverter is the main entry point of the component and can convert CSS
25 * selectors to XPath expressions.
26 *
27 * @author Christophe Coevoet <[email protected]>
28 */
29 class CssSelectorConverter
30 {
31 private $translator;
32 private $cache;
33
34 private static $xmlCache = [];
35 private static $htmlCache = [];
36
37 /**
38 * @param bool $html Whether HTML support should be enabled. Disable it for XML documents
39 */
40 public function __construct(bool $html = true)
41 {
42 $this->translator = new Translator();
43
44 if ($html) {
45 $this->translator->registerExtension(new HtmlExtension($this->translator));
46 $this->cache = &self::$htmlCache;
47 } else {
48 $this->cache = &self::$xmlCache;
49 }
50
51 $this->translator
52 ->registerParserShortcut(new EmptyStringParser())
53 ->registerParserShortcut(new ElementParser())
54 ->registerParserShortcut(new ClassParser())
55 ->registerParserShortcut(new HashParser())
56 ;
57 }
58
59 /**
60 * Translates a CSS expression to its XPath equivalent.
61 *
62 * Optionally, a prefix can be added to the resulting XPath
63 * expression with the $prefix parameter.
64 *
65 * @return string
66 */
67 public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::')
68 {
69 return $this->cache[$prefix][$cssExpr] ?? $this->cache[$prefix][$cssExpr] = $this->translator->cssToXPath($cssExpr, $prefix);
70 }
71 }
72