| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sabberworm\CSS\Property; |
| 5 |
|
| 6 |
use WCPOS\Vendor\Sabberworm\CSS\Comment\CommentContainer; |
| 7 |
use WCPOS\Vendor\Sabberworm\CSS\OutputFormat; |
| 8 |
use WCPOS\Vendor\Sabberworm\CSS\Position\Position; |
| 9 |
use WCPOS\Vendor\Sabberworm\CSS\Position\Positionable; |
| 10 |
use WCPOS\Vendor\Sabberworm\CSS\ShortClassNameProvider; |
| 11 |
use WCPOS\Vendor\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 |
|