PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / vendor / sabberworm / php-css-parser / src / OutputFormat.php

OutputFormat.php in Yatra – Travel Booking & Tour Operator Software trunk, at vendor/sabberworm/php-css-parser/src/OutputFormat.php

438 lines 11.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sabberworm\CSS;
4
5 /**
6 * Extending this class is deprecated in version 8.8.0; it will be made `final` in version 9.0.0.
7 *
8 * @method OutputFormat setSemicolonAfterLastRule(bool $bSemicolonAfterLastRule) Set whether semicolons are added after
9 * last rule.
10 */
11 class OutputFormat
12 {
13 /**
14 * Value format: `"` means double-quote, `'` means single-quote
15 *
16 * @var string
17 *
18 * @internal since 8.8.0, will be made private in 9.0.0
19 */
20 public $sStringQuotingType = '"';
21
22 /**
23 * Output RGB colors in hash notation if possible
24 *
25 * @var bool
26 *
27 * @internal since 8.8.0, will be made private in 9.0.0
28 */
29 public $bRGBHashNotation = true;
30
31 /**
32 * Declaration format
33 *
34 * Semicolon after the last rule of a declaration block can be omitted. To do that, set this false.
35 *
36 * @var bool
37 *
38 * @internal since 8.8.0, will be made private in 9.0.0
39 */
40 public $bSemicolonAfterLastRule = true;
41
42 /**
43 * Spacing
44 * Note that these strings are not sanity-checked: the value should only consist of whitespace
45 * Any newline character will be indented according to the current level.
46 * The triples (After, Before, Between) can be set using a wildcard (e.g. `$oFormat->set('Space*Rules', "\n");`)
47 *
48 * @var string
49 *
50 * @internal since 8.8.0, will be made private in 9.0.0
51 */
52 public $sSpaceAfterRuleName = ' ';
53
54 /**
55 * @var string
56 *
57 * @internal since 8.8.0, will be made private in 9.0.0
58 */
59 public $sSpaceBeforeRules = '';
60
61 /**
62 * @var string
63 *
64 * @internal since 8.8.0, will be made private in 9.0.0
65 */
66 public $sSpaceAfterRules = '';
67
68 /**
69 * @var string
70 *
71 * @internal since 8.8.0, will be made private in 9.0.0
72 */
73 public $sSpaceBetweenRules = '';
74
75 /**
76 * @var string
77 *
78 * @internal since 8.8.0, will be made private in 9.0.0
79 */
80 public $sSpaceBeforeBlocks = '';
81
82 /**
83 * @var string
84 *
85 * @internal since 8.8.0, will be made private in 9.0.0
86 */
87 public $sSpaceAfterBlocks = '';
88
89 /**
90 * @var string
91 *
92 * @internal since 8.8.0, will be made private in 9.0.0
93 */
94 public $sSpaceBetweenBlocks = "\n";
95
96 /**
97 * Content injected in and around at-rule blocks.
98 *
99 * @var string
100 *
101 * @internal since 8.8.0, will be made private in 9.0.0
102 */
103 public $sBeforeAtRuleBlock = '';
104
105 /**
106 * @var string
107 *
108 * @internal since 8.8.0, will be made private in 9.0.0
109 */
110 public $sAfterAtRuleBlock = '';
111
112 /**
113 * This is what’s printed before and after the comma if a declaration block contains multiple selectors.
114 *
115 * @var string
116 *
117 * @internal since 8.8.0, will be made private in 9.0.0
118 */
119 public $sSpaceBeforeSelectorSeparator = '';
120
121 /**
122 * @var string
123 *
124 * @internal since 8.8.0, will be made private in 9.0.0
125 */
126 public $sSpaceAfterSelectorSeparator = ' ';
127
128 /**
129 * This is what’s inserted before the separator in value lists, by default.
130 *
131 * `array` is deprecated in version 8.8.0, and will be removed in version 9.0.0.
132 * To set the spacing for specific separators, use {@see $aSpaceBeforeListArgumentSeparators} instead.
133 *
134 * @var string|array<non-empty-string, string>
135 *
136 * @internal since 8.8.0, will be made private in 9.0.0
137 */
138 public $sSpaceBeforeListArgumentSeparator = '';
139
140 /**
141 * Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string.
142 *
143 * @var array<non-empty-string, string>
144 *
145 * @internal since 8.8.0, will be made private in 9.0.0
146 */
147 public $aSpaceBeforeListArgumentSeparators = [];
148
149 /**
150 * This is what’s inserted after the separator in value lists, by default.
151 *
152 * `array` is deprecated in version 8.8.0, and will be removed in version 9.0.0.
153 * To set the spacing for specific separators, use {@see $aSpaceAfterListArgumentSeparators} instead.
154 *
155 * @var string|array<non-empty-string, string>
156 *
157 * @internal since 8.8.0, will be made private in 9.0.0
158 */
159 public $sSpaceAfterListArgumentSeparator = '';
160
161 /**
162 * Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string.
163 *
164 * @var array<non-empty-string, string>
165 *
166 * @internal since 8.8.0, will be made private in 9.0.0
167 */
168 public $aSpaceAfterListArgumentSeparators = [];
169
170 /**
171 * @var string
172 *
173 * @internal since 8.8.0, will be made private in 9.0.0
174 */
175 public $sSpaceBeforeOpeningBrace = ' ';
176
177 /**
178 * Content injected in and around declaration blocks.
179 *
180 * @var string
181 *
182 * @internal since 8.8.0, will be made private in 9.0.0
183 */
184 public $sBeforeDeclarationBlock = '';
185
186 /**
187 * @var string
188 *
189 * @internal since 8.8.0, will be made private in 9.0.0
190 */
191 public $sAfterDeclarationBlockSelectors = '';
192
193 /**
194 * @var string
195 *
196 * @internal since 8.8.0, will be made private in 9.0.0
197 */
198 public $sAfterDeclarationBlock = '';
199
200 /**
201 * Indentation character(s) per level. Only applicable if newlines are used in any of the spacing settings.
202 *
203 * @var string
204 *
205 * @internal since 8.8.0, will be made private in 9.0.0
206 */
207 public $sIndentation = "\t";
208
209 /**
210 * Output exceptions.
211 *
212 * @var bool
213 *
214 * @internal since 8.8.0, will be made private in 9.0.0
215 */
216 public $bIgnoreExceptions = false;
217
218 /**
219 * Render comments for lists and RuleSets
220 *
221 * @var bool
222 *
223 * @internal since 8.8.0, will be made private in 9.0.0
224 */
225 public $bRenderComments = false;
226
227 /**
228 * @var OutputFormatter|null
229 */
230 private $oFormatter = null;
231
232 /**
233 * @var OutputFormat|null
234 */
235 private $oNextLevelFormat = null;
236
237 /**
238 * @var int
239 */
240 private $iIndentationLevel = 0;
241
242 /**
243 * @internal since V8.8.0. Use the factory methods `create()`, `createCompact()`, or `createPretty()` instead.
244 */
245 public function __construct()
246 {
247 }
248
249 /**
250 * @param string $sName
251 *
252 * @return string|null
253 *
254 * @deprecated since 8.8.0, will be removed in 9.0.0. Use specific getters instead.
255 */
256 public function get($sName)
257 {
258 $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i'];
259 foreach ($aVarPrefixes as $sPrefix) {
260 $sFieldName = $sPrefix . ucfirst($sName);
261 if (isset($this->$sFieldName)) {
262 return $this->$sFieldName;
263 }
264 }
265 return null;
266 }
267
268 /**
269 * @param array<array-key, string>|string $aNames
270 * @param mixed $mValue
271 *
272 * @return self|false
273 *
274 * @deprecated since 8.8.0, will be removed in 9.0.0. Use specific setters instead.
275 */
276 public function set($aNames, $mValue)
277 {
278 $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i'];
279 if (is_string($aNames) && strpos($aNames, '*') !== false) {
280 $aNames =
281 [
282 str_replace('*', 'Before', $aNames),
283 str_replace('*', 'Between', $aNames),
284 str_replace('*', 'After', $aNames),
285 ];
286 } elseif (!is_array($aNames)) {
287 $aNames = [$aNames];
288 }
289 foreach ($aVarPrefixes as $sPrefix) {
290 $bDidReplace = false;
291 foreach ($aNames as $sName) {
292 $sFieldName = $sPrefix . ucfirst($sName);
293 if (isset($this->$sFieldName)) {
294 $this->$sFieldName = $mValue;
295 $bDidReplace = true;
296 }
297 }
298 if ($bDidReplace) {
299 return $this;
300 }
301 }
302 // Break the chain so the user knows this option is invalid
303 return false;
304 }
305
306 /**
307 * @param string $sMethodName
308 * @param array<array-key, mixed> $aArguments
309 *
310 * @return mixed
311 *
312 * @throws \Exception
313 */
314 public function __call($sMethodName, array $aArguments)
315 {
316 if (strpos($sMethodName, 'set') === 0) {
317 return $this->set(substr($sMethodName, 3), $aArguments[0]);
318 } elseif (strpos($sMethodName, 'get') === 0) {
319 return $this->get(substr($sMethodName, 3));
320 } elseif (method_exists(OutputFormatter::class, $sMethodName)) {
321 // @deprecated since 8.8.0, will be removed in 9.0.0. Call the method on the formatter directly instead.
322 return call_user_func_array([$this->getFormatter(), $sMethodName], $aArguments);
323 } else {
324 throw new \Exception('Unknown OutputFormat method called: ' . $sMethodName);
325 }
326 }
327
328 /**
329 * @param int $iNumber
330 *
331 * @return self
332 */
333 public function indentWithTabs($iNumber = 1)
334 {
335 return $this->setIndentation(str_repeat("\t", $iNumber));
336 }
337
338 /**
339 * @param int $iNumber
340 *
341 * @return self
342 */
343 public function indentWithSpaces($iNumber = 2)
344 {
345 return $this->setIndentation(str_repeat(" ", $iNumber));
346 }
347
348 /**
349 * @return OutputFormat
350 *
351 * @internal since V8.8.0
352 */
353 public function nextLevel()
354 {
355 if ($this->oNextLevelFormat === null) {
356 $this->oNextLevelFormat = clone $this;
357 $this->oNextLevelFormat->iIndentationLevel++;
358 $this->oNextLevelFormat->oFormatter = null;
359 }
360 return $this->oNextLevelFormat;
361 }
362
363 /**
364 * @return void
365 */
366 public function beLenient()
367 {
368 $this->bIgnoreExceptions = true;
369 }
370
371 /**
372 * @return OutputFormatter
373 *
374 * @internal since 8.8.0
375 */
376 public function getFormatter()
377 {
378 if ($this->oFormatter === null) {
379 $this->oFormatter = new OutputFormatter($this);
380 }
381
382 return $this->oFormatter;
383 }
384
385 /**
386 * @return int
387 *
388 * @deprecated #869 since version V8.8.0, will be removed in V9.0.0. Use `getIndentationLevel()` instead.
389 */
390 public function level()
391 {
392 return $this->iIndentationLevel;
393 }
394
395 /**
396 * Creates an instance of this class without any particular formatting settings.
397 *
398 * @return self
399 */
400 public static function create()
401 {
402 return new OutputFormat();
403 }
404
405 /**
406 * Creates an instance of this class with a preset for compact formatting.
407 *
408 * @return self
409 */
410 public static function createCompact()
411 {
412 $format = self::create();
413 $format->set('Space*Rules', "")
414 ->set('Space*Blocks', "")
415 ->setSpaceAfterRuleName('')
416 ->setSpaceBeforeOpeningBrace('')
417 ->setSpaceAfterSelectorSeparator('')
418 ->setRenderComments(false);
419 return $format;
420 }
421
422 /**
423 * Creates an instance of this class with a preset for pretty formatting.
424 *
425 * @return self
426 */
427 public static function createPretty()
428 {
429 $format = self::create();
430 $format->set('Space*Rules', "\n")
431 ->set('Space*Blocks', "\n")
432 ->setSpaceBetweenBlocks("\n\n")
433 ->set('SpaceAfterListArgumentSeparators', [',' => ' '])
434 ->setRenderComments(true);
435 return $format;
436 }
437 }
438