Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
    protected $aComponents;
19
 
20
    /**
21
     * @var string
22
     */
23
    protected $sSeparator;
24
 
25
    /**
26
     * phpcs:ignore Generic.Files.LineLength
27
     * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>|RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $aComponents
28
     * @param string $sSeparator
29
     * @param int $iLineNo
30
     */
31
    public function __construct($aComponents = [], $sSeparator = ',', $iLineNo = 0)
32
    {
33
        parent::__construct($iLineNo);
34
        if (!is_array($aComponents)) {
35
            $aComponents = [$aComponents];
36
        }
37
        $this->aComponents = $aComponents;
38
        $this->sSeparator = $sSeparator;
39
    }
40
 
41
    /**
42
     * @param RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $mComponent
43
     *
44
     * @return void
45
     */
46
    public function addListComponent($mComponent)
47
    {
48
        $this->aComponents[] = $mComponent;
49
    }
50
 
51
    /**
52
     * @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>
53
     */
54
    public function getListComponents()
55
    {
56
        return $this->aComponents;
57
    }
58
 
59
    /**
60
     * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents
61
     *
62
     * @return void
63
     */
64
    public function setListComponents(array $aComponents)
65
    {
66
        $this->aComponents = $aComponents;
67
    }
68
 
69
    /**
70
     * @return string
71
     */
72
    public function getListSeparator()
73
    {
74
        return $this->sSeparator;
75
    }
76
 
77
    /**
78
     * @param string $sSeparator
79
     *
80
     * @return void
81
     */
82
    public function setListSeparator($sSeparator)
83
    {
84
        $this->sSeparator = $sSeparator;
85
    }
86
 
87
    /**
88
     * @return string
89
     */
90
    public function __toString()
91
    {
92
        return $this->render(new OutputFormat());
93
    }
94
 
95
    /**
96
     * @param OutputFormat|null $oOutputFormat
97
     *
98
     * @return string
99
     */
100
    public function render($oOutputFormat)
101
    {
102
        return $oOutputFormat->implode(
103
            $oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator
104
            . $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator),
105
            $this->aComponents
106
        );
107
    }
108
}