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\Node;
15 * Represents a "<selector>[<namespace>|<attribute> <operator> <value>]" node.
17 * This component is a port of the Python cssselect library,
18 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
20 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
24 class AttributeNode extends AbstractNode
52 * @param NodeInterface $selector
53 * @param string $namespace
54 * @param string $attribute
55 * @param string $operator
56 * @param string $value
58 public function __construct(NodeInterface $selector, $namespace, $attribute, $operator, $value)
60 $this->selector = $selector;
61 $this->namespace = $namespace;
62 $this->attribute = $attribute;
63 $this->operator = $operator;
64 $this->value = $value;
68 * @return NodeInterface
70 public function getSelector()
72 return $this->selector;
78 public function getNamespace()
80 return $this->namespace;
86 public function getAttribute()
88 return $this->attribute;
94 public function getOperator()
96 return $this->operator;
102 public function getValue()
110 public function getSpecificity()
112 return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
118 public function __toString()
120 $attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute;
122 return 'exists' === $this->operator
123 ? sprintf('%s[%s[%s]]', $this->getNodeName(), $this->selector, $attribute)
124 : sprintf("%s[%s[%s %s '%s']]", $this->getNodeName(), $this->selector, $attribute, $this->operator, $this->value);