← All changes
|
back/Libraries/Sabberworm/CSS/src/OutputFormat.php
+753
-0
10.2.0
→
11.1.0
View file →
| @@ -1,0 +1,753 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace AcyMailing\Libraries\Sabberworm\CSS; | |
| 6 | + | |
| 7 | +final class OutputFormat | |
| 8 | +{ | |
| 9 | + /** | |
| 10 | + * Value format: `"` means double-quote, `'` means single-quote | |
| 11 | + * | |
| 12 | + * @var non-empty-string | |
| 13 | + */ | |
| 14 | + private $stringQuotingType = '"'; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Output RGB colors in hash notation if possible | |
| 18 | + * | |
| 19 | + * @var bool | |
| 20 | + */ | |
| 21 | + private $usesRgbHashNotation = true; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Declaration format | |
| 25 | + * | |
| 26 | + * Semicolon after the last rule of a declaration block can be omitted. To do that, set this false. | |
| 27 | + * | |
| 28 | + * @var bool | |
| 29 | + */ | |
| 30 | + private $renderSemicolonAfterLastRule = true; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Spacing | |
| 34 | + * Note that these strings are not sanity-checked: the value should only consist of whitespace | |
| 35 | + * Any newline character will be indented according to the current level. | |
| 36 | + * The triples (After, Before, Between) can be set using a wildcard | |
| 37 | + * (e.g. `$outputFormat->set('Space*Rules', "\n");`) | |
| 38 | + * | |
| 39 | + * @var string | |
| 40 | + */ | |
| 41 | + private $spaceAfterRuleName = ' '; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @var string | |
| 45 | + */ | |
| 46 | + private $spaceBeforeRules = ''; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * @var string | |
| 50 | + */ | |
| 51 | + private $spaceAfterRules = ''; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @var string | |
| 55 | + */ | |
| 56 | + private $spaceBetweenRules = ''; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * @var string | |
| 60 | + */ | |
| 61 | + private $spaceBeforeBlocks = ''; | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * @var string | |
| 65 | + */ | |
| 66 | + private $spaceAfterBlocks = ''; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @var string | |
| 70 | + */ | |
| 71 | + private $spaceBetweenBlocks = "\n"; | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Content injected in and around at-rule blocks. | |
| 75 | + * | |
| 76 | + * @var string | |
| 77 | + */ | |
| 78 | + private $contentBeforeAtRuleBlock = ''; | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * @var string | |
| 82 | + */ | |
| 83 | + private $contentAfterAtRuleBlock = ''; | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * This is what’s printed before and after the comma if a declaration block contains multiple selectors. | |
| 87 | + * | |
| 88 | + * @var string | |
| 89 | + */ | |
| 90 | + private $spaceBeforeSelectorSeparator = ''; | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * @var string | |
| 94 | + */ | |
| 95 | + private $spaceAfterSelectorSeparator = ' '; | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * This is what’s inserted before the separator in value lists, by default. | |
| 99 | + * | |
| 100 | + * @var string | |
| 101 | + */ | |
| 102 | + private $spaceBeforeListArgumentSeparator = ''; | |
| 103 | + | |
| 104 | + /** | |
| 105 | + * Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string. | |
| 106 | + * | |
| 107 | + * @var array<non-empty-string, string> | |
| 108 | + */ | |
| 109 | + private $spaceBeforeListArgumentSeparators = []; | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * This is what’s inserted after the separator in value lists, by default. | |
| 113 | + * | |
| 114 | + * @var string | |
| 115 | + */ | |
| 116 | + private $spaceAfterListArgumentSeparator = ''; | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string. | |
| 120 | + * | |
| 121 | + * @var array<non-empty-string, string> | |
| 122 | + */ | |
| 123 | + private $spaceAfterListArgumentSeparators = []; | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * @var string | |
| 127 | + */ | |
| 128 | + private $spaceBeforeOpeningBrace = ' '; | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * Content injected in and around declaration blocks. | |
| 132 | + * | |
| 133 | + * @var string | |
| 134 | + */ | |
| 135 | + private $contentBeforeDeclarationBlock = ''; | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * @var string | |
| 139 | + */ | |
| 140 | + private $contentAfterDeclarationBlockSelectors = ''; | |
| 141 | + | |
| 142 | + /** | |
| 143 | + * @var string | |
| 144 | + */ | |
| 145 | + private $contentAfterDeclarationBlock = ''; | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * Indentation character(s) per level. Only applicable if newlines are used in any of the spacing settings. | |
| 149 | + * | |
| 150 | + * @var string | |
| 151 | + */ | |
| 152 | + private $indentation = "\t"; | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Output exceptions. | |
| 156 | + * | |
| 157 | + * @var bool | |
| 158 | + */ | |
| 159 | + private $shouldIgnoreExceptions = false; | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * Render comments for lists and RuleSets | |
| 163 | + * | |
| 164 | + * @var bool | |
| 165 | + */ | |
| 166 | + private $shouldRenderComments = false; | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * @var OutputFormatter|null | |
| 170 | + */ | |
| 171 | + private $outputFormatter; | |
| 172 | + | |
| 173 | + /** | |
| 174 | + * @var OutputFormat|null | |
| 175 | + */ | |
| 176 | + private $nextLevelFormat; | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * @var int<0, max> | |
| 180 | + */ | |
| 181 | + private $indentationLevel = 0; | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * @return non-empty-string | |
| 185 | + * | |
| 186 | + * @internal | |
| 187 | + */ | |
| 188 | + public function getStringQuotingType(): string | |
| 189 | + { | |
| 190 | + return $this->stringQuotingType; | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** | |
| 194 | + * @param non-empty-string $quotingType | |
| 195 | + * | |
| 196 | + * @return $this fluent interface | |
| 197 | + */ | |
| 198 | + public function setStringQuotingType(string $quotingType): self | |
| 199 | + { | |
| 200 | + $this->stringQuotingType = $quotingType; | |
| 201 | + | |
| 202 | + return $this; | |
| 203 | + } | |
| 204 | + | |
| 205 | + /** | |
| 206 | + * @internal | |
| 207 | + */ | |
| 208 | + public function usesRgbHashNotation(): bool | |
| 209 | + { | |
| 210 | + return $this->usesRgbHashNotation; | |
| 211 | + } | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * @return $this fluent interface | |
| 215 | + */ | |
| 216 | + public function setRGBHashNotation(bool $usesRgbHashNotation): self | |
| 217 | + { | |
| 218 | + $this->usesRgbHashNotation = $usesRgbHashNotation; | |
| 219 | + | |
| 220 | + return $this; | |
| 221 | + } | |
| 222 | + | |
| 223 | + /** | |
| 224 | + * @internal | |
| 225 | + */ | |
| 226 | + public function shouldRenderSemicolonAfterLastRule(): bool | |
| 227 | + { | |
| 228 | + return $this->renderSemicolonAfterLastRule; | |
| 229 | + } | |
| 230 | + | |
| 231 | + /** | |
| 232 | + * @return $this fluent interface | |
| 233 | + */ | |
| 234 | + public function setSemicolonAfterLastRule(bool $renderSemicolonAfterLastRule): self | |
| 235 | + { | |
| 236 | + $this->renderSemicolonAfterLastRule = $renderSemicolonAfterLastRule; | |
| 237 | + | |
| 238 | + return $this; | |
| 239 | + } | |
| 240 | + | |
| 241 | + /** | |
| 242 | + * @internal | |
| 243 | + */ | |
| 244 | + public function getSpaceAfterRuleName(): string | |
| 245 | + { | |
| 246 | + return $this->spaceAfterRuleName; | |
| 247 | + } | |
| 248 | + | |
| 249 | + /** | |
| 250 | + * @return $this fluent interface | |
| 251 | + */ | |
| 252 | + public function setSpaceAfterRuleName(string $whitespace): self | |
| 253 | + { | |
| 254 | + $this->spaceAfterRuleName = $whitespace; | |
| 255 | + | |
| 256 | + return $this; | |
| 257 | + } | |
| 258 | + | |
| 259 | + /** | |
| 260 | + * @internal | |
| 261 | + */ | |
| 262 | + public function getSpaceBeforeRules(): string | |
| 263 | + { | |
| 264 | + return $this->spaceBeforeRules; | |
| 265 | + } | |
| 266 | + | |
| 267 | + /** | |
| 268 | + * @return $this fluent interface | |
| 269 | + */ | |
| 270 | + public function setSpaceBeforeRules(string $whitespace): self | |
| 271 | + { | |
| 272 | + $this->spaceBeforeRules = $whitespace; | |
| 273 | + | |
| 274 | + return $this; | |
| 275 | + } | |
| 276 | + | |
| 277 | + /** | |
| 278 | + * @internal | |
| 279 | + */ | |
| 280 | + public function getSpaceAfterRules(): string | |
| 281 | + { | |
| 282 | + return $this->spaceAfterRules; | |
| 283 | + } | |
| 284 | + | |
| 285 | + /** | |
| 286 | + * @return $this fluent interface | |
| 287 | + */ | |
| 288 | + public function setSpaceAfterRules(string $whitespace): self | |
| 289 | + { | |
| 290 | + $this->spaceAfterRules = $whitespace; | |
| 291 | + | |
| 292 | + return $this; | |
| 293 | + } | |
| 294 | + | |
| 295 | + /** | |
| 296 | + * @internal | |
| 297 | + */ | |
| 298 | + public function getSpaceBetweenRules(): string | |
| 299 | + { | |
| 300 | + return $this->spaceBetweenRules; | |
| 301 | + } | |
| 302 | + | |
| 303 | + /** | |
| 304 | + * @return $this fluent interface | |
| 305 | + */ | |
| 306 | + public function setSpaceBetweenRules(string $whitespace): self | |
| 307 | + { | |
| 308 | + $this->spaceBetweenRules = $whitespace; | |
| 309 | + | |
| 310 | + return $this; | |
| 311 | + } | |
| 312 | + | |
| 313 | + /** | |
| 314 | + * @internal | |
| 315 | + */ | |
| 316 | + public function getSpaceBeforeBlocks(): string | |
| 317 | + { | |
| 318 | + return $this->spaceBeforeBlocks; | |
| 319 | + } | |
| 320 | + | |
| 321 | + /** | |
| 322 | + * @return $this fluent interface | |
| 323 | + */ | |
| 324 | + public function setSpaceBeforeBlocks(string $whitespace): self | |
| 325 | + { | |
| 326 | + $this->spaceBeforeBlocks = $whitespace; | |
| 327 | + | |
| 328 | + return $this; | |
| 329 | + } | |
| 330 | + | |
| 331 | + /** | |
| 332 | + * @internal | |
| 333 | + */ | |
| 334 | + public function getSpaceAfterBlocks(): string | |
| 335 | + { | |
| 336 | + return $this->spaceAfterBlocks; | |
| 337 | + } | |
| 338 | + | |
| 339 | + /** | |
| 340 | + * @return $this fluent interface | |
| 341 | + */ | |
| 342 | + public function setSpaceAfterBlocks(string $whitespace): self | |
| 343 | + { | |
| 344 | + $this->spaceAfterBlocks = $whitespace; | |
| 345 | + | |
| 346 | + return $this; | |
| 347 | + } | |
| 348 | + | |
| 349 | + /** | |
| 350 | + * @internal | |
| 351 | + */ | |
| 352 | + public function getSpaceBetweenBlocks(): string | |
| 353 | + { | |
| 354 | + return $this->spaceBetweenBlocks; | |
| 355 | + } | |
| 356 | + | |
| 357 | + /** | |
| 358 | + * @return $this fluent interface | |
| 359 | + */ | |
| 360 | + public function setSpaceBetweenBlocks(string $whitespace): self | |
| 361 | + { | |
| 362 | + $this->spaceBetweenBlocks = $whitespace; | |
| 363 | + | |
| 364 | + return $this; | |
| 365 | + } | |
| 366 | + | |
| 367 | + /** | |
| 368 | + * @internal | |
| 369 | + */ | |
| 370 | + public function getContentBeforeAtRuleBlock(): string | |
| 371 | + { | |
| 372 | + return $this->contentBeforeAtRuleBlock; | |
| 373 | + } | |
| 374 | + | |
| 375 | + /** | |
| 376 | + * @return $this fluent interface | |
| 377 | + */ | |
| 378 | + public function setBeforeAtRuleBlock(string $content): self | |
| 379 | + { | |
| 380 | + $this->contentBeforeAtRuleBlock = $content; | |
| 381 | + | |
| 382 | + return $this; | |
| 383 | + } | |
| 384 | + | |
| 385 | + /** | |
| 386 | + * @internal | |
| 387 | + */ | |
| 388 | + public function getContentAfterAtRuleBlock(): string | |
| 389 | + { | |
| 390 | + return $this->contentAfterAtRuleBlock; | |
| 391 | + } | |
| 392 | + | |
| 393 | + /** | |
| 394 | + * @return $this fluent interface | |
| 395 | + */ | |
| 396 | + public function setAfterAtRuleBlock(string $content): self | |
| 397 | + { | |
| 398 | + $this->contentAfterAtRuleBlock = $content; | |
| 399 | + | |
| 400 | + return $this; | |
| 401 | + } | |
| 402 | + | |
| 403 | + /** | |
| 404 | + * @internal | |
| 405 | + */ | |
| 406 | + public function getSpaceBeforeSelectorSeparator(): string | |
| 407 | + { | |
| 408 | + return $this->spaceBeforeSelectorSeparator; | |
| 409 | + } | |
| 410 | + | |
| 411 | + /** | |
| 412 | + * @return $this fluent interface | |
| 413 | + */ | |
| 414 | + public function setSpaceBeforeSelectorSeparator(string $whitespace): self | |
| 415 | + { | |
| 416 | + $this->spaceBeforeSelectorSeparator = $whitespace; | |
| 417 | + | |
| 418 | + return $this; | |
| 419 | + } | |
| 420 | + | |
| 421 | + /** | |
| 422 | + * @internal | |
| 423 | + */ | |
| 424 | + public function getSpaceAfterSelectorSeparator(): string | |
| 425 | + { | |
| 426 | + return $this->spaceAfterSelectorSeparator; | |
| 427 | + } | |
| 428 | + | |
| 429 | + /** | |
| 430 | + * @return $this fluent interface | |
| 431 | + */ | |
| 432 | + public function setSpaceAfterSelectorSeparator(string $whitespace): self | |
| 433 | + { | |
| 434 | + $this->spaceAfterSelectorSeparator = $whitespace; | |
| 435 | + | |
| 436 | + return $this; | |
| 437 | + } | |
| 438 | + | |
| 439 | + /** | |
| 440 | + * @internal | |
| 441 | + */ | |
| 442 | + public function getSpaceBeforeListArgumentSeparator(): string | |
| 443 | + { | |
| 444 | + return $this->spaceBeforeListArgumentSeparator; | |
| 445 | + } | |
| 446 | + | |
| 447 | + /** | |
| 448 | + * @return $this fluent interface | |
| 449 | + */ | |
| 450 | + public function setSpaceBeforeListArgumentSeparator(string $whitespace): self | |
| 451 | + { | |
| 452 | + $this->spaceBeforeListArgumentSeparator = $whitespace; | |
| 453 | + | |
| 454 | + return $this; | |
| 455 | + } | |
| 456 | + | |
| 457 | + /** | |
| 458 | + * @return array<non-empty-string, string> | |
| 459 | + * | |
| 460 | + * @internal | |
| 461 | + */ | |
| 462 | + public function getSpaceBeforeListArgumentSeparators(): array | |
| 463 | + { | |
| 464 | + return $this->spaceBeforeListArgumentSeparators; | |
| 465 | + } | |
| 466 | + | |
| 467 | + /** | |
| 468 | + * @param array<non-empty-string, string> $separatorSpaces | |
| 469 | + * | |
| 470 | + * @return $this fluent interface | |
| 471 | + */ | |
| 472 | + public function setSpaceBeforeListArgumentSeparators(array $separatorSpaces): self | |
| 473 | + { | |
| 474 | + $this->spaceBeforeListArgumentSeparators = $separatorSpaces; | |
| 475 | + | |
| 476 | + return $this; | |
| 477 | + } | |
| 478 | + | |
| 479 | + /** | |
| 480 | + * @internal | |
| 481 | + */ | |
| 482 | + public function getSpaceAfterListArgumentSeparator(): string | |
| 483 | + { | |
| 484 | + return $this->spaceAfterListArgumentSeparator; | |
| 485 | + } | |
| 486 | + | |
| 487 | + /** | |
| 488 | + * @return $this fluent interface | |
| 489 | + */ | |
| 490 | + public function setSpaceAfterListArgumentSeparator(string $whitespace): self | |
| 491 | + { | |
| 492 | + $this->spaceAfterListArgumentSeparator = $whitespace; | |
| 493 | + | |
| 494 | + return $this; | |
| 495 | + } | |
| 496 | + | |
| 497 | + /** | |
| 498 | + * @return array<non-empty-string, string> | |
| 499 | + * | |
| 500 | + * @internal | |
| 501 | + */ | |
| 502 | + public function getSpaceAfterListArgumentSeparators(): array | |
| 503 | + { | |
| 504 | + return $this->spaceAfterListArgumentSeparators; | |
| 505 | + } | |
| 506 | + | |
| 507 | + /** | |
| 508 | + * @param array<non-empty-string, string> $separatorSpaces | |
| 509 | + * | |
| 510 | + * @return $this fluent interface | |
| 511 | + */ | |
| 512 | + public function setSpaceAfterListArgumentSeparators(array $separatorSpaces): self | |
| 513 | + { | |
| 514 | + $this->spaceAfterListArgumentSeparators = $separatorSpaces; | |
| 515 | + | |
| 516 | + return $this; | |
| 517 | + } | |
| 518 | + | |
| 519 | + /** | |
| 520 | + * @internal | |
| 521 | + */ | |
| 522 | + public function getSpaceBeforeOpeningBrace(): string | |
| 523 | + { | |
| 524 | + return $this->spaceBeforeOpeningBrace; | |
| 525 | + } | |
| 526 | + | |
| 527 | + /** | |
| 528 | + * @return $this fluent interface | |
| 529 | + */ | |
| 530 | + public function setSpaceBeforeOpeningBrace(string $whitespace): self | |
| 531 | + { | |
| 532 | + $this->spaceBeforeOpeningBrace = $whitespace; | |
| 533 | + | |
| 534 | + return $this; | |
| 535 | + } | |
| 536 | + | |
| 537 | + /** | |
| 538 | + * @internal | |
| 539 | + */ | |
| 540 | + public function getContentBeforeDeclarationBlock(): string | |
| 541 | + { | |
| 542 | + return $this->contentBeforeDeclarationBlock; | |
| 543 | + } | |
| 544 | + | |
| 545 | + /** | |
| 546 | + * @return $this fluent interface | |
| 547 | + */ | |
| 548 | + public function setBeforeDeclarationBlock(string $content): self | |
| 549 | + { | |
| 550 | + $this->contentBeforeDeclarationBlock = $content; | |
| 551 | + | |
| 552 | + return $this; | |
| 553 | + } | |
| 554 | + | |
| 555 | + /** | |
| 556 | + * @internal | |
| 557 | + */ | |
| 558 | + public function getContentAfterDeclarationBlockSelectors(): string | |
| 559 | + { | |
| 560 | + return $this->contentAfterDeclarationBlockSelectors; | |
| 561 | + } | |
| 562 | + | |
| 563 | + /** | |
| 564 | + * @return $this fluent interface | |
| 565 | + */ | |
| 566 | + public function setAfterDeclarationBlockSelectors(string $content): self | |
| 567 | + { | |
| 568 | + $this->contentAfterDeclarationBlockSelectors = $content; | |
| 569 | + | |
| 570 | + return $this; | |
| 571 | + } | |
| 572 | + | |
| 573 | + /** | |
| 574 | + * @internal | |
| 575 | + */ | |
| 576 | + public function getContentAfterDeclarationBlock(): string | |
| 577 | + { | |
| 578 | + return $this->contentAfterDeclarationBlock; | |
| 579 | + } | |
| 580 | + | |
| 581 | + /** | |
| 582 | + * @return $this fluent interface | |
| 583 | + */ | |
| 584 | + public function setAfterDeclarationBlock(string $content): self | |
| 585 | + { | |
| 586 | + $this->contentAfterDeclarationBlock = $content; | |
| 587 | + | |
| 588 | + return $this; | |
| 589 | + } | |
| 590 | + | |
| 591 | + /** | |
| 592 | + * @internal | |
| 593 | + */ | |
| 594 | + public function getIndentation(): string | |
| 595 | + { | |
| 596 | + return $this->indentation; | |
| 597 | + } | |
| 598 | + | |
| 599 | + /** | |
| 600 | + * @return $this fluent interface | |
| 601 | + */ | |
| 602 | + public function setIndentation(string $indentation): self | |
| 603 | + { | |
| 604 | + $this->indentation = $indentation; | |
| 605 | + | |
| 606 | + return $this; | |
| 607 | + } | |
| 608 | + | |
| 609 | + /** | |
| 610 | + * @internal | |
| 611 | + */ | |
| 612 | + public function shouldIgnoreExceptions(): bool | |
| 613 | + { | |
| 614 | + return $this->shouldIgnoreExceptions; | |
| 615 | + } | |
| 616 | + | |
| 617 | + /** | |
| 618 | + * @return $this fluent interface | |
| 619 | + */ | |
| 620 | + public function setIgnoreExceptions(bool $ignoreExceptions): self | |
| 621 | + { | |
| 622 | + $this->shouldIgnoreExceptions = $ignoreExceptions; | |
| 623 | + | |
| 624 | + return $this; | |
| 625 | + } | |
| 626 | + | |
| 627 | + /** | |
| 628 | + * @internal | |
| 629 | + */ | |
| 630 | + public function shouldRenderComments(): bool | |
| 631 | + { | |
| 632 | + return $this->shouldRenderComments; | |
| 633 | + } | |
| 634 | + | |
| 635 | + /** | |
| 636 | + * @return $this fluent interface | |
| 637 | + */ | |
| 638 | + public function setRenderComments(bool $renderComments): self | |
| 639 | + { | |
| 640 | + $this->shouldRenderComments = $renderComments; | |
| 641 | + | |
| 642 | + return $this; | |
| 643 | + } | |
| 644 | + | |
| 645 | + /** | |
| 646 | + * @return int<0, max> | |
| 647 | + * | |
| 648 | + * @internal | |
| 649 | + */ | |
| 650 | + public function getIndentationLevel(): int | |
| 651 | + { | |
| 652 | + return $this->indentationLevel; | |
| 653 | + } | |
| 654 | + | |
| 655 | + /** | |
| 656 | + * @param int<1, max> $numberOfTabs | |
| 657 | + * | |
| 658 | + * @return $this fluent interface | |
| 659 | + */ | |
| 660 | + public function indentWithTabs(int $numberOfTabs = 1): self | |
| 661 | + { | |
| 662 | + return $this->setIndentation(\str_repeat("\t", $numberOfTabs)); | |
| 663 | + } | |
| 664 | + | |
| 665 | + /** | |
| 666 | + * @param int<1, max> $numberOfSpaces | |
| 667 | + * | |
| 668 | + * @return $this fluent interface | |
| 669 | + */ | |
| 670 | + public function indentWithSpaces(int $numberOfSpaces = 2): self | |
| 671 | + { | |
| 672 | + return $this->setIndentation(\str_repeat(' ', $numberOfSpaces)); | |
| 673 | + } | |
| 674 | + | |
| 675 | + /** | |
| 676 | + * @internal since V8.8.0 | |
| 677 | + */ | |
| 678 | + public function nextLevel(): self | |
| 679 | + { | |
| 680 | + if ($this->nextLevelFormat === null) { | |
| 681 | + $this->nextLevelFormat = clone $this; | |
| 682 | + $this->nextLevelFormat->indentationLevel++; | |
| 683 | + $this->nextLevelFormat->outputFormatter = null; | |
| 684 | + } | |
| 685 | + return $this->nextLevelFormat; | |
| 686 | + } | |
| 687 | + | |
| 688 | + public function beLenient(): void | |
| 689 | + { | |
| 690 | + $this->shouldIgnoreExceptions = true; | |
| 691 | + } | |
| 692 | + | |
| 693 | + /** | |
| 694 | + * @internal since 8.8.0 | |
| 695 | + */ | |
| 696 | + public function getFormatter(): OutputFormatter | |
| 697 | + { | |
| 698 | + if ($this->outputFormatter === null) { | |
| 699 | + $this->outputFormatter = new OutputFormatter($this); | |
| 700 | + } | |
| 701 | + | |
| 702 | + return $this->outputFormatter; | |
| 703 | + } | |
| 704 | + | |
| 705 | + /** | |
| 706 | + * Creates an instance of this class without any particular formatting settings. | |
| 707 | + */ | |
| 708 | + public static function create(): self | |
| 709 | + { | |
| 710 | + return new OutputFormat(); | |
| 711 | + } | |
| 712 | + | |
| 713 | + /** | |
| 714 | + * Creates an instance of this class with a preset for compact formatting. | |
| 715 | + */ | |
| 716 | + public static function createCompact(): self | |
| 717 | + { | |
| 718 | + $format = self::create(); | |
| 719 | + $format | |
| 720 | + ->setSpaceBeforeRules('') | |
| 721 | + ->setSpaceBetweenRules('') | |
| 722 | + ->setSpaceAfterRules('') | |
| 723 | + ->setSpaceBeforeBlocks('') | |
| 724 | + ->setSpaceBetweenBlocks('') | |
| 725 | + ->setSpaceAfterBlocks('') | |
| 726 | + ->setSpaceAfterRuleName('') | |
| 727 | + ->setSpaceBeforeOpeningBrace('') | |
| 728 | + ->setSpaceAfterSelectorSeparator('') | |
| 729 | + ->setSemicolonAfterLastRule(false) | |
| 730 | + ->setRenderComments(false); | |
| 731 | + | |
| 732 | + return $format; | |
| 733 | + } | |
| 734 | + | |
| 735 | + /** | |
| 736 | + * Creates an instance of this class with a preset for pretty formatting. | |
| 737 | + */ | |
| 738 | + public static function createPretty(): self | |
| 739 | + { | |
| 740 | + $format = self::create(); | |
| 741 | + $format | |
| 742 | + ->setSpaceBeforeRules("\n") | |
| 743 | + ->setSpaceBetweenRules("\n") | |
| 744 | + ->setSpaceAfterRules("\n") | |
| 745 | + ->setSpaceBeforeBlocks("\n") | |
| 746 | + ->setSpaceBetweenBlocks("\n\n") | |
| 747 | + ->setSpaceAfterBlocks("\n") | |
| 748 | + ->setSpaceAfterListArgumentSeparators([',' => ' ']) | |
| 749 | + ->setRenderComments(true); | |
| 750 | + | |
| 751 | + return $format; | |
| 752 | + } | |
| 753 | +} | |