| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace AcyMailing\Libraries\Sabberworm\CSS\Property; |
| 6 |
|
| 7 |
use AcyMailing\Libraries\Sabberworm\CSS\Comment\CommentContainer; |
| 8 |
use AcyMailing\Libraries\Sabberworm\CSS\OutputFormat; |
| 9 |
use AcyMailing\Libraries\Sabberworm\CSS\Position\Position; |
| 10 |
use AcyMailing\Libraries\Sabberworm\CSS\Position\Positionable; |
| 11 |
use AcyMailing\Libraries\Sabberworm\CSS\Value\CSSString; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class representing an `@charset` rule. |
| 15 |
* |
| 16 |
* The following restrictions apply: |
| 17 |
* - May not be found in any CSSList other than the Document. |
| 18 |
* - May only appear at the very top of a Document’s contents. |
| 19 |
* - Must not appear more than once. |
| 20 |
*/ |
| 21 |
class Charset implements AtRule, Positionable |
| 22 |
{ |
| 23 |
use CommentContainer; |
| 24 |
use Position; |
| 25 |
|
| 26 |
/** |
| 27 |
* @var CSSString |
| 28 |
*/ |
| 29 |
private $charset; |
| 30 |
|
| 31 |
/** |
| 32 |
* @param int<1, max>|null $lineNumber |
| 33 |
*/ |
| 34 |
public function __construct(CSSString $charset, ?int $lineNumber = null) |
| 35 |
{ |
| 36 |
$this->charset = $charset; |
| 37 |
$this->setPosition($lineNumber); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* @param string|CSSString $charset |
| 42 |
*/ |
| 43 |
public function setCharset($charset): void |
| 44 |
{ |
| 45 |
$charset = $charset instanceof CSSString ? $charset : new CSSString($charset); |
| 46 |
$this->charset = $charset; |
| 47 |
} |
| 48 |
|
| 49 |
public function getCharset(): string |
| 50 |
{ |
| 51 |
return $this->charset->getString(); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* @return non-empty-string |
| 56 |
*/ |
| 57 |
public function render(OutputFormat $outputFormat): string |
| 58 |
{ |
| 59 |
return "{$outputFormat->getFormatter()->comments($this)}@charset {$this->charset->render($outputFormat)};"; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* @return non-empty-string |
| 64 |
*/ |
| 65 |
public function atRuleName(): string |
| 66 |
{ |
| 67 |
return 'charset'; |
| 68 |
} |
| 69 |
|
| 70 |
public function atRuleArgs(): CSSString |
| 71 |
{ |
| 72 |
return $this->charset; |
| 73 |
} |
| 74 |
} |
| 75 |
|