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