Merge pull request #4036 from dokuwiki/issue4033
[dokuwiki.git] / _test / vendor / symfony / css-selector / CssSelectorConverter.php
blobd1aeb7eb1702ea7c9a6ed55db29fb6303e7c1942
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\CssSelector;
14 use Symfony\Component\CssSelector\Parser\Shortcut\ClassParser;
15 use Symfony\Component\CssSelector\Parser\Shortcut\ElementParser;
16 use Symfony\Component\CssSelector\Parser\Shortcut\EmptyStringParser;
17 use Symfony\Component\CssSelector\Parser\Shortcut\HashParser;
18 use Symfony\Component\CssSelector\XPath\Extension\HtmlExtension;
19 use Symfony\Component\CssSelector\XPath\Translator;
21 /**
22 * CssSelectorConverter is the main entry point of the component and can convert CSS
23 * selectors to XPath expressions.
25 * @author Christophe Coevoet <stof@notk.org>
27 class CssSelectorConverter
29 private $translator;
31 /**
32 * @param bool $html Whether HTML support should be enabled. Disable it for XML documents
34 public function __construct(bool $html = true)
36 $this->translator = new Translator();
38 if ($html) {
39 $this->translator->registerExtension(new HtmlExtension($this->translator));
42 $this->translator
43 ->registerParserShortcut(new EmptyStringParser())
44 ->registerParserShortcut(new ElementParser())
45 ->registerParserShortcut(new ClassParser())
46 ->registerParserShortcut(new HashParser())
50 /**
51 * Translates a CSS expression to its XPath equivalent.
53 * Optionally, a prefix can be added to the resulting XPath
54 * expression with the $prefix parameter.
56 * @param string $cssExpr The CSS expression
57 * @param string $prefix An optional prefix for the XPath expression
59 * @return string
61 public function toXPath($cssExpr, $prefix = 'descendant-or-self::')
63 return $this->translator->cssToXPath($cssExpr, $prefix);