PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Libraries / Sabberworm / CSS / src / Value / URL.php

URL.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.1, at back/Libraries/Sabberworm/CSS/src/Value/URL.php

84 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AcyMailing\Libraries\Sabberworm\CSS\Value;
6
7 use AcyMailing\Libraries\Sabberworm\CSS\OutputFormat;
8 use AcyMailing\Libraries\Sabberworm\CSS\Parsing\ParserState;
9 use AcyMailing\Libraries\Sabberworm\CSS\Parsing\SourceException;
10 use AcyMailing\Libraries\Sabberworm\CSS\Parsing\UnexpectedEOFException;
11 use AcyMailing\Libraries\Sabberworm\CSS\Parsing\UnexpectedTokenException;
12
13 /**
14 * This class represents URLs in CSS. `URL`s always output in `URL("")` notation.
15 */
16 class URL extends PrimitiveValue
17 {
18 /**
19 * @var CSSString
20 */
21 private $url;
22
23 /**
24 * @param int<1, max>|null $lineNumber
25 */
26 public function __construct(CSSString $url, ?int $lineNumber = null)
27 {
28 parent::__construct($lineNumber);
29 $this->url = $url;
30 }
31
32 /**
33 * @throws SourceException
34 * @throws UnexpectedEOFException
35 * @throws UnexpectedTokenException
36 *
37 * @internal since V8.8.0
38 */
39 public static function parse(ParserState $parserState): URL
40 {
41 $anchor = $parserState->anchor();
42 $identifier = '';
43 for ($i = 0; $i < 3; $i++) {
44 $character = $parserState->parseCharacter(true);
45 if ($character === null) {
46 break;
47 }
48 $identifier .= $character;
49 }
50 $useUrl = $parserState->streql($identifier, 'url');
51 if ($useUrl) {
52 $parserState->consumeWhiteSpace();
53 $parserState->consume('(');
54 } else {
55 $anchor->backtrack();
56 }
57 $parserState->consumeWhiteSpace();
58 $result = new URL(CSSString::parse($parserState), $parserState->currentLine());
59 if ($useUrl) {
60 $parserState->consumeWhiteSpace();
61 $parserState->consume(')');
62 }
63 return $result;
64 }
65
66 public function setURL(CSSString $url): void
67 {
68 $this->url = $url;
69 }
70
71 public function getURL(): CSSString
72 {
73 return $this->url;
74 }
75
76 /**
77 * @return non-empty-string
78 */
79 public function render(OutputFormat $outputFormat): string
80 {
81 return "url({$this->url->render($outputFormat)})";
82 }
83 }
84