| 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\URL; |
| 12 |
/** |
| 13 |
* Class representing an `@import` rule. |
| 14 |
*/ |
| 15 |
class Import implements AtRule, Positionable |
| 16 |
{ |
| 17 |
use CommentContainer; |
| 18 |
use Position; |
| 19 |
use ShortClassNameProvider; |
| 20 |
/** |
| 21 |
* @var URL |
| 22 |
*/ |
| 23 |
private $location; |
| 24 |
/** |
| 25 |
* @var string|null |
| 26 |
*/ |
| 27 |
private $mediaQuery; |
| 28 |
/** |
| 29 |
* @param int<1, max>|null $lineNumber |
| 30 |
*/ |
| 31 |
public function __construct(URL $location, ?string $mediaQuery, ?int $lineNumber = null) |
| 32 |
{ |
| 33 |
$this->location = $location; |
| 34 |
$this->mediaQuery = $mediaQuery; |
| 35 |
$this->setPosition($lineNumber); |
| 36 |
} |
| 37 |
public function setLocation(URL $location) : void |
| 38 |
{ |
| 39 |
$this->location = $location; |
| 40 |
} |
| 41 |
public function getLocation() : URL |
| 42 |
{ |
| 43 |
return $this->location; |
| 44 |
} |
| 45 |
/** |
| 46 |
* @return non-empty-string |
| 47 |
*/ |
| 48 |
public function render(OutputFormat $outputFormat) : string |
| 49 |
{ |
| 50 |
return $outputFormat->getFormatter()->comments($this) . '@import ' . $this->location->render($outputFormat) . ($this->mediaQuery === null ? '' : ' ' . $this->mediaQuery) . ';'; |
| 51 |
} |
| 52 |
/** |
| 53 |
* @return non-empty-string |
| 54 |
*/ |
| 55 |
public function atRuleName() : string |
| 56 |
{ |
| 57 |
return 'import'; |
| 58 |
} |
| 59 |
/** |
| 60 |
* @return array{0: URL, 1?: non-empty-string} |
| 61 |
*/ |
| 62 |
public function atRuleArgs() : array |
| 63 |
{ |
| 64 |
$result = [$this->location]; |
| 65 |
if (\is_string($this->mediaQuery) && $this->mediaQuery !== '') { |
| 66 |
$result[] = $this->mediaQuery; |
| 67 |
} |
| 68 |
return $result; |
| 69 |
} |
| 70 |
public function getMediaQuery() : ?string |
| 71 |
{ |
| 72 |
return $this->mediaQuery; |
| 73 |
} |
| 74 |
/** |
| 75 |
* @return array<string, bool|int|float|string|array<mixed>|null> |
| 76 |
* |
| 77 |
* @internal |
| 78 |
*/ |
| 79 |
public function getArrayRepresentation() : array |
| 80 |
{ |
| 81 |
return [ |
| 82 |
'class' => $this->getShortClassName(), |
| 83 |
// We're using the term "uri" here to match the wording used in the specs: |
| 84 |
// https://www.w3.org/TR/CSS22/cascade.html#at-import |
| 85 |
'uri' => $this->location->getArrayRepresentation(), |
| 86 |
]; |
| 87 |
} |
| 88 |
} |
| 89 |
|