@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | { |
172 | 172 | $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i']; |
173 | 173 | foreach ($aVarPrefixes as $sPrefix) { |
174 | - $sFieldName = $sPrefix . ucfirst($sName); |
|
174 | + $sFieldName = $sPrefix.ucfirst($sName); |
|
175 | 175 | if (isset($this->$sFieldName)) { |
176 | 176 | return $this->$sFieldName; |
177 | 177 | } |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | str_replace('*', 'Between', $aNames), |
196 | 196 | str_replace('*', 'After', $aNames), |
197 | 197 | ]; |
198 | - } elseif (!is_array($aNames)) { |
|
198 | + } elseif ( ! is_array($aNames)) { |
|
199 | 199 | $aNames = [$aNames]; |
200 | 200 | } |
201 | 201 | foreach ($aVarPrefixes as $sPrefix) { |
202 | 202 | $bDidReplace = false; |
203 | 203 | foreach ($aNames as $sName) { |
204 | - $sFieldName = $sPrefix . ucfirst($sName); |
|
204 | + $sFieldName = $sPrefix.ucfirst($sName); |
|
205 | 205 | if (isset($this->$sFieldName)) { |
206 | 206 | $this->$sFieldName = $mValue; |
207 | 207 | $bDidReplace = true; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | } elseif (method_exists(OutputFormatter::class, $sMethodName)) { |
233 | 233 | return call_user_func_array([$this->getFormatter(), $sMethodName], $aArguments); |
234 | 234 | } else { |
235 | - throw new \Exception('Unknown OutputFormat method called: ' . $sMethodName); |
|
235 | + throw new \Exception('Unknown OutputFormat method called: '.$sMethodName); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 |
@@ -10,339 +10,339 @@ |
||
10 | 10 | */ |
11 | 11 | class OutputFormat |
12 | 12 | { |
13 | - /** |
|
14 | - * Value format: `"` means double-quote, `'` means single-quote |
|
15 | - * |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - public $sStringQuotingType = '"'; |
|
19 | - |
|
20 | - /** |
|
21 | - * Output RGB colors in hash notation if possible |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - public $bRGBHashNotation = true; |
|
26 | - |
|
27 | - /** |
|
28 | - * Declaration format |
|
29 | - * |
|
30 | - * Semicolon after the last rule of a declaration block can be omitted. To do that, set this false. |
|
31 | - * |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - public $bSemicolonAfterLastRule = true; |
|
35 | - |
|
36 | - /** |
|
37 | - * Spacing |
|
38 | - * Note that these strings are not sanity-checked: the value should only consist of whitespace |
|
39 | - * Any newline character will be indented according to the current level. |
|
40 | - * The triples (After, Before, Between) can be set using a wildcard (e.g. `$oFormat->set('Space*Rules', "\n");`) |
|
41 | - */ |
|
42 | - public $sSpaceAfterRuleName = ' '; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - public $sSpaceBeforeRules = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $sSpaceAfterRules = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $sSpaceBetweenRules = ''; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - public $sSpaceBeforeBlocks = ''; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $sSpaceAfterBlocks = ''; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - public $sSpaceBetweenBlocks = "\n"; |
|
73 | - |
|
74 | - /** |
|
75 | - * Content injected in and around at-rule blocks. |
|
76 | - * |
|
77 | - * @var string |
|
78 | - */ |
|
79 | - public $sBeforeAtRuleBlock = ''; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var string |
|
83 | - */ |
|
84 | - public $sAfterAtRuleBlock = ''; |
|
85 | - |
|
86 | - /** |
|
87 | - * This is what’s printed before and after the comma if a declaration block contains multiple selectors. |
|
88 | - * |
|
89 | - * @var string |
|
90 | - */ |
|
91 | - public $sSpaceBeforeSelectorSeparator = ''; |
|
92 | - |
|
93 | - /** |
|
94 | - * @var string |
|
95 | - */ |
|
96 | - public $sSpaceAfterSelectorSeparator = ' '; |
|
97 | - |
|
98 | - /** |
|
99 | - * This is what’s printed after the comma of value lists |
|
100 | - * |
|
101 | - * @var string |
|
102 | - */ |
|
103 | - public $sSpaceBeforeListArgumentSeparator = ''; |
|
104 | - |
|
105 | - /** |
|
106 | - * @var string |
|
107 | - */ |
|
108 | - public $sSpaceAfterListArgumentSeparator = ''; |
|
109 | - |
|
110 | - /** |
|
111 | - * @var string |
|
112 | - */ |
|
113 | - public $sSpaceBeforeOpeningBrace = ' '; |
|
114 | - |
|
115 | - /** |
|
116 | - * Content injected in and around declaration blocks. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $sBeforeDeclarationBlock = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * @var string |
|
124 | - */ |
|
125 | - public $sAfterDeclarationBlockSelectors = ''; |
|
126 | - |
|
127 | - /** |
|
128 | - * @var string |
|
129 | - */ |
|
130 | - public $sAfterDeclarationBlock = ''; |
|
131 | - |
|
132 | - /** |
|
133 | - * Indentation character(s) per level. Only applicable if newlines are used in any of the spacing settings. |
|
134 | - * |
|
135 | - * @var string |
|
136 | - */ |
|
137 | - public $sIndentation = "\t"; |
|
138 | - |
|
139 | - /** |
|
140 | - * Output exceptions. |
|
141 | - * |
|
142 | - * @var bool |
|
143 | - */ |
|
144 | - public $bIgnoreExceptions = false; |
|
145 | - |
|
146 | - /** |
|
147 | - * Render comments for lists and RuleSets |
|
148 | - * |
|
149 | - * @var bool |
|
150 | - */ |
|
151 | - public $bRenderComments = false; |
|
152 | - |
|
153 | - /** |
|
154 | - * @var OutputFormatter|null |
|
155 | - */ |
|
156 | - private $oFormatter = null; |
|
157 | - |
|
158 | - /** |
|
159 | - * @var OutputFormat|null |
|
160 | - */ |
|
161 | - private $oNextLevelFormat = null; |
|
162 | - |
|
163 | - /** |
|
164 | - * @var int |
|
165 | - */ |
|
166 | - private $iIndentationLevel = 0; |
|
167 | - |
|
168 | - public function __construct() |
|
169 | - { |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @param string $sName |
|
174 | - * |
|
175 | - * @return string|null |
|
176 | - */ |
|
177 | - public function get($sName) |
|
178 | - { |
|
179 | - $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i']; |
|
180 | - foreach ($aVarPrefixes as $sPrefix) { |
|
181 | - $sFieldName = $sPrefix . ucfirst($sName); |
|
182 | - if (isset($this->$sFieldName)) { |
|
183 | - return $this->$sFieldName; |
|
184 | - } |
|
185 | - } |
|
186 | - return null; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @param array<array-key, string>|string $aNames |
|
191 | - * @param mixed $mValue |
|
192 | - * |
|
193 | - * @return self|false |
|
194 | - */ |
|
195 | - public function set($aNames, $mValue) |
|
196 | - { |
|
197 | - $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i']; |
|
198 | - if (is_string($aNames) && strpos($aNames, '*') !== false) { |
|
199 | - $aNames = |
|
200 | - [ |
|
201 | - str_replace('*', 'Before', $aNames), |
|
202 | - str_replace('*', 'Between', $aNames), |
|
203 | - str_replace('*', 'After', $aNames), |
|
204 | - ]; |
|
205 | - } elseif (!is_array($aNames)) { |
|
206 | - $aNames = [$aNames]; |
|
207 | - } |
|
208 | - foreach ($aVarPrefixes as $sPrefix) { |
|
209 | - $bDidReplace = false; |
|
210 | - foreach ($aNames as $sName) { |
|
211 | - $sFieldName = $sPrefix . ucfirst($sName); |
|
212 | - if (isset($this->$sFieldName)) { |
|
213 | - $this->$sFieldName = $mValue; |
|
214 | - $bDidReplace = true; |
|
215 | - } |
|
216 | - } |
|
217 | - if ($bDidReplace) { |
|
218 | - return $this; |
|
219 | - } |
|
220 | - } |
|
221 | - // Break the chain so the user knows this option is invalid |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @param string $sMethodName |
|
227 | - * @param array<array-key, mixed> $aArguments |
|
228 | - * |
|
229 | - * @return mixed |
|
230 | - * |
|
231 | - * @throws \Exception |
|
232 | - */ |
|
233 | - public function __call($sMethodName, array $aArguments) |
|
234 | - { |
|
235 | - if (strpos($sMethodName, 'set') === 0) { |
|
236 | - return $this->set(substr($sMethodName, 3), $aArguments[0]); |
|
237 | - } elseif (strpos($sMethodName, 'get') === 0) { |
|
238 | - return $this->get(substr($sMethodName, 3)); |
|
239 | - } elseif (method_exists(OutputFormatter::class, $sMethodName)) { |
|
240 | - return call_user_func_array([$this->getFormatter(), $sMethodName], $aArguments); |
|
241 | - } else { |
|
242 | - throw new \Exception('Unknown OutputFormat method called: ' . $sMethodName); |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @param int $iNumber |
|
248 | - * |
|
249 | - * @return self |
|
250 | - */ |
|
251 | - public function indentWithTabs($iNumber = 1) |
|
252 | - { |
|
253 | - return $this->setIndentation(str_repeat("\t", $iNumber)); |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @param int $iNumber |
|
258 | - * |
|
259 | - * @return self |
|
260 | - */ |
|
261 | - public function indentWithSpaces($iNumber = 2) |
|
262 | - { |
|
263 | - return $this->setIndentation(str_repeat(" ", $iNumber)); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * @return OutputFormat |
|
268 | - */ |
|
269 | - public function nextLevel() |
|
270 | - { |
|
271 | - if ($this->oNextLevelFormat === null) { |
|
272 | - $this->oNextLevelFormat = clone $this; |
|
273 | - $this->oNextLevelFormat->iIndentationLevel++; |
|
274 | - $this->oNextLevelFormat->oFormatter = null; |
|
275 | - } |
|
276 | - return $this->oNextLevelFormat; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - public function beLenient() |
|
283 | - { |
|
284 | - $this->bIgnoreExceptions = true; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @return OutputFormatter |
|
289 | - */ |
|
290 | - public function getFormatter() |
|
291 | - { |
|
292 | - if ($this->oFormatter === null) { |
|
293 | - $this->oFormatter = new OutputFormatter($this); |
|
294 | - } |
|
295 | - return $this->oFormatter; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * @return int |
|
300 | - */ |
|
301 | - public function level() |
|
302 | - { |
|
303 | - return $this->iIndentationLevel; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Creates an instance of this class without any particular formatting settings. |
|
308 | - * |
|
309 | - * @return self |
|
310 | - */ |
|
311 | - public static function create() |
|
312 | - { |
|
313 | - return new OutputFormat(); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Creates an instance of this class with a preset for compact formatting. |
|
318 | - * |
|
319 | - * @return self |
|
320 | - */ |
|
321 | - public static function createCompact() |
|
322 | - { |
|
323 | - $format = self::create(); |
|
324 | - $format->set('Space*Rules', "") |
|
325 | - ->set('Space*Blocks', "") |
|
326 | - ->setSpaceAfterRuleName('') |
|
327 | - ->setSpaceBeforeOpeningBrace('') |
|
328 | - ->setSpaceAfterSelectorSeparator('') |
|
329 | - ->setRenderComments(false); |
|
330 | - return $format; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Creates an instance of this class with a preset for pretty formatting. |
|
335 | - * |
|
336 | - * @return self |
|
337 | - */ |
|
338 | - public static function createPretty() |
|
339 | - { |
|
340 | - $format = self::create(); |
|
341 | - $format->set('Space*Rules', "\n") |
|
342 | - ->set('Space*Blocks', "\n") |
|
343 | - ->setSpaceBetweenBlocks("\n\n") |
|
344 | - ->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' ']) |
|
345 | - ->setRenderComments(true); |
|
346 | - return $format; |
|
347 | - } |
|
13 | + /** |
|
14 | + * Value format: `"` means double-quote, `'` means single-quote |
|
15 | + * |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + public $sStringQuotingType = '"'; |
|
19 | + |
|
20 | + /** |
|
21 | + * Output RGB colors in hash notation if possible |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + public $bRGBHashNotation = true; |
|
26 | + |
|
27 | + /** |
|
28 | + * Declaration format |
|
29 | + * |
|
30 | + * Semicolon after the last rule of a declaration block can be omitted. To do that, set this false. |
|
31 | + * |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + public $bSemicolonAfterLastRule = true; |
|
35 | + |
|
36 | + /** |
|
37 | + * Spacing |
|
38 | + * Note that these strings are not sanity-checked: the value should only consist of whitespace |
|
39 | + * Any newline character will be indented according to the current level. |
|
40 | + * The triples (After, Before, Between) can be set using a wildcard (e.g. `$oFormat->set('Space*Rules', "\n");`) |
|
41 | + */ |
|
42 | + public $sSpaceAfterRuleName = ' '; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + public $sSpaceBeforeRules = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $sSpaceAfterRules = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $sSpaceBetweenRules = ''; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + public $sSpaceBeforeBlocks = ''; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $sSpaceAfterBlocks = ''; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + public $sSpaceBetweenBlocks = "\n"; |
|
73 | + |
|
74 | + /** |
|
75 | + * Content injected in and around at-rule blocks. |
|
76 | + * |
|
77 | + * @var string |
|
78 | + */ |
|
79 | + public $sBeforeAtRuleBlock = ''; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var string |
|
83 | + */ |
|
84 | + public $sAfterAtRuleBlock = ''; |
|
85 | + |
|
86 | + /** |
|
87 | + * This is what’s printed before and after the comma if a declaration block contains multiple selectors. |
|
88 | + * |
|
89 | + * @var string |
|
90 | + */ |
|
91 | + public $sSpaceBeforeSelectorSeparator = ''; |
|
92 | + |
|
93 | + /** |
|
94 | + * @var string |
|
95 | + */ |
|
96 | + public $sSpaceAfterSelectorSeparator = ' '; |
|
97 | + |
|
98 | + /** |
|
99 | + * This is what’s printed after the comma of value lists |
|
100 | + * |
|
101 | + * @var string |
|
102 | + */ |
|
103 | + public $sSpaceBeforeListArgumentSeparator = ''; |
|
104 | + |
|
105 | + /** |
|
106 | + * @var string |
|
107 | + */ |
|
108 | + public $sSpaceAfterListArgumentSeparator = ''; |
|
109 | + |
|
110 | + /** |
|
111 | + * @var string |
|
112 | + */ |
|
113 | + public $sSpaceBeforeOpeningBrace = ' '; |
|
114 | + |
|
115 | + /** |
|
116 | + * Content injected in and around declaration blocks. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $sBeforeDeclarationBlock = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * @var string |
|
124 | + */ |
|
125 | + public $sAfterDeclarationBlockSelectors = ''; |
|
126 | + |
|
127 | + /** |
|
128 | + * @var string |
|
129 | + */ |
|
130 | + public $sAfterDeclarationBlock = ''; |
|
131 | + |
|
132 | + /** |
|
133 | + * Indentation character(s) per level. Only applicable if newlines are used in any of the spacing settings. |
|
134 | + * |
|
135 | + * @var string |
|
136 | + */ |
|
137 | + public $sIndentation = "\t"; |
|
138 | + |
|
139 | + /** |
|
140 | + * Output exceptions. |
|
141 | + * |
|
142 | + * @var bool |
|
143 | + */ |
|
144 | + public $bIgnoreExceptions = false; |
|
145 | + |
|
146 | + /** |
|
147 | + * Render comments for lists and RuleSets |
|
148 | + * |
|
149 | + * @var bool |
|
150 | + */ |
|
151 | + public $bRenderComments = false; |
|
152 | + |
|
153 | + /** |
|
154 | + * @var OutputFormatter|null |
|
155 | + */ |
|
156 | + private $oFormatter = null; |
|
157 | + |
|
158 | + /** |
|
159 | + * @var OutputFormat|null |
|
160 | + */ |
|
161 | + private $oNextLevelFormat = null; |
|
162 | + |
|
163 | + /** |
|
164 | + * @var int |
|
165 | + */ |
|
166 | + private $iIndentationLevel = 0; |
|
167 | + |
|
168 | + public function __construct() |
|
169 | + { |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @param string $sName |
|
174 | + * |
|
175 | + * @return string|null |
|
176 | + */ |
|
177 | + public function get($sName) |
|
178 | + { |
|
179 | + $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i']; |
|
180 | + foreach ($aVarPrefixes as $sPrefix) { |
|
181 | + $sFieldName = $sPrefix . ucfirst($sName); |
|
182 | + if (isset($this->$sFieldName)) { |
|
183 | + return $this->$sFieldName; |
|
184 | + } |
|
185 | + } |
|
186 | + return null; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @param array<array-key, string>|string $aNames |
|
191 | + * @param mixed $mValue |
|
192 | + * |
|
193 | + * @return self|false |
|
194 | + */ |
|
195 | + public function set($aNames, $mValue) |
|
196 | + { |
|
197 | + $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i']; |
|
198 | + if (is_string($aNames) && strpos($aNames, '*') !== false) { |
|
199 | + $aNames = |
|
200 | + [ |
|
201 | + str_replace('*', 'Before', $aNames), |
|
202 | + str_replace('*', 'Between', $aNames), |
|
203 | + str_replace('*', 'After', $aNames), |
|
204 | + ]; |
|
205 | + } elseif (!is_array($aNames)) { |
|
206 | + $aNames = [$aNames]; |
|
207 | + } |
|
208 | + foreach ($aVarPrefixes as $sPrefix) { |
|
209 | + $bDidReplace = false; |
|
210 | + foreach ($aNames as $sName) { |
|
211 | + $sFieldName = $sPrefix . ucfirst($sName); |
|
212 | + if (isset($this->$sFieldName)) { |
|
213 | + $this->$sFieldName = $mValue; |
|
214 | + $bDidReplace = true; |
|
215 | + } |
|
216 | + } |
|
217 | + if ($bDidReplace) { |
|
218 | + return $this; |
|
219 | + } |
|
220 | + } |
|
221 | + // Break the chain so the user knows this option is invalid |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @param string $sMethodName |
|
227 | + * @param array<array-key, mixed> $aArguments |
|
228 | + * |
|
229 | + * @return mixed |
|
230 | + * |
|
231 | + * @throws \Exception |
|
232 | + */ |
|
233 | + public function __call($sMethodName, array $aArguments) |
|
234 | + { |
|
235 | + if (strpos($sMethodName, 'set') === 0) { |
|
236 | + return $this->set(substr($sMethodName, 3), $aArguments[0]); |
|
237 | + } elseif (strpos($sMethodName, 'get') === 0) { |
|
238 | + return $this->get(substr($sMethodName, 3)); |
|
239 | + } elseif (method_exists(OutputFormatter::class, $sMethodName)) { |
|
240 | + return call_user_func_array([$this->getFormatter(), $sMethodName], $aArguments); |
|
241 | + } else { |
|
242 | + throw new \Exception('Unknown OutputFormat method called: ' . $sMethodName); |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @param int $iNumber |
|
248 | + * |
|
249 | + * @return self |
|
250 | + */ |
|
251 | + public function indentWithTabs($iNumber = 1) |
|
252 | + { |
|
253 | + return $this->setIndentation(str_repeat("\t", $iNumber)); |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @param int $iNumber |
|
258 | + * |
|
259 | + * @return self |
|
260 | + */ |
|
261 | + public function indentWithSpaces($iNumber = 2) |
|
262 | + { |
|
263 | + return $this->setIndentation(str_repeat(" ", $iNumber)); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * @return OutputFormat |
|
268 | + */ |
|
269 | + public function nextLevel() |
|
270 | + { |
|
271 | + if ($this->oNextLevelFormat === null) { |
|
272 | + $this->oNextLevelFormat = clone $this; |
|
273 | + $this->oNextLevelFormat->iIndentationLevel++; |
|
274 | + $this->oNextLevelFormat->oFormatter = null; |
|
275 | + } |
|
276 | + return $this->oNextLevelFormat; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + public function beLenient() |
|
283 | + { |
|
284 | + $this->bIgnoreExceptions = true; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @return OutputFormatter |
|
289 | + */ |
|
290 | + public function getFormatter() |
|
291 | + { |
|
292 | + if ($this->oFormatter === null) { |
|
293 | + $this->oFormatter = new OutputFormatter($this); |
|
294 | + } |
|
295 | + return $this->oFormatter; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * @return int |
|
300 | + */ |
|
301 | + public function level() |
|
302 | + { |
|
303 | + return $this->iIndentationLevel; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Creates an instance of this class without any particular formatting settings. |
|
308 | + * |
|
309 | + * @return self |
|
310 | + */ |
|
311 | + public static function create() |
|
312 | + { |
|
313 | + return new OutputFormat(); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Creates an instance of this class with a preset for compact formatting. |
|
318 | + * |
|
319 | + * @return self |
|
320 | + */ |
|
321 | + public static function createCompact() |
|
322 | + { |
|
323 | + $format = self::create(); |
|
324 | + $format->set('Space*Rules', "") |
|
325 | + ->set('Space*Blocks', "") |
|
326 | + ->setSpaceAfterRuleName('') |
|
327 | + ->setSpaceBeforeOpeningBrace('') |
|
328 | + ->setSpaceAfterSelectorSeparator('') |
|
329 | + ->setRenderComments(false); |
|
330 | + return $format; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Creates an instance of this class with a preset for pretty formatting. |
|
335 | + * |
|
336 | + * @return self |
|
337 | + */ |
|
338 | + public static function createPretty() |
|
339 | + { |
|
340 | + $format = self::create(); |
|
341 | + $format->set('Space*Rules', "\n") |
|
342 | + ->set('Space*Blocks', "\n") |
|
343 | + ->setSpaceBetweenBlocks("\n\n") |
|
344 | + ->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' ']) |
|
345 | + ->setRenderComments(true); |
|
346 | + return $format; |
|
347 | + } |
|
348 | 348 | } |
@@ -7,65 +7,65 @@ |
||
7 | 7 | |
8 | 8 | class Comment implements Renderable |
9 | 9 | { |
10 | - /** |
|
11 | - * @var int |
|
12 | - */ |
|
13 | - protected $iLineNo; |
|
10 | + /** |
|
11 | + * @var int |
|
12 | + */ |
|
13 | + protected $iLineNo; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - protected $sComment; |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + protected $sComment; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param string $sComment |
|
22 | - * @param int $iLineNo |
|
23 | - */ |
|
24 | - public function __construct($sComment = '', $iLineNo = 0) |
|
25 | - { |
|
26 | - $this->sComment = $sComment; |
|
27 | - $this->iLineNo = $iLineNo; |
|
28 | - } |
|
20 | + /** |
|
21 | + * @param string $sComment |
|
22 | + * @param int $iLineNo |
|
23 | + */ |
|
24 | + public function __construct($sComment = '', $iLineNo = 0) |
|
25 | + { |
|
26 | + $this->sComment = $sComment; |
|
27 | + $this->iLineNo = $iLineNo; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function getComment() |
|
34 | - { |
|
35 | - return $this->sComment; |
|
36 | - } |
|
30 | + /** |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function getComment() |
|
34 | + { |
|
35 | + return $this->sComment; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return int |
|
40 | - */ |
|
41 | - public function getLineNo() |
|
42 | - { |
|
43 | - return $this->iLineNo; |
|
44 | - } |
|
38 | + /** |
|
39 | + * @return int |
|
40 | + */ |
|
41 | + public function getLineNo() |
|
42 | + { |
|
43 | + return $this->iLineNo; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param string $sComment |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function setComment($sComment) |
|
52 | - { |
|
53 | - $this->sComment = $sComment; |
|
54 | - } |
|
46 | + /** |
|
47 | + * @param string $sComment |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function setComment($sComment) |
|
52 | + { |
|
53 | + $this->sComment = $sComment; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function __toString() |
|
60 | - { |
|
61 | - return $this->render(new OutputFormat()); |
|
62 | - } |
|
56 | + /** |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function __toString() |
|
60 | + { |
|
61 | + return $this->render(new OutputFormat()); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function render(OutputFormat $oOutputFormat) |
|
68 | - { |
|
69 | - return '/*' . $this->sComment . '*/'; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function render(OutputFormat $oOutputFormat) |
|
68 | + { |
|
69 | + return '/*' . $this->sComment . '*/'; |
|
70 | + } |
|
71 | 71 | } |
@@ -66,6 +66,6 @@ |
||
66 | 66 | */ |
67 | 67 | public function render(OutputFormat $oOutputFormat) |
68 | 68 | { |
69 | - return '/*' . $this->sComment . '*/'; |
|
69 | + return '/*'.$this->sComment.'*/'; |
|
70 | 70 | } |
71 | 71 | } |
@@ -4,22 +4,22 @@ |
||
4 | 4 | |
5 | 5 | interface Commentable |
6 | 6 | { |
7 | - /** |
|
8 | - * @param array<array-key, Comment> $aComments |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function addComments(array $aComments); |
|
7 | + /** |
|
8 | + * @param array<array-key, Comment> $aComments |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function addComments(array $aComments); |
|
13 | 13 | |
14 | - /** |
|
15 | - * @return array<array-key, Comment> |
|
16 | - */ |
|
17 | - public function getComments(); |
|
14 | + /** |
|
15 | + * @return array<array-key, Comment> |
|
16 | + */ |
|
17 | + public function getComments(); |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param array<array-key, Comment> $aComments |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function setComments(array $aComments); |
|
19 | + /** |
|
20 | + * @param array<array-key, Comment> $aComments |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function setComments(array $aComments); |
|
25 | 25 | } |
@@ -7,45 +7,45 @@ |
||
7 | 7 | */ |
8 | 8 | class UnexpectedTokenException extends SourceException |
9 | 9 | { |
10 | - /** |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - private $sExpected; |
|
10 | + /** |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + private $sExpected; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - private $sFound; |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + private $sFound; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Possible values: literal, identifier, count, expression, search |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - private $sMatchType; |
|
20 | + /** |
|
21 | + * Possible values: literal, identifier, count, expression, search |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + private $sMatchType; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param string $sExpected |
|
29 | - * @param string $sFound |
|
30 | - * @param string $sMatchType |
|
31 | - * @param int $iLineNo |
|
32 | - */ |
|
33 | - public function __construct($sExpected, $sFound, $sMatchType = 'literal', $iLineNo = 0) |
|
34 | - { |
|
35 | - $this->sExpected = $sExpected; |
|
36 | - $this->sFound = $sFound; |
|
37 | - $this->sMatchType = $sMatchType; |
|
38 | - $sMessage = "Token “{$sExpected}” ({$sMatchType}) not found. Got “{$sFound}”."; |
|
39 | - if ($this->sMatchType === 'search') { |
|
40 | - $sMessage = "Search for “{$sExpected}” returned no results. Context: “{$sFound}”."; |
|
41 | - } elseif ($this->sMatchType === 'count') { |
|
42 | - $sMessage = "Next token was expected to have {$sExpected} chars. Context: “{$sFound}”."; |
|
43 | - } elseif ($this->sMatchType === 'identifier') { |
|
44 | - $sMessage = "Identifier expected. Got “{$sFound}”"; |
|
45 | - } elseif ($this->sMatchType === 'custom') { |
|
46 | - $sMessage = trim("$sExpected $sFound"); |
|
47 | - } |
|
27 | + /** |
|
28 | + * @param string $sExpected |
|
29 | + * @param string $sFound |
|
30 | + * @param string $sMatchType |
|
31 | + * @param int $iLineNo |
|
32 | + */ |
|
33 | + public function __construct($sExpected, $sFound, $sMatchType = 'literal', $iLineNo = 0) |
|
34 | + { |
|
35 | + $this->sExpected = $sExpected; |
|
36 | + $this->sFound = $sFound; |
|
37 | + $this->sMatchType = $sMatchType; |
|
38 | + $sMessage = "Token “{$sExpected}” ({$sMatchType}) not found. Got “{$sFound}”."; |
|
39 | + if ($this->sMatchType === 'search') { |
|
40 | + $sMessage = "Search for “{$sExpected}” returned no results. Context: “{$sFound}”."; |
|
41 | + } elseif ($this->sMatchType === 'count') { |
|
42 | + $sMessage = "Next token was expected to have {$sExpected} chars. Context: “{$sFound}”."; |
|
43 | + } elseif ($this->sMatchType === 'identifier') { |
|
44 | + $sMessage = "Identifier expected. Got “{$sFound}”"; |
|
45 | + } elseif ($this->sMatchType === 'custom') { |
|
46 | + $sMessage = trim("$sExpected $sFound"); |
|
47 | + } |
|
48 | 48 | |
49 | - parent::__construct($sMessage, $iLineNo); |
|
50 | - } |
|
49 | + parent::__construct($sMessage, $iLineNo); |
|
50 | + } |
|
51 | 51 | } |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | class SourceException extends \Exception |
6 | 6 | { |
7 | - /** |
|
8 | - * @var int |
|
9 | - */ |
|
10 | - private $iLineNo; |
|
7 | + /** |
|
8 | + * @var int |
|
9 | + */ |
|
10 | + private $iLineNo; |
|
11 | 11 | |
12 | - /** |
|
13 | - * @param string $sMessage |
|
14 | - * @param int $iLineNo |
|
15 | - */ |
|
16 | - public function __construct($sMessage, $iLineNo = 0) |
|
17 | - { |
|
18 | - $this->iLineNo = $iLineNo; |
|
19 | - if (!empty($iLineNo)) { |
|
20 | - $sMessage .= " [line no: $iLineNo]"; |
|
21 | - } |
|
22 | - parent::__construct($sMessage); |
|
23 | - } |
|
12 | + /** |
|
13 | + * @param string $sMessage |
|
14 | + * @param int $iLineNo |
|
15 | + */ |
|
16 | + public function __construct($sMessage, $iLineNo = 0) |
|
17 | + { |
|
18 | + $this->iLineNo = $iLineNo; |
|
19 | + if (!empty($iLineNo)) { |
|
20 | + $sMessage .= " [line no: $iLineNo]"; |
|
21 | + } |
|
22 | + parent::__construct($sMessage); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return int |
|
27 | - */ |
|
28 | - public function getLineNo() |
|
29 | - { |
|
30 | - return $this->iLineNo; |
|
31 | - } |
|
25 | + /** |
|
26 | + * @return int |
|
27 | + */ |
|
28 | + public function getLineNo() |
|
29 | + { |
|
30 | + return $this->iLineNo; |
|
31 | + } |
|
32 | 32 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | public function __construct($sMessage, $iLineNo = 0) |
17 | 17 | { |
18 | 18 | $this->iLineNo = $iLineNo; |
19 | - if (!empty($iLineNo)) { |
|
19 | + if ( ! empty($iLineNo)) { |
|
20 | 20 | $sMessage .= " [line no: $iLineNo]"; |
21 | 21 | } |
22 | 22 | parent::__construct($sMessage); |
@@ -7,12 +7,12 @@ |
||
7 | 7 | */ |
8 | 8 | class OutputException extends SourceException |
9 | 9 | { |
10 | - /** |
|
11 | - * @param string $sMessage |
|
12 | - * @param int $iLineNo |
|
13 | - */ |
|
14 | - public function __construct($sMessage, $iLineNo = 0) |
|
15 | - { |
|
16 | - parent::__construct($sMessage, $iLineNo); |
|
17 | - } |
|
10 | + /** |
|
11 | + * @param string $sMessage |
|
12 | + * @param int $iLineNo |
|
13 | + */ |
|
14 | + public function __construct($sMessage, $iLineNo = 0) |
|
15 | + { |
|
16 | + parent::__construct($sMessage, $iLineNo); |
|
17 | + } |
|
18 | 18 | } |
@@ -4,18 +4,18 @@ |
||
4 | 4 | |
5 | 5 | interface Renderable |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function __toString(); |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function __toString(); |
|
11 | 11 | |
12 | - /** |
|
13 | - * @return string |
|
14 | - */ |
|
15 | - public function render(OutputFormat $oOutputFormat); |
|
12 | + /** |
|
13 | + * @return string |
|
14 | + */ |
|
15 | + public function render(OutputFormat $oOutputFormat); |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return int |
|
19 | - */ |
|
20 | - public function getLineNo(); |
|
17 | + /** |
|
18 | + * @return int |
|
19 | + */ |
|
20 | + public function getLineNo(); |
|
21 | 21 | } |
@@ -18,126 +18,126 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class CSSBlockList extends CSSList |
20 | 20 | { |
21 | - /** |
|
22 | - * @param int $iLineNo |
|
23 | - */ |
|
24 | - public function __construct($iLineNo = 0) |
|
25 | - { |
|
26 | - parent::__construct($iLineNo); |
|
27 | - } |
|
21 | + /** |
|
22 | + * @param int $iLineNo |
|
23 | + */ |
|
24 | + public function __construct($iLineNo = 0) |
|
25 | + { |
|
26 | + parent::__construct($iLineNo); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param array<int, DeclarationBlock> $aResult |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - protected function allDeclarationBlocks(array &$aResult) |
|
35 | - { |
|
36 | - foreach ($this->aContents as $mContent) { |
|
37 | - if ($mContent instanceof DeclarationBlock) { |
|
38 | - $aResult[] = $mContent; |
|
39 | - } elseif ($mContent instanceof CSSBlockList) { |
|
40 | - $mContent->allDeclarationBlocks($aResult); |
|
41 | - } |
|
42 | - } |
|
43 | - } |
|
29 | + /** |
|
30 | + * @param array<int, DeclarationBlock> $aResult |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + protected function allDeclarationBlocks(array &$aResult) |
|
35 | + { |
|
36 | + foreach ($this->aContents as $mContent) { |
|
37 | + if ($mContent instanceof DeclarationBlock) { |
|
38 | + $aResult[] = $mContent; |
|
39 | + } elseif ($mContent instanceof CSSBlockList) { |
|
40 | + $mContent->allDeclarationBlocks($aResult); |
|
41 | + } |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param array<int, RuleSet> $aResult |
|
47 | - * |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - protected function allRuleSets(array &$aResult) |
|
51 | - { |
|
52 | - foreach ($this->aContents as $mContent) { |
|
53 | - if ($mContent instanceof RuleSet) { |
|
54 | - $aResult[] = $mContent; |
|
55 | - } elseif ($mContent instanceof CSSBlockList) { |
|
56 | - $mContent->allRuleSets($aResult); |
|
57 | - } |
|
58 | - } |
|
59 | - } |
|
45 | + /** |
|
46 | + * @param array<int, RuleSet> $aResult |
|
47 | + * |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + protected function allRuleSets(array &$aResult) |
|
51 | + { |
|
52 | + foreach ($this->aContents as $mContent) { |
|
53 | + if ($mContent instanceof RuleSet) { |
|
54 | + $aResult[] = $mContent; |
|
55 | + } elseif ($mContent instanceof CSSBlockList) { |
|
56 | + $mContent->allRuleSets($aResult); |
|
57 | + } |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param CSSList|Rule|RuleSet|Value $oElement |
|
63 | - * @param array<int, Value> $aResult |
|
64 | - * @param string|null $sSearchString |
|
65 | - * @param bool $bSearchInFunctionArguments |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function allValues($oElement, array &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false) |
|
70 | - { |
|
71 | - if ($oElement instanceof CSSBlockList) { |
|
72 | - foreach ($oElement->getContents() as $oContent) { |
|
73 | - $this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
|
74 | - } |
|
75 | - } elseif ($oElement instanceof RuleSet) { |
|
76 | - foreach ($oElement->getRules($sSearchString) as $oRule) { |
|
77 | - $this->allValues($oRule, $aResult, $sSearchString, $bSearchInFunctionArguments); |
|
78 | - } |
|
79 | - } elseif ($oElement instanceof Rule) { |
|
80 | - $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments); |
|
81 | - } elseif ($oElement instanceof ValueList) { |
|
82 | - if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) { |
|
83 | - foreach ($oElement->getListComponents() as $mComponent) { |
|
84 | - $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
|
85 | - } |
|
86 | - } |
|
87 | - } else { |
|
88 | - // Non-List `Value` or `CSSString` (CSS identifier) |
|
89 | - $aResult[] = $oElement; |
|
90 | - } |
|
91 | - } |
|
61 | + /** |
|
62 | + * @param CSSList|Rule|RuleSet|Value $oElement |
|
63 | + * @param array<int, Value> $aResult |
|
64 | + * @param string|null $sSearchString |
|
65 | + * @param bool $bSearchInFunctionArguments |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function allValues($oElement, array &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false) |
|
70 | + { |
|
71 | + if ($oElement instanceof CSSBlockList) { |
|
72 | + foreach ($oElement->getContents() as $oContent) { |
|
73 | + $this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
|
74 | + } |
|
75 | + } elseif ($oElement instanceof RuleSet) { |
|
76 | + foreach ($oElement->getRules($sSearchString) as $oRule) { |
|
77 | + $this->allValues($oRule, $aResult, $sSearchString, $bSearchInFunctionArguments); |
|
78 | + } |
|
79 | + } elseif ($oElement instanceof Rule) { |
|
80 | + $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments); |
|
81 | + } elseif ($oElement instanceof ValueList) { |
|
82 | + if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) { |
|
83 | + foreach ($oElement->getListComponents() as $mComponent) { |
|
84 | + $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
|
85 | + } |
|
86 | + } |
|
87 | + } else { |
|
88 | + // Non-List `Value` or `CSSString` (CSS identifier) |
|
89 | + $aResult[] = $oElement; |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @param array<int, Selector> $aResult |
|
95 | - * @param string|null $sSpecificitySearch |
|
96 | - * |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - protected function allSelectors(array &$aResult, $sSpecificitySearch = null) |
|
100 | - { |
|
101 | - /** @var array<int, DeclarationBlock> $aDeclarationBlocks */ |
|
102 | - $aDeclarationBlocks = []; |
|
103 | - $this->allDeclarationBlocks($aDeclarationBlocks); |
|
104 | - foreach ($aDeclarationBlocks as $oBlock) { |
|
105 | - foreach ($oBlock->getSelectors() as $oSelector) { |
|
106 | - if ($sSpecificitySearch === null) { |
|
107 | - $aResult[] = $oSelector; |
|
108 | - } else { |
|
109 | - $sComparator = '==='; |
|
110 | - $aSpecificitySearch = explode(' ', $sSpecificitySearch); |
|
111 | - $iTargetSpecificity = $aSpecificitySearch[0]; |
|
112 | - if (count($aSpecificitySearch) > 1) { |
|
113 | - $sComparator = $aSpecificitySearch[0]; |
|
114 | - $iTargetSpecificity = $aSpecificitySearch[1]; |
|
115 | - } |
|
116 | - $iTargetSpecificity = (int)$iTargetSpecificity; |
|
117 | - $iSelectorSpecificity = $oSelector->getSpecificity(); |
|
118 | - $bMatches = false; |
|
119 | - switch ($sComparator) { |
|
120 | - case '<=': |
|
121 | - $bMatches = $iSelectorSpecificity <= $iTargetSpecificity; |
|
122 | - break; |
|
123 | - case '<': |
|
124 | - $bMatches = $iSelectorSpecificity < $iTargetSpecificity; |
|
125 | - break; |
|
126 | - case '>=': |
|
127 | - $bMatches = $iSelectorSpecificity >= $iTargetSpecificity; |
|
128 | - break; |
|
129 | - case '>': |
|
130 | - $bMatches = $iSelectorSpecificity > $iTargetSpecificity; |
|
131 | - break; |
|
132 | - default: |
|
133 | - $bMatches = $iSelectorSpecificity === $iTargetSpecificity; |
|
134 | - break; |
|
135 | - } |
|
136 | - if ($bMatches) { |
|
137 | - $aResult[] = $oSelector; |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
93 | + /** |
|
94 | + * @param array<int, Selector> $aResult |
|
95 | + * @param string|null $sSpecificitySearch |
|
96 | + * |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + protected function allSelectors(array &$aResult, $sSpecificitySearch = null) |
|
100 | + { |
|
101 | + /** @var array<int, DeclarationBlock> $aDeclarationBlocks */ |
|
102 | + $aDeclarationBlocks = []; |
|
103 | + $this->allDeclarationBlocks($aDeclarationBlocks); |
|
104 | + foreach ($aDeclarationBlocks as $oBlock) { |
|
105 | + foreach ($oBlock->getSelectors() as $oSelector) { |
|
106 | + if ($sSpecificitySearch === null) { |
|
107 | + $aResult[] = $oSelector; |
|
108 | + } else { |
|
109 | + $sComparator = '==='; |
|
110 | + $aSpecificitySearch = explode(' ', $sSpecificitySearch); |
|
111 | + $iTargetSpecificity = $aSpecificitySearch[0]; |
|
112 | + if (count($aSpecificitySearch) > 1) { |
|
113 | + $sComparator = $aSpecificitySearch[0]; |
|
114 | + $iTargetSpecificity = $aSpecificitySearch[1]; |
|
115 | + } |
|
116 | + $iTargetSpecificity = (int)$iTargetSpecificity; |
|
117 | + $iSelectorSpecificity = $oSelector->getSpecificity(); |
|
118 | + $bMatches = false; |
|
119 | + switch ($sComparator) { |
|
120 | + case '<=': |
|
121 | + $bMatches = $iSelectorSpecificity <= $iTargetSpecificity; |
|
122 | + break; |
|
123 | + case '<': |
|
124 | + $bMatches = $iSelectorSpecificity < $iTargetSpecificity; |
|
125 | + break; |
|
126 | + case '>=': |
|
127 | + $bMatches = $iSelectorSpecificity >= $iTargetSpecificity; |
|
128 | + break; |
|
129 | + case '>': |
|
130 | + $bMatches = $iSelectorSpecificity > $iTargetSpecificity; |
|
131 | + break; |
|
132 | + default: |
|
133 | + $bMatches = $iSelectorSpecificity === $iTargetSpecificity; |
|
134 | + break; |
|
135 | + } |
|
136 | + if ($bMatches) { |
|
137 | + $aResult[] = $oSelector; |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | 143 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | } elseif ($oElement instanceof Rule) { |
80 | 80 | $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments); |
81 | 81 | } elseif ($oElement instanceof ValueList) { |
82 | - if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) { |
|
82 | + if ($bSearchInFunctionArguments || ! ($oElement instanceof CSSFunction)) { |
|
83 | 83 | foreach ($oElement->getListComponents() as $mComponent) { |
84 | 84 | $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
85 | 85 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $sComparator = $aSpecificitySearch[0]; |
114 | 114 | $iTargetSpecificity = $aSpecificitySearch[1]; |
115 | 115 | } |
116 | - $iTargetSpecificity = (int)$iTargetSpecificity; |
|
116 | + $iTargetSpecificity = (int) $iTargetSpecificity; |
|
117 | 117 | $iSelectorSpecificity = $oSelector->getSpecificity(); |
118 | 118 | $bMatches = false; |
119 | 119 | switch ($sComparator) { |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | { |
80 | 80 | $aComments = $oParserState->consumeWhiteSpace(); |
81 | 81 | $oRule = new Rule( |
82 | - $oParserState->parseIdentifier(!$oParserState->comes("--")), |
|
82 | + $oParserState->parseIdentifier( ! $oParserState->comes("--")), |
|
83 | 83 | $oParserState->currentLine(), |
84 | 84 | $oParserState->currentColumn() |
85 | 85 | ); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $oCommaSeparatedList = new RuleValueList(',', $this->iLineNo); |
210 | 210 | } |
211 | 211 | foreach ($aCommaSeparatedValues as $mValue) { |
212 | - if (!$oSpaceSeparatedList && !$oCommaSeparatedList) { |
|
212 | + if ( ! $oSpaceSeparatedList && ! $oCommaSeparatedList) { |
|
213 | 213 | $this->mValue = $mValue; |
214 | 214 | return $mValue; |
215 | 215 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $oSpaceSeparatedList->addListComponent($mValue); |
220 | 220 | } |
221 | 221 | } |
222 | - if (!$oSpaceSeparatedList) { |
|
222 | + if ( ! $oSpaceSeparatedList) { |
|
223 | 223 | $this->mValue = $oCommaSeparatedList; |
224 | 224 | return $oCommaSeparatedList; |
225 | 225 | } else { |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function getValues() |
241 | 241 | { |
242 | - if (!$this->mValue instanceof RuleValueList) { |
|
242 | + if ( ! $this->mValue instanceof RuleValueList) { |
|
243 | 243 | return [[$this->mValue]]; |
244 | 244 | } |
245 | 245 | if ($this->mValue->getListSeparator() === ',') { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | } |
248 | 248 | $aResult = []; |
249 | 249 | foreach ($this->mValue->getListComponents() as $mValue) { |
250 | - if (!$mValue instanceof RuleValueList || $mValue->getListSeparator() !== ',') { |
|
250 | + if ( ! $mValue instanceof RuleValueList || $mValue->getListSeparator() !== ',') { |
|
251 | 251 | $aResult[] = [$mValue]; |
252 | 252 | continue; |
253 | 253 | } |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public function addValue($mValue, $sType = ' ') |
274 | 274 | { |
275 | - if (!is_array($mValue)) { |
|
275 | + if ( ! is_array($mValue)) { |
|
276 | 276 | $mValue = [$mValue]; |
277 | 277 | } |
278 | - if (!$this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) { |
|
278 | + if ( ! $this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) { |
|
279 | 279 | $mCurrentValue = $this->mValue; |
280 | 280 | $this->mValue = new RuleValueList($sType, $this->iLineNo); |
281 | 281 | if ($mCurrentValue) { |
@@ -352,8 +352,8 @@ discard block |
||
352 | 352 | } else { |
353 | 353 | $sResult .= $this->mValue; |
354 | 354 | } |
355 | - if (!empty($this->aIeHack)) { |
|
356 | - $sResult .= ' \\' . implode('\\', $this->aIeHack); |
|
355 | + if ( ! empty($this->aIeHack)) { |
|
356 | + $sResult .= ' \\'.implode('\\', $this->aIeHack); |
|
357 | 357 | } |
358 | 358 | if ($this->bIsImportant) { |
359 | 359 | $sResult .= ' !important'; |
@@ -19,375 +19,375 @@ |
||
19 | 19 | */ |
20 | 20 | class Rule implements Renderable, Commentable |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - private $sRule; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var RuleValueList|string|null |
|
29 | - */ |
|
30 | - private $mValue; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var bool |
|
34 | - */ |
|
35 | - private $bIsImportant; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var array<int, int> |
|
39 | - */ |
|
40 | - private $aIeHack; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $iLineNo; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int |
|
49 | - */ |
|
50 | - protected $iColNo; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array<array-key, Comment> |
|
54 | - */ |
|
55 | - protected $aComments; |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $sRule |
|
59 | - * @param int $iLineNo |
|
60 | - * @param int $iColNo |
|
61 | - */ |
|
62 | - public function __construct($sRule, $iLineNo = 0, $iColNo = 0) |
|
63 | - { |
|
64 | - $this->sRule = $sRule; |
|
65 | - $this->mValue = null; |
|
66 | - $this->bIsImportant = false; |
|
67 | - $this->aIeHack = []; |
|
68 | - $this->iLineNo = $iLineNo; |
|
69 | - $this->iColNo = $iColNo; |
|
70 | - $this->aComments = []; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @return Rule |
|
75 | - * |
|
76 | - * @throws UnexpectedEOFException |
|
77 | - * @throws UnexpectedTokenException |
|
78 | - */ |
|
79 | - public static function parse(ParserState $oParserState) |
|
80 | - { |
|
81 | - $aComments = $oParserState->consumeWhiteSpace(); |
|
82 | - $oRule = new Rule( |
|
83 | - $oParserState->parseIdentifier(!$oParserState->comes("--")), |
|
84 | - $oParserState->currentLine(), |
|
85 | - $oParserState->currentColumn() |
|
86 | - ); |
|
87 | - $oRule->setComments($aComments); |
|
88 | - $oRule->addComments($oParserState->consumeWhiteSpace()); |
|
89 | - $oParserState->consume(':'); |
|
90 | - $oValue = Value::parseValue($oParserState, self::listDelimiterForRule($oRule->getRule())); |
|
91 | - $oRule->setValue($oValue); |
|
92 | - if ($oParserState->getSettings()->bLenientParsing) { |
|
93 | - while ($oParserState->comes('\\')) { |
|
94 | - $oParserState->consume('\\'); |
|
95 | - $oRule->addIeHack($oParserState->consume()); |
|
96 | - $oParserState->consumeWhiteSpace(); |
|
97 | - } |
|
98 | - } |
|
99 | - $oParserState->consumeWhiteSpace(); |
|
100 | - if ($oParserState->comes('!')) { |
|
101 | - $oParserState->consume('!'); |
|
102 | - $oParserState->consumeWhiteSpace(); |
|
103 | - $oParserState->consume('important'); |
|
104 | - $oRule->setIsImportant(true); |
|
105 | - } |
|
106 | - $oParserState->consumeWhiteSpace(); |
|
107 | - while ($oParserState->comes(';')) { |
|
108 | - $oParserState->consume(';'); |
|
109 | - } |
|
110 | - $oParserState->consumeWhiteSpace(); |
|
111 | - |
|
112 | - return $oRule; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $sRule |
|
117 | - * |
|
118 | - * @return array<int, string> |
|
119 | - */ |
|
120 | - private static function listDelimiterForRule($sRule) |
|
121 | - { |
|
122 | - if (preg_match('/^font($|-)/', $sRule)) { |
|
123 | - return [',', '/', ' ']; |
|
124 | - } |
|
125 | - return [',', ' ', '/']; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function getLineNo() |
|
132 | - { |
|
133 | - return $this->iLineNo; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return int |
|
138 | - */ |
|
139 | - public function getColNo() |
|
140 | - { |
|
141 | - return $this->iColNo; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @param int $iLine |
|
146 | - * @param int $iColumn |
|
147 | - * |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - public function setPosition($iLine, $iColumn) |
|
151 | - { |
|
152 | - $this->iColNo = $iColumn; |
|
153 | - $this->iLineNo = $iLine; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $sRule |
|
158 | - * |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - public function setRule($sRule) |
|
162 | - { |
|
163 | - $this->sRule = $sRule; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function getRule() |
|
170 | - { |
|
171 | - return $this->sRule; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @return RuleValueList|string|null |
|
176 | - */ |
|
177 | - public function getValue() |
|
178 | - { |
|
179 | - return $this->mValue; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * @param RuleValueList|string|null $mValue |
|
184 | - * |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - public function setValue($mValue) |
|
188 | - { |
|
189 | - $this->mValue = $mValue; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @param array<array-key, array<array-key, RuleValueList>> $aSpaceSeparatedValues |
|
194 | - * |
|
195 | - * @return RuleValueList |
|
196 | - * |
|
197 | - * @deprecated will be removed in version 9.0 |
|
198 | - * Old-Style 2-dimensional array given. Retained for (some) backwards-compatibility. |
|
199 | - * Use `setValue()` instead and wrap the value inside a RuleValueList if necessary. |
|
200 | - */ |
|
201 | - public function setValues(array $aSpaceSeparatedValues) |
|
202 | - { |
|
203 | - $oSpaceSeparatedList = null; |
|
204 | - if (count($aSpaceSeparatedValues) > 1) { |
|
205 | - $oSpaceSeparatedList = new RuleValueList(' ', $this->iLineNo); |
|
206 | - } |
|
207 | - foreach ($aSpaceSeparatedValues as $aCommaSeparatedValues) { |
|
208 | - $oCommaSeparatedList = null; |
|
209 | - if (count($aCommaSeparatedValues) > 1) { |
|
210 | - $oCommaSeparatedList = new RuleValueList(',', $this->iLineNo); |
|
211 | - } |
|
212 | - foreach ($aCommaSeparatedValues as $mValue) { |
|
213 | - if (!$oSpaceSeparatedList && !$oCommaSeparatedList) { |
|
214 | - $this->mValue = $mValue; |
|
215 | - return $mValue; |
|
216 | - } |
|
217 | - if ($oCommaSeparatedList) { |
|
218 | - $oCommaSeparatedList->addListComponent($mValue); |
|
219 | - } else { |
|
220 | - $oSpaceSeparatedList->addListComponent($mValue); |
|
221 | - } |
|
222 | - } |
|
223 | - if (!$oSpaceSeparatedList) { |
|
224 | - $this->mValue = $oCommaSeparatedList; |
|
225 | - return $oCommaSeparatedList; |
|
226 | - } else { |
|
227 | - $oSpaceSeparatedList->addListComponent($oCommaSeparatedList); |
|
228 | - } |
|
229 | - } |
|
230 | - $this->mValue = $oSpaceSeparatedList; |
|
231 | - return $oSpaceSeparatedList; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @return array<int, array<int, RuleValueList>> |
|
236 | - * |
|
237 | - * @deprecated will be removed in version 9.0 |
|
238 | - * Old-Style 2-dimensional array returned. Retained for (some) backwards-compatibility. |
|
239 | - * Use `getValue()` instead and check for the existence of a (nested set of) ValueList object(s). |
|
240 | - */ |
|
241 | - public function getValues() |
|
242 | - { |
|
243 | - if (!$this->mValue instanceof RuleValueList) { |
|
244 | - return [[$this->mValue]]; |
|
245 | - } |
|
246 | - if ($this->mValue->getListSeparator() === ',') { |
|
247 | - return [$this->mValue->getListComponents()]; |
|
248 | - } |
|
249 | - $aResult = []; |
|
250 | - foreach ($this->mValue->getListComponents() as $mValue) { |
|
251 | - if (!$mValue instanceof RuleValueList || $mValue->getListSeparator() !== ',') { |
|
252 | - $aResult[] = [$mValue]; |
|
253 | - continue; |
|
254 | - } |
|
255 | - if ($this->mValue->getListSeparator() === ' ' || count($aResult) === 0) { |
|
256 | - $aResult[] = []; |
|
257 | - } |
|
258 | - foreach ($mValue->getListComponents() as $mValue) { |
|
259 | - $aResult[count($aResult) - 1][] = $mValue; |
|
260 | - } |
|
261 | - } |
|
262 | - return $aResult; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Adds a value to the existing value. Value will be appended if a `RuleValueList` exists of the given type. |
|
267 | - * Otherwise, the existing value will be wrapped by one. |
|
268 | - * |
|
269 | - * @param RuleValueList|array<int, RuleValueList> $mValue |
|
270 | - * @param string $sType |
|
271 | - * |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - public function addValue($mValue, $sType = ' ') |
|
275 | - { |
|
276 | - if (!is_array($mValue)) { |
|
277 | - $mValue = [$mValue]; |
|
278 | - } |
|
279 | - if (!$this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) { |
|
280 | - $mCurrentValue = $this->mValue; |
|
281 | - $this->mValue = new RuleValueList($sType, $this->iLineNo); |
|
282 | - if ($mCurrentValue) { |
|
283 | - $this->mValue->addListComponent($mCurrentValue); |
|
284 | - } |
|
285 | - } |
|
286 | - foreach ($mValue as $mValueItem) { |
|
287 | - $this->mValue->addListComponent($mValueItem); |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * @param int $iModifier |
|
293 | - * |
|
294 | - * @return void |
|
295 | - */ |
|
296 | - public function addIeHack($iModifier) |
|
297 | - { |
|
298 | - $this->aIeHack[] = $iModifier; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @param array<int, int> $aModifiers |
|
303 | - * |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - public function setIeHack(array $aModifiers) |
|
307 | - { |
|
308 | - $this->aIeHack = $aModifiers; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @return array<int, int> |
|
313 | - */ |
|
314 | - public function getIeHack() |
|
315 | - { |
|
316 | - return $this->aIeHack; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * @param bool $bIsImportant |
|
321 | - * |
|
322 | - * @return void |
|
323 | - */ |
|
324 | - public function setIsImportant($bIsImportant) |
|
325 | - { |
|
326 | - $this->bIsImportant = $bIsImportant; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * @return bool |
|
331 | - */ |
|
332 | - public function getIsImportant() |
|
333 | - { |
|
334 | - return $this->bIsImportant; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - public function __toString() |
|
341 | - { |
|
342 | - return $this->render(new OutputFormat()); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * @return string |
|
347 | - */ |
|
348 | - public function render(OutputFormat $oOutputFormat) |
|
349 | - { |
|
350 | - $sResult = "{$oOutputFormat->comments($this)}{$this->sRule}:{$oOutputFormat->spaceAfterRuleName()}"; |
|
351 | - if ($this->mValue instanceof Value) { // Can also be a ValueList |
|
352 | - $sResult .= $this->mValue->render($oOutputFormat); |
|
353 | - } else { |
|
354 | - $sResult .= $this->mValue; |
|
355 | - } |
|
356 | - if (!empty($this->aIeHack)) { |
|
357 | - $sResult .= ' \\' . implode('\\', $this->aIeHack); |
|
358 | - } |
|
359 | - if ($this->bIsImportant) { |
|
360 | - $sResult .= ' !important'; |
|
361 | - } |
|
362 | - $sResult .= ';'; |
|
363 | - return $sResult; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * @param array<array-key, Comment> $aComments |
|
368 | - * |
|
369 | - * @return void |
|
370 | - */ |
|
371 | - public function addComments(array $aComments) |
|
372 | - { |
|
373 | - $this->aComments = array_merge($this->aComments, $aComments); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * @return array<array-key, Comment> |
|
378 | - */ |
|
379 | - public function getComments() |
|
380 | - { |
|
381 | - return $this->aComments; |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * @param array<array-key, Comment> $aComments |
|
386 | - * |
|
387 | - * @return void |
|
388 | - */ |
|
389 | - public function setComments(array $aComments) |
|
390 | - { |
|
391 | - $this->aComments = $aComments; |
|
392 | - } |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + private $sRule; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var RuleValueList|string|null |
|
29 | + */ |
|
30 | + private $mValue; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var bool |
|
34 | + */ |
|
35 | + private $bIsImportant; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var array<int, int> |
|
39 | + */ |
|
40 | + private $aIeHack; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $iLineNo; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int |
|
49 | + */ |
|
50 | + protected $iColNo; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array<array-key, Comment> |
|
54 | + */ |
|
55 | + protected $aComments; |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $sRule |
|
59 | + * @param int $iLineNo |
|
60 | + * @param int $iColNo |
|
61 | + */ |
|
62 | + public function __construct($sRule, $iLineNo = 0, $iColNo = 0) |
|
63 | + { |
|
64 | + $this->sRule = $sRule; |
|
65 | + $this->mValue = null; |
|
66 | + $this->bIsImportant = false; |
|
67 | + $this->aIeHack = []; |
|
68 | + $this->iLineNo = $iLineNo; |
|
69 | + $this->iColNo = $iColNo; |
|
70 | + $this->aComments = []; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @return Rule |
|
75 | + * |
|
76 | + * @throws UnexpectedEOFException |
|
77 | + * @throws UnexpectedTokenException |
|
78 | + */ |
|
79 | + public static function parse(ParserState $oParserState) |
|
80 | + { |
|
81 | + $aComments = $oParserState->consumeWhiteSpace(); |
|
82 | + $oRule = new Rule( |
|
83 | + $oParserState->parseIdentifier(!$oParserState->comes("--")), |
|
84 | + $oParserState->currentLine(), |
|
85 | + $oParserState->currentColumn() |
|
86 | + ); |
|
87 | + $oRule->setComments($aComments); |
|
88 | + $oRule->addComments($oParserState->consumeWhiteSpace()); |
|
89 | + $oParserState->consume(':'); |
|
90 | + $oValue = Value::parseValue($oParserState, self::listDelimiterForRule($oRule->getRule())); |
|
91 | + $oRule->setValue($oValue); |
|
92 | + if ($oParserState->getSettings()->bLenientParsing) { |
|
93 | + while ($oParserState->comes('\\')) { |
|
94 | + $oParserState->consume('\\'); |
|
95 | + $oRule->addIeHack($oParserState->consume()); |
|
96 | + $oParserState->consumeWhiteSpace(); |
|
97 | + } |
|
98 | + } |
|
99 | + $oParserState->consumeWhiteSpace(); |
|
100 | + if ($oParserState->comes('!')) { |
|
101 | + $oParserState->consume('!'); |
|
102 | + $oParserState->consumeWhiteSpace(); |
|
103 | + $oParserState->consume('important'); |
|
104 | + $oRule->setIsImportant(true); |
|
105 | + } |
|
106 | + $oParserState->consumeWhiteSpace(); |
|
107 | + while ($oParserState->comes(';')) { |
|
108 | + $oParserState->consume(';'); |
|
109 | + } |
|
110 | + $oParserState->consumeWhiteSpace(); |
|
111 | + |
|
112 | + return $oRule; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $sRule |
|
117 | + * |
|
118 | + * @return array<int, string> |
|
119 | + */ |
|
120 | + private static function listDelimiterForRule($sRule) |
|
121 | + { |
|
122 | + if (preg_match('/^font($|-)/', $sRule)) { |
|
123 | + return [',', '/', ' ']; |
|
124 | + } |
|
125 | + return [',', ' ', '/']; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function getLineNo() |
|
132 | + { |
|
133 | + return $this->iLineNo; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return int |
|
138 | + */ |
|
139 | + public function getColNo() |
|
140 | + { |
|
141 | + return $this->iColNo; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @param int $iLine |
|
146 | + * @param int $iColumn |
|
147 | + * |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + public function setPosition($iLine, $iColumn) |
|
151 | + { |
|
152 | + $this->iColNo = $iColumn; |
|
153 | + $this->iLineNo = $iLine; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $sRule |
|
158 | + * |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + public function setRule($sRule) |
|
162 | + { |
|
163 | + $this->sRule = $sRule; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function getRule() |
|
170 | + { |
|
171 | + return $this->sRule; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @return RuleValueList|string|null |
|
176 | + */ |
|
177 | + public function getValue() |
|
178 | + { |
|
179 | + return $this->mValue; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * @param RuleValueList|string|null $mValue |
|
184 | + * |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + public function setValue($mValue) |
|
188 | + { |
|
189 | + $this->mValue = $mValue; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @param array<array-key, array<array-key, RuleValueList>> $aSpaceSeparatedValues |
|
194 | + * |
|
195 | + * @return RuleValueList |
|
196 | + * |
|
197 | + * @deprecated will be removed in version 9.0 |
|
198 | + * Old-Style 2-dimensional array given. Retained for (some) backwards-compatibility. |
|
199 | + * Use `setValue()` instead and wrap the value inside a RuleValueList if necessary. |
|
200 | + */ |
|
201 | + public function setValues(array $aSpaceSeparatedValues) |
|
202 | + { |
|
203 | + $oSpaceSeparatedList = null; |
|
204 | + if (count($aSpaceSeparatedValues) > 1) { |
|
205 | + $oSpaceSeparatedList = new RuleValueList(' ', $this->iLineNo); |
|
206 | + } |
|
207 | + foreach ($aSpaceSeparatedValues as $aCommaSeparatedValues) { |
|
208 | + $oCommaSeparatedList = null; |
|
209 | + if (count($aCommaSeparatedValues) > 1) { |
|
210 | + $oCommaSeparatedList = new RuleValueList(',', $this->iLineNo); |
|
211 | + } |
|
212 | + foreach ($aCommaSeparatedValues as $mValue) { |
|
213 | + if (!$oSpaceSeparatedList && !$oCommaSeparatedList) { |
|
214 | + $this->mValue = $mValue; |
|
215 | + return $mValue; |
|
216 | + } |
|
217 | + if ($oCommaSeparatedList) { |
|
218 | + $oCommaSeparatedList->addListComponent($mValue); |
|
219 | + } else { |
|
220 | + $oSpaceSeparatedList->addListComponent($mValue); |
|
221 | + } |
|
222 | + } |
|
223 | + if (!$oSpaceSeparatedList) { |
|
224 | + $this->mValue = $oCommaSeparatedList; |
|
225 | + return $oCommaSeparatedList; |
|
226 | + } else { |
|
227 | + $oSpaceSeparatedList->addListComponent($oCommaSeparatedList); |
|
228 | + } |
|
229 | + } |
|
230 | + $this->mValue = $oSpaceSeparatedList; |
|
231 | + return $oSpaceSeparatedList; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @return array<int, array<int, RuleValueList>> |
|
236 | + * |
|
237 | + * @deprecated will be removed in version 9.0 |
|
238 | + * Old-Style 2-dimensional array returned. Retained for (some) backwards-compatibility. |
|
239 | + * Use `getValue()` instead and check for the existence of a (nested set of) ValueList object(s). |
|
240 | + */ |
|
241 | + public function getValues() |
|
242 | + { |
|
243 | + if (!$this->mValue instanceof RuleValueList) { |
|
244 | + return [[$this->mValue]]; |
|
245 | + } |
|
246 | + if ($this->mValue->getListSeparator() === ',') { |
|
247 | + return [$this->mValue->getListComponents()]; |
|
248 | + } |
|
249 | + $aResult = []; |
|
250 | + foreach ($this->mValue->getListComponents() as $mValue) { |
|
251 | + if (!$mValue instanceof RuleValueList || $mValue->getListSeparator() !== ',') { |
|
252 | + $aResult[] = [$mValue]; |
|
253 | + continue; |
|
254 | + } |
|
255 | + if ($this->mValue->getListSeparator() === ' ' || count($aResult) === 0) { |
|
256 | + $aResult[] = []; |
|
257 | + } |
|
258 | + foreach ($mValue->getListComponents() as $mValue) { |
|
259 | + $aResult[count($aResult) - 1][] = $mValue; |
|
260 | + } |
|
261 | + } |
|
262 | + return $aResult; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Adds a value to the existing value. Value will be appended if a `RuleValueList` exists of the given type. |
|
267 | + * Otherwise, the existing value will be wrapped by one. |
|
268 | + * |
|
269 | + * @param RuleValueList|array<int, RuleValueList> $mValue |
|
270 | + * @param string $sType |
|
271 | + * |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + public function addValue($mValue, $sType = ' ') |
|
275 | + { |
|
276 | + if (!is_array($mValue)) { |
|
277 | + $mValue = [$mValue]; |
|
278 | + } |
|
279 | + if (!$this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) { |
|
280 | + $mCurrentValue = $this->mValue; |
|
281 | + $this->mValue = new RuleValueList($sType, $this->iLineNo); |
|
282 | + if ($mCurrentValue) { |
|
283 | + $this->mValue->addListComponent($mCurrentValue); |
|
284 | + } |
|
285 | + } |
|
286 | + foreach ($mValue as $mValueItem) { |
|
287 | + $this->mValue->addListComponent($mValueItem); |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * @param int $iModifier |
|
293 | + * |
|
294 | + * @return void |
|
295 | + */ |
|
296 | + public function addIeHack($iModifier) |
|
297 | + { |
|
298 | + $this->aIeHack[] = $iModifier; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @param array<int, int> $aModifiers |
|
303 | + * |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + public function setIeHack(array $aModifiers) |
|
307 | + { |
|
308 | + $this->aIeHack = $aModifiers; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @return array<int, int> |
|
313 | + */ |
|
314 | + public function getIeHack() |
|
315 | + { |
|
316 | + return $this->aIeHack; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * @param bool $bIsImportant |
|
321 | + * |
|
322 | + * @return void |
|
323 | + */ |
|
324 | + public function setIsImportant($bIsImportant) |
|
325 | + { |
|
326 | + $this->bIsImportant = $bIsImportant; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * @return bool |
|
331 | + */ |
|
332 | + public function getIsImportant() |
|
333 | + { |
|
334 | + return $this->bIsImportant; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + public function __toString() |
|
341 | + { |
|
342 | + return $this->render(new OutputFormat()); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * @return string |
|
347 | + */ |
|
348 | + public function render(OutputFormat $oOutputFormat) |
|
349 | + { |
|
350 | + $sResult = "{$oOutputFormat->comments($this)}{$this->sRule}:{$oOutputFormat->spaceAfterRuleName()}"; |
|
351 | + if ($this->mValue instanceof Value) { // Can also be a ValueList |
|
352 | + $sResult .= $this->mValue->render($oOutputFormat); |
|
353 | + } else { |
|
354 | + $sResult .= $this->mValue; |
|
355 | + } |
|
356 | + if (!empty($this->aIeHack)) { |
|
357 | + $sResult .= ' \\' . implode('\\', $this->aIeHack); |
|
358 | + } |
|
359 | + if ($this->bIsImportant) { |
|
360 | + $sResult .= ' !important'; |
|
361 | + } |
|
362 | + $sResult .= ';'; |
|
363 | + return $sResult; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * @param array<array-key, Comment> $aComments |
|
368 | + * |
|
369 | + * @return void |
|
370 | + */ |
|
371 | + public function addComments(array $aComments) |
|
372 | + { |
|
373 | + $this->aComments = array_merge($this->aComments, $aComments); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * @return array<array-key, Comment> |
|
378 | + */ |
|
379 | + public function getComments() |
|
380 | + { |
|
381 | + return $this->aComments; |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * @param array<array-key, Comment> $aComments |
|
386 | + * |
|
387 | + * @return void |
|
388 | + */ |
|
389 | + public function setComments(array $aComments) |
|
390 | + { |
|
391 | + $this->aComments = $aComments; |
|
392 | + } |
|
393 | 393 | } |