| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace AcyMailing\Libraries\Sabberworm\CSS\CSSList; |
| 6 |
|
| 7 |
use AcyMailing\Libraries\Sabberworm\CSS\OutputFormat; |
| 8 |
use AcyMailing\Libraries\Sabberworm\CSS\Property\AtRule; |
| 9 |
|
| 10 |
/** |
| 11 |
* A `BlockList` constructed by an unknown at-rule. `@media` rules are rendered into `AtRuleBlockList` objects. |
| 12 |
*/ |
| 13 |
class AtRuleBlockList extends CSSBlockList implements AtRule |
| 14 |
{ |
| 15 |
/** |
| 16 |
* @var non-empty-string |
| 17 |
*/ |
| 18 |
private $type; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private $arguments; |
| 24 |
|
| 25 |
/** |
| 26 |
* @param non-empty-string $type |
| 27 |
* @param int<1, max>|null $lineNumber |
| 28 |
*/ |
| 29 |
public function __construct(string $type, string $arguments = '', ?int $lineNumber = null) |
| 30 |
{ |
| 31 |
parent::__construct($lineNumber); |
| 32 |
$this->type = $type; |
| 33 |
$this->arguments = $arguments; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* @return non-empty-string |
| 38 |
*/ |
| 39 |
public function atRuleName(): string |
| 40 |
{ |
| 41 |
return $this->type; |
| 42 |
} |
| 43 |
|
| 44 |
public function atRuleArgs(): string |
| 45 |
{ |
| 46 |
return $this->arguments; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* @return non-empty-string |
| 51 |
*/ |
| 52 |
public function render(OutputFormat $outputFormat): string |
| 53 |
{ |
| 54 |
$formatter = $outputFormat->getFormatter(); |
| 55 |
$result = $formatter->comments($this); |
| 56 |
$result .= $outputFormat->getContentBeforeAtRuleBlock(); |
| 57 |
$arguments = $this->arguments; |
| 58 |
if ($arguments !== '') { |
| 59 |
$arguments = ' ' . $arguments; |
| 60 |
} |
| 61 |
$result .= "@{$this->type}$arguments{$formatter->spaceBeforeOpeningBrace()}{"; |
| 62 |
$result .= $this->renderListContents($outputFormat); |
| 63 |
$result .= '}'; |
| 64 |
$result .= $outputFormat->getContentAfterAtRuleBlock(); |
| 65 |
return $result; |
| 66 |
} |
| 67 |
|
| 68 |
public function isRootList(): bool |
| 69 |
{ |
| 70 |
return false; |
| 71 |
} |
| 72 |
} |
| 73 |
|