Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/css-selector/Node/AttributeNode.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 /** | |
27 * @var NodeInterface | |
28 */ | |
29 private $selector; | |
30 | |
31 /** | |
32 * @var string | |
33 */ | |
34 private $namespace; | |
35 | |
36 /** | |
37 * @var string | |
38 */ | |
39 private $attribute; | |
40 | |
41 /** | |
42 * @var string | |
43 */ | |
44 private $operator; | |
45 | |
46 /** | |
47 * @var string | |
48 */ | |
49 private $value; | |
50 | |
51 /** | |
52 * @param NodeInterface $selector | |
53 * @param string $namespace | |
54 * @param string $attribute | |
55 * @param string $operator | |
56 * @param string $value | |
57 */ | |
58 public function __construct(NodeInterface $selector, $namespace, $attribute, $operator, $value) | |
59 { | |
60 $this->selector = $selector; | |
61 $this->namespace = $namespace; | |
62 $this->attribute = $attribute; | |
63 $this->operator = $operator; | |
64 $this->value = $value; | |
65 } | |
66 | |
67 /** | |
68 * @return NodeInterface | |
69 */ | |
70 public function getSelector() | |
71 { | |
72 return $this->selector; | |
73 } | |
74 | |
75 /** | |
76 * @return string | |
77 */ | |
78 public function getNamespace() | |
79 { | |
80 return $this->namespace; | |
81 } | |
82 | |
83 /** | |
84 * @return string | |
85 */ | |
86 public function getAttribute() | |
87 { | |
88 return $this->attribute; | |
89 } | |
90 | |
91 /** | |
92 * @return string | |
93 */ | |
94 public function getOperator() | |
95 { | |
96 return $this->operator; | |
97 } | |
98 | |
99 /** | |
100 * @return string | |
101 */ | |
102 public function getValue() | |
103 { | |
104 return $this->value; | |
105 } | |
106 | |
107 /** | |
108 * {@inheritdoc} | |
109 */ | |
110 public function getSpecificity() | |
111 { | |
112 return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0)); | |
113 } | |
114 | |
115 /** | |
116 * {@inheritdoc} | |
117 */ | |
118 public function __toString() | |
119 { | |
120 $attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute; | |
121 | |
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); | |
125 } | |
126 } |