@@ -29,11 +29,6 @@ class NodeExtension extends AbstractExtension
29
29
const ATTRIBUTE_NAME_IN_LOWER_CASE = 2 ;
30
30
const ATTRIBUTE_VALUE_IN_LOWER_CASE = 4 ;
31
31
32
- /**
33
- * @var Translator
34
- */
35
- private $ translator ;
36
-
37
32
/**
38
33
* @var int
39
34
*/
@@ -42,12 +37,10 @@ class NodeExtension extends AbstractExtension
42
37
/**
43
38
* Constructor.
44
39
*
45
- * @param Translator $translator
46
- * @param int $flags
40
+ * @param int $flags
47
41
*/
48
- public function __construct (Translator $ translator , $ flags = 0 )
42
+ public function __construct ($ flags = 0 )
49
43
{
50
- $ this ->translator = $ translator ;
51
44
$ this ->flags = $ flags ;
52
45
}
53
46
@@ -100,33 +93,36 @@ public function getNodeTranslators()
100
93
101
94
/**
102
95
* @param Node\SelectorNode $node
96
+ * @param Translator $translator
103
97
*
104
98
* @return XPathExpr
105
99
*/
106
- public function translateSelector (Node \SelectorNode $ node )
100
+ public function translateSelector (Node \SelectorNode $ node, Translator $ translator )
107
101
{
108
- return $ this -> translator ->nodeToXPath ($ node ->getTree ());
102
+ return $ translator ->nodeToXPath ($ node ->getTree ());
109
103
}
110
104
111
105
/**
112
106
* @param Node\CombinedSelectorNode $node
107
+ * @param Translator $translator
113
108
*
114
109
* @return XPathExpr
115
110
*/
116
- public function translateCombinedSelector (Node \CombinedSelectorNode $ node )
111
+ public function translateCombinedSelector (Node \CombinedSelectorNode $ node, Translator $ translator )
117
112
{
118
- return $ this -> translator ->addCombination ($ node ->getCombinator (), $ node ->getSelector (), $ node ->getSubSelector ());
113
+ return $ translator ->addCombination ($ node ->getCombinator (), $ node ->getSelector (), $ node ->getSubSelector ());
119
114
}
120
115
121
116
/**
122
117
* @param Node\NegationNode $node
118
+ * @param Translator $translator
123
119
*
124
120
* @return XPathExpr
125
121
*/
126
- public function translateNegation (Node \NegationNode $ node )
122
+ public function translateNegation (Node \NegationNode $ node, Translator $ translator )
127
123
{
128
- $ xpath = $ this -> translator ->nodeToXPath ($ node ->getSelector ());
129
- $ subXpath = $ this -> translator ->nodeToXPath ($ node ->getSubSelector ());
124
+ $ xpath = $ translator ->nodeToXPath ($ node ->getSelector ());
125
+ $ subXpath = $ translator ->nodeToXPath ($ node ->getSubSelector ());
130
126
$ subXpath ->addNameTest ();
131
127
132
128
if ($ subXpath ->getCondition ()) {
@@ -138,34 +134,37 @@ public function translateNegation(Node\NegationNode $node)
138
134
139
135
/**
140
136
* @param Node\FunctionNode $node
137
+ * @param Translator $translator
141
138
*
142
139
* @return XPathExpr
143
140
*/
144
- public function translateFunction (Node \FunctionNode $ node )
141
+ public function translateFunction (Node \FunctionNode $ node, Translator $ translator )
145
142
{
146
- $ xpath = $ this -> translator ->nodeToXPath ($ node ->getSelector ());
143
+ $ xpath = $ translator ->nodeToXPath ($ node ->getSelector ());
147
144
148
- return $ this -> translator ->addFunction ($ xpath , $ node );
145
+ return $ translator ->addFunction ($ xpath , $ node );
149
146
}
150
147
151
148
/**
152
149
* @param Node\PseudoNode $node
150
+ * @param Translator $translator
153
151
*
154
152
* @return XPathExpr
155
153
*/
156
- public function translatePseudo (Node \PseudoNode $ node )
154
+ public function translatePseudo (Node \PseudoNode $ node, Translator $ translator )
157
155
{
158
- $ xpath = $ this -> translator ->nodeToXPath ($ node ->getSelector ());
156
+ $ xpath = $ translator ->nodeToXPath ($ node ->getSelector ());
159
157
160
- return $ this -> translator ->addPseudoClass ($ xpath , $ node ->getIdentifier ());
158
+ return $ translator ->addPseudoClass ($ xpath , $ node ->getIdentifier ());
161
159
}
162
160
163
161
/**
164
162
* @param Node\AttributeNode $node
163
+ * @param Translator $translator
165
164
*
166
165
* @return XPathExpr
167
166
*/
168
- public function translateAttribute (Node \AttributeNode $ node )
167
+ public function translateAttribute (Node \AttributeNode $ node, Translator $ translator )
169
168
{
170
169
$ name = $ node ->getAttribute ();
171
170
$ safe = $ this ->isSafeName ($ name );
@@ -181,37 +180,39 @@ public function translateAttribute(Node\AttributeNode $node)
181
180
182
181
$ attribute = $ safe ? '@ ' .$ name : sprintf ('attribute::*[name() = %s] ' , Translator::getXpathLiteral ($ name ));
183
182
$ value = $ node ->getValue ();
184
- $ xpath = $ this -> translator ->nodeToXPath ($ node ->getSelector ());
183
+ $ xpath = $ translator ->nodeToXPath ($ node ->getSelector ());
185
184
186
185
if ($ this ->hasFlag (self ::ATTRIBUTE_VALUE_IN_LOWER_CASE )) {
187
186
$ value = strtolower ($ value );
188
187
}
189
188
190
- return $ this -> translator ->addAttributeMatching ($ xpath , $ node ->getOperator (), $ attribute , $ value );
189
+ return $ translator ->addAttributeMatching ($ xpath , $ node ->getOperator (), $ attribute , $ value );
191
190
}
192
191
193
192
/**
194
193
* @param Node\ClassNode $node
194
+ * @param Translator $translator
195
195
*
196
196
* @return XPathExpr
197
197
*/
198
- public function translateClass (Node \ClassNode $ node )
198
+ public function translateClass (Node \ClassNode $ node, Translator $ translator )
199
199
{
200
- $ xpath = $ this -> translator ->nodeToXPath ($ node ->getSelector ());
200
+ $ xpath = $ translator ->nodeToXPath ($ node ->getSelector ());
201
201
202
- return $ this -> translator ->addAttributeMatching ($ xpath , '~= ' , '@class ' , $ node ->getName ());
202
+ return $ translator ->addAttributeMatching ($ xpath , '~= ' , '@class ' , $ node ->getName ());
203
203
}
204
204
205
205
/**
206
206
* @param Node\HashNode $node
207
+ * @param Translator $translator
207
208
*
208
209
* @return XPathExpr
209
210
*/
210
- public function translateHash (Node \HashNode $ node )
211
+ public function translateHash (Node \HashNode $ node, Translator $ translator )
211
212
{
212
- $ xpath = $ this -> translator ->nodeToXPath ($ node ->getSelector ());
213
+ $ xpath = $ translator ->nodeToXPath ($ node ->getSelector ());
213
214
214
- return $ this -> translator ->addAttributeMatching ($ xpath , '= ' , '@id ' , $ node ->getId ());
215
+ return $ translator ->addAttributeMatching ($ xpath , '= ' , '@id ' , $ node ->getId ());
215
216
}
216
217
217
218
/**
0 commit comments