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