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
33 * @param NodeInterface $selector
34 * @param string $namespace
35 * @param string $attribute
36 * @param string $operator
37 * @param string $value
39 public function __construct(NodeInterface $selector, $namespace, $attribute, $operator, $value)
41 $this->selector = $selector;
42 $this->namespace = $namespace;
43 $this->attribute = $attribute;
44 $this->operator = $operator;
45 $this->value = $value;
49 * @return NodeInterface
51 public function getSelector()
53 return $this->selector;
59 public function getNamespace()
61 return $this->namespace;
67 public function getAttribute()
69 return $this->attribute;
75 public function getOperator()
77 return $this->operator;
83 public function getValue()
91 public function getSpecificity()
93 return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
99 public function __toString()
101 $attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute;
103 return 'exists' === $this->operator
104 ? sprintf('%s[%s[%s]]', $this->getNodeName(), $this->selector, $attribute)
105 : sprintf("%s[%s[%s %s '%s']]", $this->getNodeName(), $this->selector, $attribute, $this->operator, $this->value);