-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathImport.php
More file actions
102 lines (87 loc) · 2.33 KB
/
Copy pathImport.php
File metadata and controls
102 lines (87 loc) · 2.33 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
<?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\URL;
/**
* Class representing an `@import` rule.
*/
class Import implements AtRule, Positionable
{
use CommentContainer;
use Position;
use ShortClassNameProvider;
/**
* @var URL
*/
private $location;
/**
* @var string|null
*/
private $mediaQuery;
/**
* @param int<1, max>|null $lineNumber
*/
public function __construct(URL $location, ?string $mediaQuery, ?int $lineNumber = null)
{
$this->location = $location;
$this->mediaQuery = $mediaQuery;
$this->setPosition($lineNumber);
}
public function setLocation(URL $location): void
{
$this->location = $location;
}
public function getLocation(): URL
{
return $this->location;
}
/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return $outputFormat->getFormatter()->comments($this) . '@import ' . $this->location->render($outputFormat)
. ($this->mediaQuery === null ? '' : ' ' . $this->mediaQuery) . ';';
}
/**
* @return non-empty-string
*/
public function atRuleName(): string
{
return 'import';
}
/**
* @return array{0: URL, 1?: non-empty-string}
*/
public function atRuleArgs(): array
{
$result = [$this->location];
if (\is_string($this->mediaQuery) && $this->mediaQuery !== '') {
$result[] = $this->mediaQuery;
}
return $result;
}
public function getMediaQuery(): ?string
{
return $this->mediaQuery;
}
/**
* @return array<string, bool|int|float|string|array<mixed>|null>
*
* @internal
*/
public function getArrayRepresentation(): array
{
return [
'class' => $this->getShortClassName(),
// We're using the term "uri" here to match the wording used in the specs:
// https://www.w3.org/TR/CSS22/cascade.html#at-import
'uri' => $this->location->getArrayRepresentation(),
];
}
}