Debian Codegraph @

vendor/wikimedia/css-sanitizer/src/Objects/TokenList.php

raw
1 <?php
2 /**
3 * @file
4 * @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
5 */
6
7 namespace Wikimedia\CSS\Objects;
8
9 use Wikimedia\CSS\Exception\ParseException;
10 use Wikimedia\CSS\Parser\Parser;
11
12 /**
13 * Represent a list of CSS tokens
14 * @extends CSSObjectList<Token>
15 */
16 class TokenList extends CSSObjectList {
17 /**
18 * @var string
19 */
20 protected static $objectType = Token::class;
21
22 /** @var Token[] The objects contained */
23 protected $objects;
24
25 /** @inheritDoc */
26 public function toTokenArray() {
27 // We can greatly simplify this, assuming no separator
28 return $this->objects;
29 }
30
31 /** @inheritDoc */
32 public function toComponentValueArray() {
33 // This one, though, is complicated
34 $parser = Parser::newFromTokens( $this->objects );
35 $ret = $parser->parseComponentValueList();
36 if ( $parser->getParseErrors() ) {
37 $ex = new ParseException( 'TokenList cannot be converted to a ComponentValueList' );
38 $ex->parseErrors = $parser->getParseErrors();
39 throw $ex;
40 }
41 return $ret->toComponentValueArray();
42 }
43 }