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
use Sabberworm\CSS\Parsing\SourceException;
8
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
9
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
10
 
11
/**
12
 * This class represents URLs in CSS. `URL`s always output in `URL("")` notation.
13
 */
14
class URL extends PrimitiveValue
15
{
16
    /**
17
     * @var CSSString
18
     */
19
    private $oURL;
20
 
21
    /**
22
     * @param int $iLineNo
23
     */
24
    public function __construct(CSSString $oURL, $iLineNo = 0)
25
    {
26
        parent::__construct($iLineNo);
27
        $this->oURL = $oURL;
28
    }
29
 
30
    /**
31
     * @return URL
32
     *
33
     * @throws SourceException
34
     * @throws UnexpectedEOFException
35
     * @throws UnexpectedTokenException
36
     */
37
    public static function parse(ParserState $oParserState)
38
    {
39
        $oAnchor = $oParserState->anchor();
40
        $sIdentifier = '';
41
        for ($i = 0; $i < 3; $i++) {
42
            $sChar = $oParserState->parseCharacter(true);
43
            if ($sChar === null) {
44
                break;
45
            }
46
            $sIdentifier .= $sChar;
47
        }
48
        $bUseUrl = $oParserState->streql($sIdentifier, 'url');
49
        if ($bUseUrl) {
50
            $oParserState->consumeWhiteSpace();
51
            $oParserState->consume('(');
52
        } else {
53
            $oAnchor->backtrack();
54
        }
55
        $oParserState->consumeWhiteSpace();
56
        $oResult = new URL(CSSString::parse($oParserState), $oParserState->currentLine());
57
        if ($bUseUrl) {
58
            $oParserState->consumeWhiteSpace();
59
            $oParserState->consume(')');
60
        }
61
        return $oResult;
62
    }
63
 
64
    /**
65
     * @return void
66
     */
67
    public function setURL(CSSString $oURL)
68
    {
69
        $this->oURL = $oURL;
70
    }
71
 
72
    /**
73
     * @return CSSString
74
     */
75
    public function getURL()
76
    {
77
        return $this->oURL;
78
    }
79
 
80
    /**
81
     * @return string
82
     */
83
    public function __toString()
84
    {
85
        return $this->render(new OutputFormat());
86
    }
87
 
88
    /**
89
     * @param OutputFormat|null $oOutputFormat
90
     *
91
     * @return string
92
     */
93
    public function render($oOutputFormat)
94
    {
95
        return "url({$this->oURL->render($oOutputFormat)})";
96
    }
97
}