AtRule.php
3 years ago
CSSNamespace.php
3 years ago
Charset.php
3 years ago
Import.php
3 years ago
KeyframeSelector.php
3 years ago
Selector.php
3 years ago
Import.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Sabberworm\CSS\Property; |
| 4 | |
| 5 | use IAWP\Sabberworm\CSS\Comment\Comment; |
| 6 | use IAWP\Sabberworm\CSS\OutputFormat; |
| 7 | use IAWP\Sabberworm\CSS\Value\URL; |
| 8 | /** |
| 9 | * Class representing an `@import` rule. |
| 10 | */ |
| 11 | class Import implements AtRule |
| 12 | { |
| 13 | /** |
| 14 | * @var URL |
| 15 | */ |
| 16 | private $oLocation; |
| 17 | /** |
| 18 | * @var string |
| 19 | */ |
| 20 | private $sMediaQuery; |
| 21 | /** |
| 22 | * @var int |
| 23 | */ |
| 24 | protected $iLineNo; |
| 25 | /** |
| 26 | * @var array<array-key, Comment> |
| 27 | */ |
| 28 | protected $aComments; |
| 29 | /** |
| 30 | * @param URL $oLocation |
| 31 | * @param string $sMediaQuery |
| 32 | * @param int $iLineNo |
| 33 | */ |
| 34 | public function __construct(URL $oLocation, $sMediaQuery, $iLineNo = 0) |
| 35 | { |
| 36 | $this->oLocation = $oLocation; |
| 37 | $this->sMediaQuery = $sMediaQuery; |
| 38 | $this->iLineNo = $iLineNo; |
| 39 | $this->aComments = []; |
| 40 | } |
| 41 | /** |
| 42 | * @return int |
| 43 | */ |
| 44 | public function getLineNo() |
| 45 | { |
| 46 | return $this->iLineNo; |
| 47 | } |
| 48 | /** |
| 49 | * @param URL $oLocation |
| 50 | * |
| 51 | * @return void |
| 52 | */ |
| 53 | public function setLocation($oLocation) |
| 54 | { |
| 55 | $this->oLocation = $oLocation; |
| 56 | } |
| 57 | /** |
| 58 | * @return URL |
| 59 | */ |
| 60 | public function getLocation() |
| 61 | { |
| 62 | return $this->oLocation; |
| 63 | } |
| 64 | /** |
| 65 | * @return string |
| 66 | */ |
| 67 | public function __toString() |
| 68 | { |
| 69 | return $this->render(new OutputFormat()); |
| 70 | } |
| 71 | /** |
| 72 | * @return string |
| 73 | */ |
| 74 | public function render(OutputFormat $oOutputFormat) |
| 75 | { |
| 76 | return "@import " . $this->oLocation->render($oOutputFormat) . ($this->sMediaQuery === null ? '' : ' ' . $this->sMediaQuery) . ';'; |
| 77 | } |
| 78 | /** |
| 79 | * @return string |
| 80 | */ |
| 81 | public function atRuleName() |
| 82 | { |
| 83 | return 'import'; |
| 84 | } |
| 85 | /** |
| 86 | * @return array<int, URL|string> |
| 87 | */ |
| 88 | public function atRuleArgs() |
| 89 | { |
| 90 | $aResult = [$this->oLocation]; |
| 91 | if ($this->sMediaQuery) { |
| 92 | \array_push($aResult, $this->sMediaQuery); |
| 93 | } |
| 94 | return $aResult; |
| 95 | } |
| 96 | /** |
| 97 | * @param array<array-key, Comment> $aComments |
| 98 | * |
| 99 | * @return void |
| 100 | */ |
| 101 | public function addComments(array $aComments) |
| 102 | { |
| 103 | $this->aComments = \array_merge($this->aComments, $aComments); |
| 104 | } |
| 105 | /** |
| 106 | * @return array<array-key, Comment> |
| 107 | */ |
| 108 | public function getComments() |
| 109 | { |
| 110 | return $this->aComments; |
| 111 | } |
| 112 | /** |
| 113 | * @param array<array-key, Comment> $aComments |
| 114 | * |
| 115 | * @return void |
| 116 | */ |
| 117 | public function setComments(array $aComments) |
| 118 | { |
| 119 | $this->aComments = $aComments; |
| 120 | } |
| 121 | } |
| 122 |