AbstractNode.php
2 months ago
AttributeNode.php
2 months ago
ClassNode.php
2 months ago
CombinedSelectorNode.php
2 months ago
ElementNode.php
2 months ago
FunctionNode.php
2 months ago
HashNode.php
2 months ago
NegationNode.php
2 months ago
NodeInterface.php
2 months ago
PseudoNode.php
2 months ago
SelectorNode.php
2 months ago
Specificity.php
2 months ago
AttributeNode.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace ProfilePressVendor\Symfony\Component\CssSelector\Node; |
| 12 | |
| 13 | /** |
| 14 | * Represents a "<selector>[<namespace>|<attribute> <operator> <value>]" node. |
| 15 | * |
| 16 | * This component is a port of the Python cssselect library, |
| 17 | * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. |
| 18 | * |
| 19 | * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> |
| 20 | * |
| 21 | * @internal |
| 22 | */ |
| 23 | class AttributeNode extends AbstractNode |
| 24 | { |
| 25 | private $selector; |
| 26 | private $namespace; |
| 27 | private $attribute; |
| 28 | private $operator; |
| 29 | private $value; |
| 30 | public function __construct(NodeInterface $selector, ?string $namespace, string $attribute, string $operator, ?string $value) |
| 31 | { |
| 32 | $this->selector = $selector; |
| 33 | $this->namespace = $namespace; |
| 34 | $this->attribute = $attribute; |
| 35 | $this->operator = $operator; |
| 36 | $this->value = $value; |
| 37 | } |
| 38 | public function getSelector(): NodeInterface |
| 39 | { |
| 40 | return $this->selector; |
| 41 | } |
| 42 | public function getNamespace(): ?string |
| 43 | { |
| 44 | return $this->namespace; |
| 45 | } |
| 46 | public function getAttribute(): string |
| 47 | { |
| 48 | return $this->attribute; |
| 49 | } |
| 50 | public function getOperator(): string |
| 51 | { |
| 52 | return $this->operator; |
| 53 | } |
| 54 | public function getValue(): ?string |
| 55 | { |
| 56 | return $this->value; |
| 57 | } |
| 58 | /** |
| 59 | * {@inheritdoc} |
| 60 | */ |
| 61 | public function getSpecificity(): Specificity |
| 62 | { |
| 63 | return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0)); |
| 64 | } |
| 65 | public function __toString(): string |
| 66 | { |
| 67 | $attribute = $this->namespace ? $this->namespace . '|' . $this->attribute : $this->attribute; |
| 68 | return 'exists' === $this->operator ? sprintf('%s[%s[%s]]', $this->getNodeName(), $this->selector, $attribute) : sprintf("%s[%s[%s %s '%s']]", $this->getNodeName(), $this->selector, $attribute, $this->operator, $this->value); |
| 69 | } |
| 70 | } |
| 71 |