| 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\CSSString; |
| 12 |
use AcyMailing\Libraries\Sabberworm\CSS\Value\URL; |
| 13 |
|
| 14 |
/** |
| 15 |
* `CSSNamespace` represents an `@namespace` rule. |
| 16 |
*/ |
| 17 |
class CSSNamespace implements AtRule, Positionable |
| 18 |
{ |
| 19 |
use CommentContainer; |
| 20 |
use Position; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var CSSString|URL |
| 24 |
*/ |
| 25 |
private $url; |
| 26 |
|
| 27 |
/** |
| 28 |
* @var string|null |
| 29 |
*/ |
| 30 |
private $prefix; |
| 31 |
|
| 32 |
/** |
| 33 |
* @param CSSString|URL $url |
| 34 |
* @param int<1, max>|null $lineNumber |
| 35 |
*/ |
| 36 |
public function __construct($url, ?string $prefix = null, ?int $lineNumber = null) |
| 37 |
{ |
| 38 |
$this->url = $url; |
| 39 |
$this->prefix = $prefix; |
| 40 |
$this->setPosition($lineNumber); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* @return non-empty-string |
| 45 |
*/ |
| 46 |
public function render(OutputFormat $outputFormat): string |
| 47 |
{ |
| 48 |
return '@namespace ' . ($this->prefix === null ? '' : $this->prefix . ' ') |
| 49 |
. $this->url->render($outputFormat) . ';'; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* @return CSSString|URL |
| 54 |
*/ |
| 55 |
public function getUrl() |
| 56 |
{ |
| 57 |
return $this->url; |
| 58 |
} |
| 59 |
|
| 60 |
public function getPrefix(): ?string |
| 61 |
{ |
| 62 |
return $this->prefix; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* @param CSSString|URL $url |
| 67 |
*/ |
| 68 |
public function setUrl($url): void |
| 69 |
{ |
| 70 |
$this->url = $url; |
| 71 |
} |
| 72 |
|
| 73 |
public function setPrefix(string $prefix): void |
| 74 |
{ |
| 75 |
$this->prefix = $prefix; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* @return non-empty-string |
| 80 |
*/ |
| 81 |
public function atRuleName(): string |
| 82 |
{ |
| 83 |
return 'namespace'; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* @return array{0: CSSString|URL|non-empty-string, 1?: CSSString|URL} |
| 88 |
*/ |
| 89 |
public function atRuleArgs(): array |
| 90 |
{ |
| 91 |
$result = [$this->url]; |
| 92 |
if (\is_string($this->prefix) && $this->prefix !== '') { |
| 93 |
\array_unshift($result, $this->prefix); |
| 94 |
} |
| 95 |
return $result; |
| 96 |
} |
| 97 |
} |
| 98 |
|