PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.3
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.3
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 / XPath / XPathExpr.php

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

103 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace AcyMailing\Libraries\Symfony\CssSelector\XPath;
13
14 /**
15 * XPath expression translator interface.
16 *
17 * This component is a port of the Python cssselect library,
18 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
19 *
20 * @author Jean-François Simon <[email protected]>
21 *
22 * @internal
23 */
24 class XPathExpr
25 {
26 private $path;
27 private $element;
28 private $condition;
29
30 public function __construct(string $path = '', string $element = '*', string $condition = '', bool $starPrefix = false)
31 {
32 $this->path = $path;
33 $this->element = $element;
34 $this->condition = $condition;
35
36 if ($starPrefix) {
37 $this->addStarPrefix();
38 }
39 }
40
41 public function getElement(): string
42 {
43 return $this->element;
44 }
45
46 public function addCondition(string $condition): self
47 {
48 $this->condition = $this->condition ? sprintf('(%s) and (%s)', $this->condition, $condition) : $condition;
49
50 return $this;
51 }
52
53 public function getCondition(): string
54 {
55 return $this->condition;
56 }
57
58 public function addNameTest(): self
59 {
60 if ('*' !== $this->element) {
61 $this->addCondition('name() = '.Translator::getXpathLiteral($this->element));
62 $this->element = '*';
63 }
64
65 return $this;
66 }
67
68 public function addStarPrefix(): self
69 {
70 $this->path .= '*/';
71
72 return $this;
73 }
74
75 /**
76 * Joins another XPathExpr with a combiner.
77 *
78 * @return $this
79 */
80 public function join(string $combiner, self $expr): self
81 {
82 $path = $this->__toString().$combiner;
83
84 if ('*/' !== $expr->path) {
85 $path .= $expr->path;
86 }
87
88 $this->path = $path;
89 $this->element = $expr->element;
90 $this->condition = $expr->condition;
91
92 return $this;
93 }
94
95 public function __toString(): string
96 {
97 $path = $this->path.$this->element;
98 $condition = null === $this->condition || '' === $this->condition ? '' : '['.$this->condition.']';
99
100 return $path.$condition;
101 }
102 }
103