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