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
use Sabberworm\CSS\Parsing\ParserState;
7
 
8
/**
9
 * A `CSSFunction` represents a special kind of value that also contains a function name and where the values are the
10
 * function’s arguments. It also handles equals-sign-separated argument lists like `filter: alpha(opacity=90);`.
11
 */
12
class CSSFunction extends ValueList
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $sName;
18
 
19
    /**
20
     * @param string $sName
21
     * @param RuleValueList|array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aArguments
22
     * @param string $sSeparator
23
     * @param int $iLineNo
24
     */
25
    public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0)
26
    {
27
        if ($aArguments instanceof RuleValueList) {
28
            $sSeparator = $aArguments->getListSeparator();
29
            $aArguments = $aArguments->getListComponents();
30
        }
31
        $this->sName = $sName;
32
        $this->iLineNo = $iLineNo;
33
        parent::__construct($aArguments, $sSeparator, $iLineNo);
34
    }
35
 
36
    /**
37
     * @param ParserState $oParserState
38
     * @param bool $bIgnoreCase
39
     *
40
     * @return CSSFunction
41
     *
42
     * @throws SourceException
43
     * @throws UnexpectedEOFException
44
     * @throws UnexpectedTokenException
45
     */
46
    public static function parse(ParserState $oParserState, $bIgnoreCase = false)
47
    {
48
        $mResult = $oParserState->parseIdentifier($bIgnoreCase);
49
        $oParserState->consume('(');
50
        $aArguments = Value::parseValue($oParserState, ['=', ' ', ',']);
51
        $mResult = new CSSFunction($mResult, $aArguments, ',', $oParserState->currentLine());
52
        $oParserState->consume(')');
53
        return $mResult;
54
    }
55
 
56
    /**
57
     * @return string
58
     */
59
    public function getName()
60
    {
61
        return $this->sName;
62
    }
63
 
64
    /**
65
     * @param string $sName
66
     *
67
     * @return void
68
     */
69
    public function setName($sName)
70
    {
71
        $this->sName = $sName;
72
    }
73
 
74
    /**
75
     * @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>
76
     */
77
    public function getArguments()
78
    {
79
        return $this->aComponents;
80
    }
81
 
82
    /**
83
     * @return string
84
     */
85
    public function __toString()
86
    {
87
        return $this->render(new OutputFormat());
88
    }
89
 
90
    /**
91
     * @param OutputFormat|null $oOutputFormat
92
     *
93
     * @return string
94
     */
95
    public function render($oOutputFormat)
96
    {
97
        $aArguments = parent::render($oOutputFormat);
98
        return "{$this->sName}({$aArguments})";
99
    }
100
}