-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathCSSNamespace.php
More file actions
114 lines (99 loc) · 2.46 KB
/
Copy pathCSSNamespace.php
File metadata and controls
114 lines (99 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\Property;
use Sabberworm\CSS\Comment\CommentContainer;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Position\Position;
use Sabberworm\CSS\Position\Positionable;
use Sabberworm\CSS\ShortClassNameProvider;
use Sabberworm\CSS\Value\CSSString;
use Sabberworm\CSS\Value\URL;
/**
* `CSSNamespace` represents an `@namespace` rule.
*/
class CSSNamespace implements AtRule, Positionable
{
use CommentContainer;
use Position;
use ShortClassNameProvider;
/**
* @var CSSString|URL
*/
private $url;
/**
* @var string|null
*/
private $prefix;
/**
* @param CSSString|URL $url
* @param int<1, max>|null $lineNumber
*/
public function __construct($url, ?string $prefix = null, ?int $lineNumber = null)
{
$this->url = $url;
$this->prefix = $prefix;
$this->setPosition($lineNumber);
}
/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return '@namespace ' . ($this->prefix === null ? '' : $this->prefix . ' ')
. $this->url->render($outputFormat) . ';';
}
/**
* @return CSSString|URL
*/
public function getUrl()
{
return $this->url;
}
public function getPrefix(): ?string
{
return $this->prefix;
}
/**
* @param CSSString|URL $url
*/
public function setUrl($url): void
{
$this->url = $url;
}
public function setPrefix(string $prefix): void
{
$this->prefix = $prefix;
}
/**
* @return non-empty-string
*/
public function atRuleName(): string
{
return 'namespace';
}
/**
* @return array{0: CSSString|URL|non-empty-string, 1?: CSSString|URL}
*/
public function atRuleArgs(): array
{
$result = [$this->url];
if (\is_string($this->prefix) && $this->prefix !== '') {
\array_unshift($result, $this->prefix);
}
return $result;
}
/**
* @return array<string, bool|int|float|string|array<mixed>|null>
*
* @internal
*/
public function getArrayRepresentation(): array
{
return [
'class' => $this->getShortClassName(),
// We're using `uri` here instead of `url` to better match the spec.
'uri' => $this->url->getArrayRepresentation(),
'prefix' => $this->prefix,
];
}
}