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\Property;
4
 
5
use Sabberworm\CSS\Comment\Comment;
6
use Sabberworm\CSS\OutputFormat;
7
use Sabberworm\CSS\Value\URL;
8
 
9
/**
10
 * Class representing an `@import` rule.
11
 */
12
class Import implements AtRule
13
{
14
    /**
15
     * @var URL
16
     */
17
    private $oLocation;
18
 
19
    /**
20
     * @var string
21
     */
22
    private $sMediaQuery;
23
 
24
    /**
25
     * @var int
26
     */
27
    protected $iLineNo;
28
 
29
    /**
30
     * @var array<array-key, Comment>
31
     */
32
    protected $aComments;
33
 
34
    /**
35
     * @param URL $oLocation
36
     * @param string $sMediaQuery
37
     * @param int $iLineNo
38
     */
39
    public function __construct(URL $oLocation, $sMediaQuery, $iLineNo = 0)
40
    {
41
        $this->oLocation = $oLocation;
42
        $this->sMediaQuery = $sMediaQuery;
43
        $this->iLineNo = $iLineNo;
44
        $this->aComments = [];
45
    }
46
 
47
    /**
48
     * @return int
49
     */
50
    public function getLineNo()
51
    {
52
        return $this->iLineNo;
53
    }
54
 
55
    /**
56
     * @param URL $oLocation
57
     *
58
     * @return void
59
     */
60
    public function setLocation($oLocation)
61
    {
62
        $this->oLocation = $oLocation;
63
    }
64
 
65
    /**
66
     * @return URL
67
     */
68
    public function getLocation()
69
    {
70
        return $this->oLocation;
71
    }
72
 
73
    /**
74
     * @return string
75
     */
76
    public function __toString()
77
    {
78
        return $this->render(new OutputFormat());
79
    }
80
 
81
    /**
82
     * @param OutputFormat|null $oOutputFormat
83
     *
84
     * @return string
85
     */
86
    public function render($oOutputFormat)
87
    {
88
        return $oOutputFormat->comments($this) . "@import " . $this->oLocation->render($oOutputFormat)
89
            . ($this->sMediaQuery === null ? '' : ' ' . $this->sMediaQuery) . ';';
90
    }
91
 
92
    /**
93
     * @return string
94
     */
95
    public function atRuleName()
96
    {
97
        return 'import';
98
    }
99
 
100
    /**
101
     * @return array<int, URL|string>
102
     */
103
    public function atRuleArgs()
104
    {
105
        $aResult = [$this->oLocation];
106
        if ($this->sMediaQuery) {
107
            array_push($aResult, $this->sMediaQuery);
108
        }
109
        return $aResult;
110
    }
111
 
112
    /**
113
     * @param array<array-key, Comment> $aComments
114
     *
115
     * @return void
116
     */
117
    public function addComments(array $aComments)
118
    {
119
        $this->aComments = array_merge($this->aComments, $aComments);
120
    }
121
 
122
    /**
123
     * @return array<array-key, Comment>
124
     */
125
    public function getComments()
126
    {
127
        return $this->aComments;
128
    }
129
 
130
    /**
131
     * @param array<array-key, Comment> $aComments
132
     *
133
     * @return void
134
     */
135
    public function setComments(array $aComments)
136
    {
137
        $this->aComments = $aComments;
138
    }
139
 
140
    /**
141
     * @return string
142
     */
143
    public function getMediaQuery()
144
    {
145
        return $this->sMediaQuery;
146
    }
147
}