| 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\UnexpectedEOFException; |
| 8 |
use Sabberworm\CSS\Parsing\UnexpectedTokenException; |
| 9 |
|
| 10 |
class LineName extends ValueList |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents |
| 14 |
* @param int $iLineNo |
| 15 |
*/ |
| 16 |
public function __construct(array $aComponents = [], $iLineNo = 0) |
| 17 |
{ |
| 18 |
parent::__construct($aComponents, ' ', $iLineNo); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* @return LineName |
| 23 |
* |
| 24 |
* @throws UnexpectedTokenException |
| 25 |
* @throws UnexpectedEOFException |
| 26 |
* |
| 27 |
* @internal since V8.8.0 |
| 28 |
*/ |
| 29 |
public static function parse(ParserState $oParserState) |
| 30 |
{ |
| 31 |
$oParserState->consume('['); |
| 32 |
$oParserState->consumeWhiteSpace(); |
| 33 |
$aNames = []; |
| 34 |
do { |
| 35 |
if ($oParserState->getSettings()->bLenientParsing) { |
| 36 |
try { |
| 37 |
$aNames[] = $oParserState->parseIdentifier(); |
| 38 |
} catch (UnexpectedTokenException $e) { |
| 39 |
if (!$oParserState->comes(']')) { |
| 40 |
throw $e; |
| 41 |
} |
| 42 |
} |
| 43 |
} else { |
| 44 |
$aNames[] = $oParserState->parseIdentifier(); |
| 45 |
} |
| 46 |
$oParserState->consumeWhiteSpace(); |
| 47 |
} while (!$oParserState->comes(']')); |
| 48 |
$oParserState->consume(']'); |
| 49 |
return new LineName($aNames, $oParserState->currentLine()); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* @return string |
| 54 |
* |
| 55 |
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. |
| 56 |
*/ |
| 57 |
public function __toString() |
| 58 |
{ |
| 59 |
return $this->render(new OutputFormat()); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* @param OutputFormat|null $oOutputFormat |
| 64 |
* |
| 65 |
* @return string |
| 66 |
*/ |
| 67 |
public function render($oOutputFormat) |
| 68 |
{ |
| 69 |
return '[' . parent::render(OutputFormat::createCompact()) . ']'; |
| 70 |
} |
| 71 |
} |
| 72 |
|