Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / symfony / css-selector / Node / AttributeNode.php
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
12 namespace Symfony\Component\CssSelector\Node;
13
14 /**
15  * Represents a "<selector>[<namespace>|<attribute> <operator> <value>]" node.
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 <jeanfrancois.simon@sensiolabs.com>
21  *
22  * @internal
23  */
24 class AttributeNode extends AbstractNode
25 {
26     private $selector;
27     private $namespace;
28     private $attribute;
29     private $operator;
30     private $value;
31
32     /**
33      * @param NodeInterface $selector
34      * @param string        $namespace
35      * @param string        $attribute
36      * @param string        $operator
37      * @param string        $value
38      */
39     public function __construct(NodeInterface $selector, $namespace, $attribute, $operator, $value)
40     {
41         $this->selector = $selector;
42         $this->namespace = $namespace;
43         $this->attribute = $attribute;
44         $this->operator = $operator;
45         $this->value = $value;
46     }
47
48     /**
49      * @return NodeInterface
50      */
51     public function getSelector()
52     {
53         return $this->selector;
54     }
55
56     /**
57      * @return string
58      */
59     public function getNamespace()
60     {
61         return $this->namespace;
62     }
63
64     /**
65      * @return string
66      */
67     public function getAttribute()
68     {
69         return $this->attribute;
70     }
71
72     /**
73      * @return string
74      */
75     public function getOperator()
76     {
77         return $this->operator;
78     }
79
80     /**
81      * @return string
82      */
83     public function getValue()
84     {
85         return $this->value;
86     }
87
88     /**
89      * {@inheritdoc}
90      */
91     public function getSpecificity()
92     {
93         return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
94     }
95
96     /**
97      * {@inheritdoc}
98      */
99     public function __toString()
100     {
101         $attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute;
102
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);
106     }
107 }