| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sabberworm\CSS\Value; |
| 4 |
|
| 5 |
use Sabberworm\CSS\OutputFormat; |
| 6 |
|
| 7 |
/** |
| 8 |
* A `ValueList` represents a lists of `Value`s, separated by some separation character |
| 9 |
* (mostly `,`, whitespace, or `/`). |
| 10 |
* |
| 11 |
* There are two types of `ValueList`s: `RuleValueList` and `CSSFunction` |
| 12 |
*/ |
| 13 |
abstract class ValueList extends Value |
| 14 |
{ |
| 15 |
/** |
| 16 |
* @var array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> |
| 17 |
* |
| 18 |
* @internal since 8.8.0 |
| 19 |
*/ |
| 20 |
protected $aComponents; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var string |
| 24 |
* |
| 25 |
* @internal since 8.8.0 |
| 26 |
*/ |
| 27 |
protected $sSeparator; |
| 28 |
|
| 29 |
/** |
| 30 |
* phpcs:ignore Generic.Files.LineLength |
| 31 |
* @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>|RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $aComponents |
| 32 |
* @param string $sSeparator |
| 33 |
* @param int $iLineNo |
| 34 |
*/ |
| 35 |
public function __construct($aComponents = [], $sSeparator = ',', $iLineNo = 0) |
| 36 |
{ |
| 37 |
parent::__construct($iLineNo); |
| 38 |
if (!is_array($aComponents)) { |
| 39 |
$aComponents = [$aComponents]; |
| 40 |
} |
| 41 |
$this->aComponents = $aComponents; |
| 42 |
$this->sSeparator = $sSeparator; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @param RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $mComponent |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function addListComponent($mComponent) |
| 51 |
{ |
| 52 |
$this->aComponents[] = $mComponent; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> |
| 57 |
*/ |
| 58 |
public function getListComponents() |
| 59 |
{ |
| 60 |
return $this->aComponents; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function setListComponents(array $aComponents) |
| 69 |
{ |
| 70 |
$this->aComponents = $aComponents; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* @return string |
| 75 |
*/ |
| 76 |
public function getListSeparator() |
| 77 |
{ |
| 78 |
return $this->sSeparator; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* @param string $sSeparator |
| 83 |
* |
| 84 |
* @return void |
| 85 |
*/ |
| 86 |
public function setListSeparator($sSeparator) |
| 87 |
{ |
| 88 |
$this->sSeparator = $sSeparator; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* @return string |
| 93 |
* |
| 94 |
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. |
| 95 |
*/ |
| 96 |
public function __toString() |
| 97 |
{ |
| 98 |
return $this->render(new OutputFormat()); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* @param OutputFormat|null $oOutputFormat |
| 103 |
* |
| 104 |
* @return string |
| 105 |
*/ |
| 106 |
public function render($oOutputFormat) |
| 107 |
{ |
| 108 |
return $oOutputFormat->implode( |
| 109 |
$oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator |
| 110 |
. $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator), |
| 111 |
$this->aComponents |
| 112 |
); |
| 113 |
} |
| 114 |
} |
| 115 |
|