PluginProbe
WooCommerce / 11.0.0
WooCommerce v11.0.0
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / lib / packages / Sabberworm / CSS / Value / URL.php
URL.php
102 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Automattic\WooCommerce\Vendor\Sabberworm\CSS\Value;
4
5 use Automattic\WooCommerce\Vendor\Sabberworm\CSS\OutputFormat;
6 use Automattic\WooCommerce\Vendor\Sabberworm\CSS\Parsing\ParserState;
7 use Automattic\WooCommerce\Vendor\Sabberworm\CSS\Parsing\SourceException;
8 use Automattic\WooCommerce\Vendor\Sabberworm\CSS\Parsing\UnexpectedEOFException;
9 use Automattic\WooCommerce\Vendor\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 * @internal since V8.8.0
38 */
39 public static function parse(ParserState $oParserState)
40 {
41 $oAnchor = $oParserState->anchor();
42 $sIdentifier = '';
43 for ($i = 0; $i < 3; $i++) {
44 $sChar = $oParserState->parseCharacter(true);
45 if ($sChar === null) {
46 break;
47 }
48 $sIdentifier .= $sChar;
49 }
50 $bUseUrl = $oParserState->streql($sIdentifier, 'url');
51 if ($bUseUrl) {
52 $oParserState->consumeWhiteSpace();
53 $oParserState->consume('(');
54 } else {
55 $oAnchor->backtrack();
56 }
57 $oParserState->consumeWhiteSpace();
58 $oResult = new URL(CSSString::parse($oParserState), $oParserState->currentLine());
59 if ($bUseUrl) {
60 $oParserState->consumeWhiteSpace();
61 $oParserState->consume(')');
62 }
63 return $oResult;
64 }
65
66 /**
67 * @return void
68 */
69 public function setURL(CSSString $oURL)
70 {
71 $this->oURL = $oURL;
72 }
73
74 /**
75 * @return CSSString
76 */
77 public function getURL()
78 {
79 return $this->oURL;
80 }
81
82 /**
83 * @return string
84 *
85 * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
86 */
87 public function __toString()
88 {
89 return $this->render(new OutputFormat());
90 }
91
92 /**
93 * @param OutputFormat|null $oOutputFormat
94 *
95 * @return string
96 */
97 public function render($oOutputFormat)
98 {
99 return "url({$this->oURL->render($oOutputFormat)})";
100 }
101 }
102