-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathValueList.php
More file actions
96 lines (83 loc) · 2.18 KB
/
Copy pathValueList.php
File metadata and controls
96 lines (83 loc) · 2.18 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
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\Value;
use Sabberworm\CSS\OutputFormat;
/**
* A `ValueList` represents a lists of `Value`s, separated by some separation character
* (mostly `,`, whitespace, or `/`).
*
* There are two types of `ValueList`s: `RuleValueList` and `CSSFunction`
*/
abstract class ValueList extends Value
{
/**
* @var array<Value|string>
*
* @internal since 8.8.0
*/
protected $components;
/**
* @var non-empty-string
*
* @internal since 8.8.0
*/
protected $separator;
/**
* @param array<Value|string>|Value|string $components
* @param non-empty-string $separator
* @param int<1, max>|null $lineNumber
*/
public function __construct($components = [], $separator = ',', ?int $lineNumber = null)
{
parent::__construct($lineNumber);
if (!\is_array($components)) {
$components = [$components];
}
$this->components = $components;
$this->separator = $separator;
}
/**
* @param Value|string $component
*/
public function addListComponent($component): void
{
$this->components[] = $component;
}
/**
* @return array<Value|string>
*/
public function getListComponents(): array
{
return $this->components;
}
/**
* @param array<Value|string> $components
*/
public function setListComponents(array $components): void
{
$this->components = $components;
}
/**
* @return non-empty-string
*/
public function getListSeparator(): string
{
return $this->separator;
}
/**
* @param non-empty-string $separator
*/
public function setListSeparator(string $separator): void
{
$this->separator = $separator;
}
public function render(OutputFormat $outputFormat): string
{
$formatter = $outputFormat->getFormatter();
return $formatter->implode(
$formatter->spaceBeforeListArgumentSeparator($this->separator) . $this->separator
. $formatter->spaceAfterListArgumentSeparator($this->separator),
$this->components
);
}
}