1 | <?php namespace Luminaire\Premailer\Parser; |
||
26 | class RelevantSelectorParser |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * The pseudo classes that can be set in a style attribute and that are |
||
31 | * supported by the Symfony CssSelector (doesn't support CSS4 yet). |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $allowed_pseudo_classes = [ |
||
36 | StyleSelector::PSEUDO_CLASS_FIRST_CHILD, |
||
37 | StyleSelector::PSEUDO_CLASS_ROOT, |
||
38 | StyleSelector::PSEUDO_CLASS_NTH_CHILD, |
||
39 | StyleSelector::PSEUDO_CLASS_NTH_LAST_CHILD, |
||
40 | StyleSelector::PSEUDO_CLASS_NTH_OF_TYPE, |
||
41 | StyleSelector::PSEUDO_CLASS_NTH_LAST_OF_TYPE, |
||
42 | StyleSelector::PSEUDO_CLASS_LAST_CHILD, |
||
43 | StyleSelector::PSEUDO_CLASS_FIRST_OF_TYPE, |
||
44 | StyleSelector::PSEUDO_CLASS_LAST_OF_TYPE, |
||
45 | StyleSelector::PSEUDO_CLASS_ONLY_CHILD, |
||
46 | StyleSelector::PSEUDO_CLASS_ONLY_OF_TYPE, |
||
47 | StyleSelector::PSEUDO_CLASS_EMPTY, |
||
48 | StyleSelector::PSEUDO_CLASS_NOT, |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * The stylesheet reader instance |
||
53 | * |
||
54 | * @var \Crossjoin\Css\Reader\CssString |
||
55 | */ |
||
56 | protected $reader; |
||
57 | |||
58 | /** |
||
59 | * The charset of the stylesheet |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $charset; |
||
64 | |||
65 | /** |
||
66 | * Create a new instance of "Relevant Selector Parser" |
||
67 | * |
||
68 | * @param \Crossjoin\Css\Reader\CssString|string|null $stylesheet |
||
69 | * @param string $charset |
||
70 | */ |
||
71 | public function __construct($stylesheet = null, $charset = 'UTF-8') |
||
80 | |||
81 | /** |
||
82 | * Get the relevant selectors |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | public function extract() |
||
99 | |||
100 | /** |
||
101 | * Store the selectors from the rule to the tank |
||
102 | * |
||
103 | * @param array &$tank |
||
104 | * @param array $rule |
||
105 | * @return void |
||
106 | */ |
||
107 | protected function populateSelectors(array &$tank, $rule) |
||
133 | |||
134 | /** |
||
135 | * Store the declaration in the selector tank |
||
136 | * |
||
137 | * @param array &$tank |
||
138 | * @param \Crossjoin\Css\Format\Rule\Style\StyleDeclaration $declaration |
||
139 | * @param string $specifity |
||
140 | * @param string $name |
||
141 | * @return void |
||
142 | */ |
||
143 | protected function storeDeclaration(array &$tank, $declaration, $specifity, $name) |
||
147 | |||
148 | /** |
||
149 | * Before we build the dictionary of style declaration, we will need to make |
||
150 | * sure, there is an array to be inserted. |
||
151 | * |
||
152 | * @param array &$selectors |
||
153 | * @param string $specifity |
||
154 | * @param string $name |
||
155 | * @return void |
||
156 | */ |
||
157 | protected function prepareSelectorArray(array &$selectors, $specifity, $name) |
||
169 | |||
170 | /** |
||
171 | * Set the stylesheet reader instance |
||
172 | * |
||
173 | * @param \Crossjoin\Css\Reader\CssString|string $stylesheet |
||
174 | * @return $this |
||
175 | * |
||
176 | * @throws \InvalidArgumentException |
||
177 | */ |
||
178 | public function setStylesheetReader($stylesheet) |
||
195 | |||
196 | /** |
||
197 | * Get the stylesheet reader instance |
||
198 | * |
||
199 | * @return \Crossjoin\Css\Reader\CssString|null |
||
200 | */ |
||
201 | public function getStylesheetReader() |
||
205 | |||
206 | /** |
||
207 | * Set the charset of the stylesheet |
||
208 | * |
||
209 | * @param string $charset |
||
210 | * @return $this |
||
211 | */ |
||
212 | public function setCharset($charset) |
||
218 | |||
219 | /** |
||
220 | * Get the charset of the stylesheet |
||
221 | * |
||
222 | * @return string |
||
223 | */ |
||
224 | public function getCharset() |
||
228 | |||
229 | /** |
||
230 | * Check if a Selector has a valid Pseudo Class |
||
231 | * |
||
232 | * @param \Crossjoin\Css\Format\Rule\Style\StyleSelector $selector |
||
233 | * @return bool |
||
234 | */ |
||
235 | public function isPseudoClassAllowed(StyleSelector $selector) |
||
247 | |||
248 | /** |
||
249 | * Gets all generally relevant style rules |
||
250 | * |
||
251 | * @param \Crossjoin\Css\Format\Rule\RuleAbstract[] $rules |
||
252 | * @return \Crossjoin\Css\Format\Rule\Style\StyleRuleSet[] |
||
253 | */ |
||
254 | protected function getRelevantStyleRules(array $rules) |
||
273 | |||
274 | /** |
||
275 | * Gets the relevant style rules from a media rule |
||
276 | * |
||
277 | * @param \Crossjoin\Css\Format\Rule\AtMedia\MediaRule $rule |
||
278 | * @param array &$collection |
||
279 | * @return void |
||
280 | */ |
||
281 | protected function getRelevantMediaRule(MediaRule $rule, &$collection) |
||
298 | |||
299 | /** |
||
300 | * Check if the media rule should be included |
||
301 | * |
||
302 | * @param \Crossjoin\Css\Format\Rule\AtMedia\MediaQuery $media_query |
||
303 | * @return bool |
||
304 | */ |
||
305 | protected function isAllowedMediaRule(MediaQuery $media_query) |
||
312 | |||
313 | } |
||
314 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: