CSSFunction.php
2 years ago
CSSString.php
4 years ago
CalcFunction.php
2 years ago
CalcRuleValueList.php
4 years ago
Color.php
2 years ago
LineName.php
4 years ago
PrimitiveValue.php
4 years ago
RuleValueList.php
4 years ago
Size.php
2 years ago
URL.php
2 years ago
Value.php
2 years ago
ValueList.php
4 years ago
index.php
3 years ago
URL.php
60 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Sabberworm\CSS\Value; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Sabberworm\CSS\OutputFormat; |
| 5 | use MailPoetVendor\Sabberworm\CSS\Parsing\ParserState; |
| 6 | use MailPoetVendor\Sabberworm\CSS\Parsing\SourceException; |
| 7 | use MailPoetVendor\Sabberworm\CSS\Parsing\UnexpectedEOFException; |
| 8 | use MailPoetVendor\Sabberworm\CSS\Parsing\UnexpectedTokenException; |
| 9 | class URL extends PrimitiveValue |
| 10 | { |
| 11 | private $oURL; |
| 12 | public function __construct(CSSString $oURL, $iLineNo = 0) |
| 13 | { |
| 14 | parent::__construct($iLineNo); |
| 15 | $this->oURL = $oURL; |
| 16 | } |
| 17 | public static function parse(ParserState $oParserState) |
| 18 | { |
| 19 | $oAnchor = $oParserState->anchor(); |
| 20 | $sIdentifier = ''; |
| 21 | for ($i = 0; $i < 3; $i++) { |
| 22 | $sChar = $oParserState->parseCharacter(\true); |
| 23 | if ($sChar === null) { |
| 24 | break; |
| 25 | } |
| 26 | $sIdentifier .= $sChar; |
| 27 | } |
| 28 | $bUseUrl = $oParserState->streql($sIdentifier, 'url'); |
| 29 | if ($bUseUrl) { |
| 30 | $oParserState->consumeWhiteSpace(); |
| 31 | $oParserState->consume('('); |
| 32 | } else { |
| 33 | $oAnchor->backtrack(); |
| 34 | } |
| 35 | $oParserState->consumeWhiteSpace(); |
| 36 | $oResult = new URL(CSSString::parse($oParserState), $oParserState->currentLine()); |
| 37 | if ($bUseUrl) { |
| 38 | $oParserState->consumeWhiteSpace(); |
| 39 | $oParserState->consume(')'); |
| 40 | } |
| 41 | return $oResult; |
| 42 | } |
| 43 | public function setURL(CSSString $oURL) |
| 44 | { |
| 45 | $this->oURL = $oURL; |
| 46 | } |
| 47 | public function getURL() |
| 48 | { |
| 49 | return $this->oURL; |
| 50 | } |
| 51 | public function __toString() |
| 52 | { |
| 53 | return $this->render(new OutputFormat()); |
| 54 | } |
| 55 | public function render(OutputFormat $oOutputFormat) |
| 56 | { |
| 57 | return "url({$this->oURL->render($oOutputFormat)})"; |
| 58 | } |
| 59 | } |
| 60 |