Extension
2 years ago
Translator.php
2 years ago
TranslatorInterface.php
2 years ago
XPathExpr.php
2 years ago
index.php
2 years ago
XPathExpr.php
62 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\XPath; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class XPathExpr |
| 5 | { |
| 6 | private $path; |
| 7 | private $element; |
| 8 | private $condition; |
| 9 | public function __construct(string $path = '', string $element = '*', string $condition = '', bool $starPrefix = \false) |
| 10 | { |
| 11 | $this->path = $path; |
| 12 | $this->element = $element; |
| 13 | $this->condition = $condition; |
| 14 | if ($starPrefix) { |
| 15 | $this->addStarPrefix(); |
| 16 | } |
| 17 | } |
| 18 | public function getElement() : string |
| 19 | { |
| 20 | return $this->element; |
| 21 | } |
| 22 | public function addCondition(string $condition) : self |
| 23 | { |
| 24 | $this->condition = $this->condition ? \sprintf('(%s) and (%s)', $this->condition, $condition) : $condition; |
| 25 | return $this; |
| 26 | } |
| 27 | public function getCondition() : string |
| 28 | { |
| 29 | return $this->condition; |
| 30 | } |
| 31 | public function addNameTest() : self |
| 32 | { |
| 33 | if ('*' !== $this->element) { |
| 34 | $this->addCondition('name() = ' . Translator::getXpathLiteral($this->element)); |
| 35 | $this->element = '*'; |
| 36 | } |
| 37 | return $this; |
| 38 | } |
| 39 | public function addStarPrefix() : self |
| 40 | { |
| 41 | $this->path .= '*/'; |
| 42 | return $this; |
| 43 | } |
| 44 | public function join(string $combiner, self $expr) : self |
| 45 | { |
| 46 | $path = $this->__toString() . $combiner; |
| 47 | if ('*/' !== $expr->path) { |
| 48 | $path .= $expr->path; |
| 49 | } |
| 50 | $this->path = $path; |
| 51 | $this->element = $expr->element; |
| 52 | $this->condition = $expr->condition; |
| 53 | return $this; |
| 54 | } |
| 55 | public function __toString() : string |
| 56 | { |
| 57 | $path = $this->path . $this->element; |
| 58 | $condition = null === $this->condition || '' === $this->condition ? '' : '[' . $this->condition . ']'; |
| 59 | return $path . $condition; |
| 60 | } |
| 61 | } |
| 62 |