Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\CssSelector\Node; Chris@0: Chris@0: /** Chris@0: * Represents a "[| ]" node. Chris@0: * Chris@0: * This component is a port of the Python cssselect library, Chris@0: * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. Chris@0: * Chris@0: * @author Jean-François Simon Chris@0: * Chris@0: * @internal Chris@0: */ Chris@0: class AttributeNode extends AbstractNode Chris@0: { Chris@0: private $selector; Chris@0: private $namespace; Chris@0: private $attribute; Chris@0: private $operator; Chris@0: private $value; Chris@0: Chris@0: /** Chris@0: * @param NodeInterface $selector Chris@0: * @param string $namespace Chris@0: * @param string $attribute Chris@0: * @param string $operator Chris@0: * @param string $value Chris@0: */ Chris@0: public function __construct(NodeInterface $selector, $namespace, $attribute, $operator, $value) Chris@0: { Chris@0: $this->selector = $selector; Chris@0: $this->namespace = $namespace; Chris@0: $this->attribute = $attribute; Chris@0: $this->operator = $operator; Chris@0: $this->value = $value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return NodeInterface Chris@0: */ Chris@0: public function getSelector() Chris@0: { Chris@0: return $this->selector; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getNamespace() Chris@0: { Chris@0: return $this->namespace; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getAttribute() Chris@0: { Chris@0: return $this->attribute; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getOperator() Chris@0: { Chris@0: return $this->operator; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getValue() Chris@0: { Chris@0: return $this->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getSpecificity() Chris@0: { Chris@0: return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function __toString() Chris@0: { Chris@0: $attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute; Chris@0: Chris@0: return 'exists' === $this->operator Chris@0: ? sprintf('%s[%s[%s]]', $this->getNodeName(), $this->selector, $attribute) Chris@0: : sprintf("%s[%s[%s %s '%s']]", $this->getNodeName(), $this->selector, $attribute, $this->operator, $this->value); Chris@0: } Chris@0: }