recreate project
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\OutputFormat;
|
||||
use Sabberworm\CSS\Parsing\ParserState;
|
||||
use Sabberworm\CSS\Parsing\SourceException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
|
||||
|
||||
/**
|
||||
* A `CSSFunction` represents a special kind of value that also contains a function name and where the values are the
|
||||
* function’s arguments. It also handles equals-sign-separated argument lists like `filter: alpha(opacity=90);`.
|
||||
*/
|
||||
class CSSFunction extends ValueList
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @internal since 8.8.0
|
||||
*/
|
||||
protected $sName;
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param RuleValueList|array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aArguments
|
||||
* @param string $sSeparator
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0)
|
||||
{
|
||||
if ($aArguments instanceof RuleValueList) {
|
||||
$sSeparator = $aArguments->getListSeparator();
|
||||
$aArguments = $aArguments->getListComponents();
|
||||
}
|
||||
$this->sName = $sName;
|
||||
$this->setPosition($iLineNo); // TODO: redundant?
|
||||
parent::__construct($aArguments, $sSeparator, $iLineNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ParserState $oParserState
|
||||
* @param bool $bIgnoreCase
|
||||
*
|
||||
* @return CSSFunction
|
||||
*
|
||||
* @throws SourceException
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parse(ParserState $oParserState, $bIgnoreCase = false)
|
||||
{
|
||||
$mResult = $oParserState->parseIdentifier($bIgnoreCase);
|
||||
$oParserState->consume('(');
|
||||
$aArguments = Value::parseValue($oParserState, ['=', ' ', ',']);
|
||||
$mResult = new CSSFunction($mResult, $aArguments, ',', $oParserState->currentLine());
|
||||
$oParserState->consume(')');
|
||||
return $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setName($sName)
|
||||
{
|
||||
$this->sName = $sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->aComponents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render(new OutputFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat|null $oOutputFormat
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($oOutputFormat)
|
||||
{
|
||||
$aArguments = parent::render($oOutputFormat);
|
||||
return "{$this->sName}({$aArguments})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\OutputFormat;
|
||||
use Sabberworm\CSS\Parsing\ParserState;
|
||||
use Sabberworm\CSS\Parsing\SourceException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
|
||||
|
||||
/**
|
||||
* This class is a wrapper for quoted strings to distinguish them from keywords.
|
||||
*
|
||||
* `CSSString`s always output with double quotes.
|
||||
*/
|
||||
class CSSString extends PrimitiveValue
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sString;
|
||||
|
||||
/**
|
||||
* @param string $sString
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct($sString, $iLineNo = 0)
|
||||
{
|
||||
$this->sString = $sString;
|
||||
parent::__construct($iLineNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CSSString
|
||||
*
|
||||
* @throws SourceException
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parse(ParserState $oParserState)
|
||||
{
|
||||
$sBegin = $oParserState->peek();
|
||||
$sQuote = null;
|
||||
if ($sBegin === "'") {
|
||||
$sQuote = "'";
|
||||
} elseif ($sBegin === '"') {
|
||||
$sQuote = '"';
|
||||
}
|
||||
if ($sQuote !== null) {
|
||||
$oParserState->consume($sQuote);
|
||||
}
|
||||
$sResult = "";
|
||||
$sContent = null;
|
||||
if ($sQuote === null) {
|
||||
// Unquoted strings end in whitespace or with braces, brackets, parentheses
|
||||
while (!preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) {
|
||||
$sResult .= $oParserState->parseCharacter(false);
|
||||
}
|
||||
} else {
|
||||
while (!$oParserState->comes($sQuote)) {
|
||||
$sContent = $oParserState->parseCharacter(false);
|
||||
if ($sContent === null) {
|
||||
throw new SourceException(
|
||||
"Non-well-formed quoted string {$oParserState->peek(3)}",
|
||||
$oParserState->currentLine()
|
||||
);
|
||||
}
|
||||
$sResult .= $sContent;
|
||||
}
|
||||
$oParserState->consume($sQuote);
|
||||
}
|
||||
return new CSSString($sResult, $oParserState->currentLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sString
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setString($sString)
|
||||
{
|
||||
$this->sString = $sString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getString()
|
||||
{
|
||||
return $this->sString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render(new OutputFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat|null $oOutputFormat
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($oOutputFormat)
|
||||
{
|
||||
$sString = addslashes($this->sString);
|
||||
$sString = str_replace("\n", '\A', $sString);
|
||||
return $oOutputFormat->getStringQuotingType() . $sString . $oOutputFormat->getStringQuotingType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\Parsing\ParserState;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
|
||||
|
||||
/**
|
||||
* Support for `-webkit-calc` and `-moz-calc` is deprecated in version 8.8.0, and will be removed in version 9.0.0.
|
||||
*/
|
||||
class CalcFunction extends CSSFunction
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
const T_OPERAND = 1;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
const T_OPERATOR = 2;
|
||||
|
||||
/**
|
||||
* @param ParserState $oParserState
|
||||
* @param bool $bIgnoreCase
|
||||
*
|
||||
* @return CalcFunction
|
||||
*
|
||||
* @throws UnexpectedTokenException
|
||||
* @throws UnexpectedEOFException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parse(ParserState $oParserState, $bIgnoreCase = false)
|
||||
{
|
||||
$aOperators = ['+', '-', '*', '/'];
|
||||
$sFunction = $oParserState->parseIdentifier();
|
||||
if ($oParserState->peek() != '(') {
|
||||
// Found ; or end of line before an opening bracket
|
||||
throw new UnexpectedTokenException('(', $oParserState->peek(), 'literal', $oParserState->currentLine());
|
||||
} elseif (!in_array($sFunction, ['calc', '-moz-calc', '-webkit-calc'])) {
|
||||
// Found invalid calc definition. Example calc (...
|
||||
throw new UnexpectedTokenException('calc', $sFunction, 'literal', $oParserState->currentLine());
|
||||
}
|
||||
$oParserState->consume('(');
|
||||
$oCalcList = new CalcRuleValueList($oParserState->currentLine());
|
||||
$oList = new RuleValueList(',', $oParserState->currentLine());
|
||||
$iNestingLevel = 0;
|
||||
$iLastComponentType = null;
|
||||
while (!$oParserState->comes(')') || $iNestingLevel > 0) {
|
||||
if ($oParserState->isEnd() && $iNestingLevel === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$oParserState->consumeWhiteSpace();
|
||||
if ($oParserState->comes('(')) {
|
||||
$iNestingLevel++;
|
||||
$oCalcList->addListComponent($oParserState->consume(1));
|
||||
$oParserState->consumeWhiteSpace();
|
||||
continue;
|
||||
} elseif ($oParserState->comes(')')) {
|
||||
$iNestingLevel--;
|
||||
$oCalcList->addListComponent($oParserState->consume(1));
|
||||
$oParserState->consumeWhiteSpace();
|
||||
continue;
|
||||
}
|
||||
if ($iLastComponentType != CalcFunction::T_OPERAND) {
|
||||
$oVal = Value::parsePrimitiveValue($oParserState);
|
||||
$oCalcList->addListComponent($oVal);
|
||||
$iLastComponentType = CalcFunction::T_OPERAND;
|
||||
} else {
|
||||
if (in_array($oParserState->peek(), $aOperators)) {
|
||||
if (($oParserState->comes('-') || $oParserState->comes('+'))) {
|
||||
if (
|
||||
$oParserState->peek(1, -1) != ' '
|
||||
|| !($oParserState->comes('- ')
|
||||
|| $oParserState->comes('+ '))
|
||||
) {
|
||||
throw new UnexpectedTokenException(
|
||||
" {$oParserState->peek()} ",
|
||||
$oParserState->peek(1, -1) . $oParserState->peek(2),
|
||||
'literal',
|
||||
$oParserState->currentLine()
|
||||
);
|
||||
}
|
||||
}
|
||||
$oCalcList->addListComponent($oParserState->consume(1));
|
||||
$iLastComponentType = CalcFunction::T_OPERATOR;
|
||||
} else {
|
||||
throw new UnexpectedTokenException(
|
||||
sprintf(
|
||||
'Next token was expected to be an operand of type %s. Instead "%s" was found.',
|
||||
implode(', ', $aOperators),
|
||||
$oParserState->peek()
|
||||
),
|
||||
'',
|
||||
'custom',
|
||||
$oParserState->currentLine()
|
||||
);
|
||||
}
|
||||
}
|
||||
$oParserState->consumeWhiteSpace();
|
||||
}
|
||||
$oList->addListComponent($oCalcList);
|
||||
if (!$oParserState->isEnd()) {
|
||||
$oParserState->consume(')');
|
||||
}
|
||||
return new CalcFunction($sFunction, $oList, ',', $oParserState->currentLine());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\OutputFormat;
|
||||
|
||||
class CalcRuleValueList extends RuleValueList
|
||||
{
|
||||
/**
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct($iLineNo = 0)
|
||||
{
|
||||
parent::__construct(',', $iLineNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat|null $oOutputFormat
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($oOutputFormat)
|
||||
{
|
||||
return $oOutputFormat->implode(' ', $this->aComponents);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\OutputFormat;
|
||||
use Sabberworm\CSS\Parsing\ParserState;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
|
||||
|
||||
/**
|
||||
* `Color's can be input in the form #rrggbb, #rgb or schema(val1, val2, …) but are always stored as an array of
|
||||
* ('s' => val1, 'c' => val2, 'h' => val3, …) and output in the second form.
|
||||
*/
|
||||
class Color extends CSSFunction
|
||||
{
|
||||
/**
|
||||
* @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aColor
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct(array $aColor, $iLineNo = 0)
|
||||
{
|
||||
parent::__construct(implode('', array_keys($aColor)), $aColor, ',', $iLineNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ParserState $oParserState
|
||||
* @param bool $bIgnoreCase
|
||||
*
|
||||
* @return Color|CSSFunction
|
||||
*
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parse(ParserState $oParserState, $bIgnoreCase = false)
|
||||
{
|
||||
$aColor = [];
|
||||
if ($oParserState->comes('#')) {
|
||||
$oParserState->consume('#');
|
||||
$sValue = $oParserState->parseIdentifier(false);
|
||||
if ($oParserState->strlen($sValue) === 3) {
|
||||
$sValue = $sValue[0] . $sValue[0] . $sValue[1] . $sValue[1] . $sValue[2] . $sValue[2];
|
||||
} elseif ($oParserState->strlen($sValue) === 4) {
|
||||
$sValue = $sValue[0] . $sValue[0] . $sValue[1] . $sValue[1] . $sValue[2] . $sValue[2] . $sValue[3]
|
||||
. $sValue[3];
|
||||
}
|
||||
|
||||
if ($oParserState->strlen($sValue) === 8) {
|
||||
$aColor = [
|
||||
'r' => new Size(intval($sValue[0] . $sValue[1], 16), null, true, $oParserState->currentLine()),
|
||||
'g' => new Size(intval($sValue[2] . $sValue[3], 16), null, true, $oParserState->currentLine()),
|
||||
'b' => new Size(intval($sValue[4] . $sValue[5], 16), null, true, $oParserState->currentLine()),
|
||||
'a' => new Size(
|
||||
round(self::mapRange(intval($sValue[6] . $sValue[7], 16), 0, 255, 0, 1), 2),
|
||||
null,
|
||||
true,
|
||||
$oParserState->currentLine()
|
||||
),
|
||||
];
|
||||
} elseif ($oParserState->strlen($sValue) === 6) {
|
||||
$aColor = [
|
||||
'r' => new Size(intval($sValue[0] . $sValue[1], 16), null, true, $oParserState->currentLine()),
|
||||
'g' => new Size(intval($sValue[2] . $sValue[3], 16), null, true, $oParserState->currentLine()),
|
||||
'b' => new Size(intval($sValue[4] . $sValue[5], 16), null, true, $oParserState->currentLine()),
|
||||
];
|
||||
} else {
|
||||
throw new UnexpectedTokenException(
|
||||
'Invalid hex color value',
|
||||
$sValue,
|
||||
'custom',
|
||||
$oParserState->currentLine()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$sColorMode = $oParserState->parseIdentifier(true);
|
||||
$oParserState->consumeWhiteSpace();
|
||||
$oParserState->consume('(');
|
||||
|
||||
$bContainsVar = false;
|
||||
$iLength = $oParserState->strlen($sColorMode);
|
||||
for ($i = 0; $i < $iLength; ++$i) {
|
||||
$oParserState->consumeWhiteSpace();
|
||||
if ($oParserState->comes('var')) {
|
||||
$aColor[$sColorMode[$i]] = CSSFunction::parseIdentifierOrFunction($oParserState);
|
||||
$bContainsVar = true;
|
||||
} else {
|
||||
$aColor[$sColorMode[$i]] = Size::parse($oParserState, true);
|
||||
}
|
||||
|
||||
if ($bContainsVar && $oParserState->comes(')')) {
|
||||
// With a var argument the function can have fewer arguments
|
||||
break;
|
||||
}
|
||||
|
||||
$oParserState->consumeWhiteSpace();
|
||||
if ($i < ($iLength - 1)) {
|
||||
$oParserState->consume(',');
|
||||
}
|
||||
}
|
||||
$oParserState->consume(')');
|
||||
|
||||
if ($bContainsVar) {
|
||||
return new CSSFunction($sColorMode, array_values($aColor), ',', $oParserState->currentLine());
|
||||
}
|
||||
}
|
||||
return new Color($aColor, $oParserState->currentLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $fVal
|
||||
* @param float $fFromMin
|
||||
* @param float $fFromMax
|
||||
* @param float $fToMin
|
||||
* @param float $fToMax
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
private static function mapRange($fVal, $fFromMin, $fFromMax, $fToMin, $fToMax)
|
||||
{
|
||||
$fFromRange = $fFromMax - $fFromMin;
|
||||
$fToRange = $fToMax - $fToMin;
|
||||
$fMultiplier = $fToRange / $fFromRange;
|
||||
$fNewVal = $fVal - $fFromMin;
|
||||
$fNewVal *= $fMultiplier;
|
||||
return $fNewVal + $fToMin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>
|
||||
*/
|
||||
public function getColor()
|
||||
{
|
||||
return $this->aComponents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aColor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setColor(array $aColor)
|
||||
{
|
||||
$this->setName(implode('', array_keys($aColor)));
|
||||
$this->aComponents = $aColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getColorDescription()
|
||||
{
|
||||
return $this->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render(new OutputFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat|null $oOutputFormat
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($oOutputFormat)
|
||||
{
|
||||
// Shorthand RGB color values
|
||||
if ($oOutputFormat->getRGBHashNotation() && implode('', array_keys($this->aComponents)) === 'rgb') {
|
||||
$sResult = sprintf(
|
||||
'%02x%02x%02x',
|
||||
$this->aComponents['r']->getSize(),
|
||||
$this->aComponents['g']->getSize(),
|
||||
$this->aComponents['b']->getSize()
|
||||
);
|
||||
return '#' . (($sResult[0] == $sResult[1]) && ($sResult[2] == $sResult[3]) && ($sResult[4] == $sResult[5])
|
||||
? "$sResult[0]$sResult[2]$sResult[4]" : $sResult);
|
||||
}
|
||||
return parent::render($oOutputFormat);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\OutputFormat;
|
||||
use Sabberworm\CSS\Parsing\ParserState;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
|
||||
|
||||
class LineName extends ValueList
|
||||
{
|
||||
/**
|
||||
* @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct(array $aComponents = [], $iLineNo = 0)
|
||||
{
|
||||
parent::__construct($aComponents, ' ', $iLineNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LineName
|
||||
*
|
||||
* @throws UnexpectedTokenException
|
||||
* @throws UnexpectedEOFException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parse(ParserState $oParserState)
|
||||
{
|
||||
$oParserState->consume('[');
|
||||
$oParserState->consumeWhiteSpace();
|
||||
$aNames = [];
|
||||
do {
|
||||
if ($oParserState->getSettings()->bLenientParsing) {
|
||||
try {
|
||||
$aNames[] = $oParserState->parseIdentifier();
|
||||
} catch (UnexpectedTokenException $e) {
|
||||
if (!$oParserState->comes(']')) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$aNames[] = $oParserState->parseIdentifier();
|
||||
}
|
||||
$oParserState->consumeWhiteSpace();
|
||||
} while (!$oParserState->comes(']'));
|
||||
$oParserState->consume(']');
|
||||
return new LineName($aNames, $oParserState->currentLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render(new OutputFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat|null $oOutputFormat
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($oOutputFormat)
|
||||
{
|
||||
return '[' . parent::render(OutputFormat::createCompact()) . ']';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
abstract class PrimitiveValue extends Value
|
||||
{
|
||||
/**
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct($iLineNo = 0)
|
||||
{
|
||||
parent::__construct($iLineNo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
/**
|
||||
* This class is used to represent all multivalued rules like `font: bold 12px/3 Helvetica, Verdana, sans-serif;`
|
||||
* (where the value would be a whitespace-separated list of the primitive value `bold`, a slash-separated list
|
||||
* and a comma-separated list).
|
||||
*/
|
||||
class RuleValueList extends ValueList
|
||||
{
|
||||
/**
|
||||
* @param string $sSeparator
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct($sSeparator = ',', $iLineNo = 0)
|
||||
{
|
||||
parent::__construct([], $sSeparator, $iLineNo);
|
||||
}
|
||||
}
|
||||
+247
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\OutputFormat;
|
||||
use Sabberworm\CSS\Parsing\ParserState;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
|
||||
|
||||
/**
|
||||
* A `Size` consists of a numeric `size` value and a unit.
|
||||
*/
|
||||
class Size extends PrimitiveValue
|
||||
{
|
||||
/**
|
||||
* vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport)
|
||||
*
|
||||
* @var array<int, string>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
const ABSOLUTE_SIZE_UNITS = [
|
||||
'px',
|
||||
'pt',
|
||||
'pc',
|
||||
'cm',
|
||||
'mm',
|
||||
'mozmm',
|
||||
'in',
|
||||
'vh',
|
||||
'dvh',
|
||||
'svh',
|
||||
'lvh',
|
||||
'vw',
|
||||
'vmin',
|
||||
'vmax',
|
||||
'rem',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<int, string>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr'];
|
||||
|
||||
/**
|
||||
* @var array<int, string>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz'];
|
||||
|
||||
/**
|
||||
* @var array<int, array<string, string>>|null
|
||||
*/
|
||||
private static $SIZE_UNITS = null;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $fSize;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $sUnit;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bIsColorComponent;
|
||||
|
||||
/**
|
||||
* @param float|int|string $fSize
|
||||
* @param string|null $sUnit
|
||||
* @param bool $bIsColorComponent
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0)
|
||||
{
|
||||
parent::__construct($iLineNo);
|
||||
$this->fSize = (float)$fSize;
|
||||
$this->sUnit = $sUnit;
|
||||
$this->bIsColorComponent = $bIsColorComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsColorComponent
|
||||
*
|
||||
* @return Size
|
||||
*
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parse(ParserState $oParserState, $bIsColorComponent = false)
|
||||
{
|
||||
$sSize = '';
|
||||
if ($oParserState->comes('-')) {
|
||||
$sSize .= $oParserState->consume('-');
|
||||
}
|
||||
while (is_numeric($oParserState->peek()) || $oParserState->comes('.') || $oParserState->comes('e', true)) {
|
||||
if ($oParserState->comes('.')) {
|
||||
$sSize .= $oParserState->consume('.');
|
||||
} elseif ($oParserState->comes('e', true)) {
|
||||
$sLookahead = $oParserState->peek(1, 1);
|
||||
if (is_numeric($sLookahead) || $sLookahead === '+' || $sLookahead === '-') {
|
||||
$sSize .= $oParserState->consume(2);
|
||||
} else {
|
||||
break; // Reached the unit part of the number like "em" or "ex"
|
||||
}
|
||||
} else {
|
||||
$sSize .= $oParserState->consume(1);
|
||||
}
|
||||
}
|
||||
|
||||
$sUnit = null;
|
||||
$aSizeUnits = self::getSizeUnits();
|
||||
foreach ($aSizeUnits as $iLength => &$aValues) {
|
||||
$sKey = strtolower($oParserState->peek($iLength));
|
||||
if (array_key_exists($sKey, $aValues)) {
|
||||
if (($sUnit = $aValues[$sKey]) !== null) {
|
||||
$oParserState->consume($iLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Size((float)$sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, string>>
|
||||
*/
|
||||
private static function getSizeUnits()
|
||||
{
|
||||
if (!is_array(self::$SIZE_UNITS)) {
|
||||
self::$SIZE_UNITS = [];
|
||||
foreach (array_merge(self::ABSOLUTE_SIZE_UNITS, self::RELATIVE_SIZE_UNITS, self::NON_SIZE_UNITS) as $val) {
|
||||
$iSize = strlen($val);
|
||||
if (!isset(self::$SIZE_UNITS[$iSize])) {
|
||||
self::$SIZE_UNITS[$iSize] = [];
|
||||
}
|
||||
self::$SIZE_UNITS[$iSize][strtolower($val)] = $val;
|
||||
}
|
||||
|
||||
krsort(self::$SIZE_UNITS, SORT_NUMERIC);
|
||||
}
|
||||
|
||||
return self::$SIZE_UNITS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sUnit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUnit($sUnit)
|
||||
{
|
||||
$this->sUnit = $sUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUnit()
|
||||
{
|
||||
return $this->sUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float|int|string $fSize
|
||||
*/
|
||||
public function setSize($fSize)
|
||||
{
|
||||
$this->fSize = (float)$fSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
return $this->fSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isColorComponent()
|
||||
{
|
||||
return $this->bIsColorComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the number stored in this Size really represents a size (as in a length of something on screen).
|
||||
*
|
||||
* @return false if the unit an angle, a duration, a frequency or the number is a component in a Color object.
|
||||
*/
|
||||
public function isSize()
|
||||
{
|
||||
if (in_array($this->sUnit, self::NON_SIZE_UNITS, true)) {
|
||||
return false;
|
||||
}
|
||||
return !$this->isColorComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isRelative()
|
||||
{
|
||||
if (in_array($this->sUnit, self::RELATIVE_SIZE_UNITS, true)) {
|
||||
return true;
|
||||
}
|
||||
if ($this->sUnit === null && $this->fSize != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render(new OutputFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat|null $oOutputFormat
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($oOutputFormat)
|
||||
{
|
||||
$l = localeconv();
|
||||
$sPoint = preg_quote($l['decimal_point'], '/');
|
||||
$sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string)$this->fSize)
|
||||
? preg_replace("/$sPoint?0+$/", "", sprintf("%f", $this->fSize)) : (string)$this->fSize;
|
||||
return preg_replace(["/$sPoint/", "/^(-?)0\./"], ['.', '$1.'], $sSize)
|
||||
. ($this->sUnit === null ? '' : $this->sUnit);
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\OutputFormat;
|
||||
use Sabberworm\CSS\Parsing\ParserState;
|
||||
use Sabberworm\CSS\Parsing\SourceException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
|
||||
|
||||
/**
|
||||
* This class represents URLs in CSS. `URL`s always output in `URL("")` notation.
|
||||
*/
|
||||
class URL extends PrimitiveValue
|
||||
{
|
||||
/**
|
||||
* @var CSSString
|
||||
*/
|
||||
private $oURL;
|
||||
|
||||
/**
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct(CSSString $oURL, $iLineNo = 0)
|
||||
{
|
||||
parent::__construct($iLineNo);
|
||||
$this->oURL = $oURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return URL
|
||||
*
|
||||
* @throws SourceException
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parse(ParserState $oParserState)
|
||||
{
|
||||
$oAnchor = $oParserState->anchor();
|
||||
$sIdentifier = '';
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$sChar = $oParserState->parseCharacter(true);
|
||||
if ($sChar === null) {
|
||||
break;
|
||||
}
|
||||
$sIdentifier .= $sChar;
|
||||
}
|
||||
$bUseUrl = $oParserState->streql($sIdentifier, 'url');
|
||||
if ($bUseUrl) {
|
||||
$oParserState->consumeWhiteSpace();
|
||||
$oParserState->consume('(');
|
||||
} else {
|
||||
$oAnchor->backtrack();
|
||||
}
|
||||
$oParserState->consumeWhiteSpace();
|
||||
$oResult = new URL(CSSString::parse($oParserState), $oParserState->currentLine());
|
||||
if ($bUseUrl) {
|
||||
$oParserState->consumeWhiteSpace();
|
||||
$oParserState->consume(')');
|
||||
}
|
||||
return $oResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setURL(CSSString $oURL)
|
||||
{
|
||||
$this->oURL = $oURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CSSString
|
||||
*/
|
||||
public function getURL()
|
||||
{
|
||||
return $this->oURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render(new OutputFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat|null $oOutputFormat
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($oOutputFormat)
|
||||
{
|
||||
return "url({$this->oURL->render($oOutputFormat)})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\CSSElement;
|
||||
use Sabberworm\CSS\Parsing\ParserState;
|
||||
use Sabberworm\CSS\Parsing\SourceException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
|
||||
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
|
||||
use Sabberworm\CSS\Position\Position;
|
||||
use Sabberworm\CSS\Position\Positionable;
|
||||
|
||||
/**
|
||||
* Abstract base class for specific classes of CSS values: `Size`, `Color`, `CSSString` and `URL`, and another
|
||||
* abstract subclass `ValueList`.
|
||||
*/
|
||||
abstract class Value implements CSSElement, Positionable
|
||||
{
|
||||
use Position;
|
||||
|
||||
/**
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct($iLineNo = 0)
|
||||
{
|
||||
$this->setPosition($iLineNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array-key, string> $aListDelimiters
|
||||
*
|
||||
* @return RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string
|
||||
*
|
||||
* @throws UnexpectedTokenException
|
||||
* @throws UnexpectedEOFException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parseValue(ParserState $oParserState, array $aListDelimiters = [])
|
||||
{
|
||||
/** @var array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aStack */
|
||||
$aStack = [];
|
||||
$oParserState->consumeWhiteSpace();
|
||||
//Build a list of delimiters and parsed values
|
||||
while (
|
||||
!($oParserState->comes('}') || $oParserState->comes(';') || $oParserState->comes('!')
|
||||
|| $oParserState->comes(')')
|
||||
|| $oParserState->comes('\\')
|
||||
|| $oParserState->isEnd())
|
||||
) {
|
||||
if (count($aStack) > 0) {
|
||||
$bFoundDelimiter = false;
|
||||
foreach ($aListDelimiters as $sDelimiter) {
|
||||
if ($oParserState->comes($sDelimiter)) {
|
||||
array_push($aStack, $oParserState->consume($sDelimiter));
|
||||
$oParserState->consumeWhiteSpace();
|
||||
$bFoundDelimiter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$bFoundDelimiter) {
|
||||
//Whitespace was the list delimiter
|
||||
array_push($aStack, ' ');
|
||||
}
|
||||
}
|
||||
array_push($aStack, self::parsePrimitiveValue($oParserState));
|
||||
$oParserState->consumeWhiteSpace();
|
||||
}
|
||||
// Convert the list to list objects
|
||||
foreach ($aListDelimiters as $sDelimiter) {
|
||||
$iStackLength = count($aStack);
|
||||
if ($iStackLength === 1) {
|
||||
return $aStack[0];
|
||||
}
|
||||
$aNewStack = [];
|
||||
for ($iStartPosition = 0; $iStartPosition < $iStackLength; ++$iStartPosition) {
|
||||
if ($iStartPosition === ($iStackLength - 1) || $sDelimiter !== $aStack[$iStartPosition + 1]) {
|
||||
$aNewStack[] = $aStack[$iStartPosition];
|
||||
continue;
|
||||
}
|
||||
$iLength = 2; //Number of elements to be joined
|
||||
for ($i = $iStartPosition + 3; $i < $iStackLength; $i += 2, ++$iLength) {
|
||||
if ($sDelimiter !== $aStack[$i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$oList = new RuleValueList($sDelimiter, $oParserState->currentLine());
|
||||
for ($i = $iStartPosition; $i - $iStartPosition < $iLength * 2; $i += 2) {
|
||||
$oList->addListComponent($aStack[$i]);
|
||||
}
|
||||
$aNewStack[] = $oList;
|
||||
$iStartPosition += $iLength * 2 - 2;
|
||||
}
|
||||
$aStack = $aNewStack;
|
||||
}
|
||||
if (!isset($aStack[0])) {
|
||||
throw new UnexpectedTokenException(
|
||||
" {$oParserState->peek()} ",
|
||||
$oParserState->peek(1, -1) . $oParserState->peek(2),
|
||||
'literal',
|
||||
$oParserState->currentLine()
|
||||
);
|
||||
}
|
||||
return $aStack[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIgnoreCase
|
||||
*
|
||||
* @return CSSFunction|string
|
||||
*
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parseIdentifierOrFunction(ParserState $oParserState, $bIgnoreCase = false)
|
||||
{
|
||||
$oAnchor = $oParserState->anchor();
|
||||
$mResult = $oParserState->parseIdentifier($bIgnoreCase);
|
||||
|
||||
if ($oParserState->comes('(')) {
|
||||
$oAnchor->backtrack();
|
||||
if ($oParserState->streql('url', $mResult)) {
|
||||
$mResult = URL::parse($oParserState);
|
||||
} elseif (
|
||||
$oParserState->streql('calc', $mResult)
|
||||
|| $oParserState->streql('-webkit-calc', $mResult)
|
||||
|| $oParserState->streql('-moz-calc', $mResult)
|
||||
) {
|
||||
$mResult = CalcFunction::parse($oParserState);
|
||||
} else {
|
||||
$mResult = CSSFunction::parse($oParserState, $bIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
return $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CSSFunction|CSSString|LineName|Size|URL|string
|
||||
*
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
* @throws SourceException
|
||||
*
|
||||
* @internal since V8.8.0
|
||||
*/
|
||||
public static function parsePrimitiveValue(ParserState $oParserState)
|
||||
{
|
||||
$oValue = null;
|
||||
$oParserState->consumeWhiteSpace();
|
||||
if (
|
||||
is_numeric($oParserState->peek())
|
||||
|| ($oParserState->comes('-.')
|
||||
&& is_numeric($oParserState->peek(1, 2)))
|
||||
|| (($oParserState->comes('-') || $oParserState->comes('.')) && is_numeric($oParserState->peek(1, 1)))
|
||||
) {
|
||||
$oValue = Size::parse($oParserState);
|
||||
} elseif ($oParserState->comes('#') || $oParserState->comes('rgb', true) || $oParserState->comes('hsl', true)) {
|
||||
$oValue = Color::parse($oParserState);
|
||||
} elseif ($oParserState->comes("'") || $oParserState->comes('"')) {
|
||||
$oValue = CSSString::parse($oParserState);
|
||||
} elseif ($oParserState->comes("progid:") && $oParserState->getSettings()->bLenientParsing) {
|
||||
$oValue = self::parseMicrosoftFilter($oParserState);
|
||||
} elseif ($oParserState->comes("[")) {
|
||||
$oValue = LineName::parse($oParserState);
|
||||
} elseif ($oParserState->comes("U+")) {
|
||||
$oValue = self::parseUnicodeRangeValue($oParserState);
|
||||
} else {
|
||||
$sNextChar = $oParserState->peek(1);
|
||||
try {
|
||||
$oValue = self::parseIdentifierOrFunction($oParserState);
|
||||
} catch (UnexpectedTokenException $e) {
|
||||
if (\in_array($sNextChar, ['+', '-', '*', '/'], true)) {
|
||||
$oValue = $oParserState->consume(1);
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
$oParserState->consumeWhiteSpace();
|
||||
return $oValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CSSFunction
|
||||
*
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
*/
|
||||
private static function parseMicrosoftFilter(ParserState $oParserState)
|
||||
{
|
||||
$sFunction = $oParserState->consumeUntil('(', false, true);
|
||||
$aArguments = Value::parseValue($oParserState, [',', '=']);
|
||||
return new CSSFunction($sFunction, $aArguments, ',', $oParserState->currentLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @throws UnexpectedEOFException
|
||||
* @throws UnexpectedTokenException
|
||||
*/
|
||||
private static function parseUnicodeRangeValue(ParserState $oParserState)
|
||||
{
|
||||
$iCodepointMaxLength = 6; // Code points outside BMP can use up to six digits
|
||||
$sRange = "";
|
||||
$oParserState->consume("U+");
|
||||
do {
|
||||
if ($oParserState->comes('-')) {
|
||||
$iCodepointMaxLength = 13; // Max length is 2 six digit code points + the dash(-) between them
|
||||
}
|
||||
$sRange .= $oParserState->consume(1);
|
||||
} while (strlen($sRange) < $iCodepointMaxLength && preg_match("/[A-Fa-f0-9\?-]/", $oParserState->peek()));
|
||||
return "U+{$sRange}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Sabberworm\CSS\Value;
|
||||
|
||||
use Sabberworm\CSS\OutputFormat;
|
||||
|
||||
/**
|
||||
* A `ValueList` represents a lists of `Value`s, separated by some separation character
|
||||
* (mostly `,`, whitespace, or `/`).
|
||||
*
|
||||
* There are two types of `ValueList`s: `RuleValueList` and `CSSFunction`
|
||||
*/
|
||||
abstract class ValueList extends Value
|
||||
{
|
||||
/**
|
||||
* @var array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>
|
||||
*
|
||||
* @internal since 8.8.0
|
||||
*/
|
||||
protected $aComponents;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @internal since 8.8.0
|
||||
*/
|
||||
protected $sSeparator;
|
||||
|
||||
/**
|
||||
* phpcs:ignore Generic.Files.LineLength
|
||||
* @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>|RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $aComponents
|
||||
* @param string $sSeparator
|
||||
* @param int $iLineNo
|
||||
*/
|
||||
public function __construct($aComponents = [], $sSeparator = ',', $iLineNo = 0)
|
||||
{
|
||||
parent::__construct($iLineNo);
|
||||
if (!is_array($aComponents)) {
|
||||
$aComponents = [$aComponents];
|
||||
}
|
||||
$this->aComponents = $aComponents;
|
||||
$this->sSeparator = $sSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $mComponent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addListComponent($mComponent)
|
||||
{
|
||||
$this->aComponents[] = $mComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>
|
||||
*/
|
||||
public function getListComponents()
|
||||
{
|
||||
return $this->aComponents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setListComponents(array $aComponents)
|
||||
{
|
||||
$this->aComponents = $aComponents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getListSeparator()
|
||||
{
|
||||
return $this->sSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSeparator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setListSeparator($sSeparator)
|
||||
{
|
||||
$this->sSeparator = $sSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render(new OutputFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat|null $oOutputFormat
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($oOutputFormat)
|
||||
{
|
||||
return $oOutputFormat->implode(
|
||||
$oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator
|
||||
. $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator),
|
||||
$this->aComponents
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user