Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../www/wp-conte.../plugins/wpforms-.../vendor_p.../symfony/css-sele.../Parser
File: Parser.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of the Symfony package.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier <fabien@symfony.com>
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
namespace WPForms\Vendor\Symfony\Component\CssSelector\Parser;
[10] Fix | Delete
[11] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Exception\SyntaxErrorException;
[12] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Node;
[13] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Parser\Tokenizer\Tokenizer;
[14] Fix | Delete
/**
[15] Fix | Delete
* CSS selector parser.
[16] Fix | Delete
*
[17] Fix | Delete
* This component is a port of the Python cssselect library,
[18] Fix | Delete
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
[19] Fix | Delete
*
[20] Fix | Delete
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
[21] Fix | Delete
*
[22] Fix | Delete
* @internal
[23] Fix | Delete
*/
[24] Fix | Delete
class Parser implements ParserInterface
[25] Fix | Delete
{
[26] Fix | Delete
/**
[27] Fix | Delete
* @var Tokenizer
[28] Fix | Delete
*/
[29] Fix | Delete
private $tokenizer;
[30] Fix | Delete
/**
[31] Fix | Delete
* Constructor.
[32] Fix | Delete
*
[33] Fix | Delete
* @param null|Tokenizer $tokenizer
[34] Fix | Delete
*/
[35] Fix | Delete
public function __construct(Tokenizer $tokenizer = null)
[36] Fix | Delete
{
[37] Fix | Delete
$this->tokenizer = $tokenizer ?: new Tokenizer();
[38] Fix | Delete
}
[39] Fix | Delete
/**
[40] Fix | Delete
* {@inheritdoc}
[41] Fix | Delete
*/
[42] Fix | Delete
public function parse($source)
[43] Fix | Delete
{
[44] Fix | Delete
$reader = new Reader($source);
[45] Fix | Delete
$stream = $this->tokenizer->tokenize($reader);
[46] Fix | Delete
return $this->parseSelectorList($stream);
[47] Fix | Delete
}
[48] Fix | Delete
/**
[49] Fix | Delete
* Parses the arguments for ":nth-child()" and friends.
[50] Fix | Delete
*
[51] Fix | Delete
* @param Token[] $tokens
[52] Fix | Delete
*
[53] Fix | Delete
* @return array
[54] Fix | Delete
*
[55] Fix | Delete
* @throws SyntaxErrorException
[56] Fix | Delete
*/
[57] Fix | Delete
public static function parseSeries(array $tokens)
[58] Fix | Delete
{
[59] Fix | Delete
foreach ($tokens as $token) {
[60] Fix | Delete
if ($token->isString()) {
[61] Fix | Delete
throw SyntaxErrorException::stringAsFunctionArgument();
[62] Fix | Delete
}
[63] Fix | Delete
}
[64] Fix | Delete
$joined = \trim(\implode('', \array_map(function (Token $token) {
[65] Fix | Delete
return $token->getValue();
[66] Fix | Delete
}, $tokens)));
[67] Fix | Delete
$int = function ($string) {
[68] Fix | Delete
if (!\is_numeric($string)) {
[69] Fix | Delete
throw SyntaxErrorException::stringAsFunctionArgument();
[70] Fix | Delete
}
[71] Fix | Delete
return (int) $string;
[72] Fix | Delete
};
[73] Fix | Delete
switch (\true) {
[74] Fix | Delete
case 'odd' === $joined:
[75] Fix | Delete
return array(2, 1);
[76] Fix | Delete
case 'even' === $joined:
[77] Fix | Delete
return array(2, 0);
[78] Fix | Delete
case 'n' === $joined:
[79] Fix | Delete
return array(1, 0);
[80] Fix | Delete
case \false === \strpos($joined, 'n'):
[81] Fix | Delete
return array(0, $int($joined));
[82] Fix | Delete
}
[83] Fix | Delete
$split = \explode('n', $joined);
[84] Fix | Delete
$first = isset($split[0]) ? $split[0] : null;
[85] Fix | Delete
return array($first ? '-' === $first || '+' === $first ? $int($first . '1') : $int($first) : 1, isset($split[1]) && $split[1] ? $int($split[1]) : 0);
[86] Fix | Delete
}
[87] Fix | Delete
/**
[88] Fix | Delete
* Parses selector nodes.
[89] Fix | Delete
*
[90] Fix | Delete
* @param TokenStream $stream
[91] Fix | Delete
*
[92] Fix | Delete
* @return array
[93] Fix | Delete
*/
[94] Fix | Delete
private function parseSelectorList(TokenStream $stream)
[95] Fix | Delete
{
[96] Fix | Delete
$stream->skipWhitespace();
[97] Fix | Delete
$selectors = array();
[98] Fix | Delete
while (\true) {
[99] Fix | Delete
$selectors[] = $this->parserSelectorNode($stream);
[100] Fix | Delete
if ($stream->getPeek()->isDelimiter(array(','))) {
[101] Fix | Delete
$stream->getNext();
[102] Fix | Delete
$stream->skipWhitespace();
[103] Fix | Delete
} else {
[104] Fix | Delete
break;
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
return $selectors;
[108] Fix | Delete
}
[109] Fix | Delete
/**
[110] Fix | Delete
* Parses next selector or combined node.
[111] Fix | Delete
*
[112] Fix | Delete
* @param TokenStream $stream
[113] Fix | Delete
*
[114] Fix | Delete
* @return Node\SelectorNode
[115] Fix | Delete
*
[116] Fix | Delete
* @throws SyntaxErrorException
[117] Fix | Delete
*/
[118] Fix | Delete
private function parserSelectorNode(TokenStream $stream)
[119] Fix | Delete
{
[120] Fix | Delete
list($result, $pseudoElement) = $this->parseSimpleSelector($stream);
[121] Fix | Delete
while (\true) {
[122] Fix | Delete
$stream->skipWhitespace();
[123] Fix | Delete
$peek = $stream->getPeek();
[124] Fix | Delete
if ($peek->isFileEnd() || $peek->isDelimiter(array(','))) {
[125] Fix | Delete
break;
[126] Fix | Delete
}
[127] Fix | Delete
if (null !== $pseudoElement) {
[128] Fix | Delete
throw SyntaxErrorException::pseudoElementFound($pseudoElement, 'not at the end of a selector');
[129] Fix | Delete
}
[130] Fix | Delete
if ($peek->isDelimiter(array('+', '>', '~'))) {
[131] Fix | Delete
$combinator = $stream->getNext()->getValue();
[132] Fix | Delete
$stream->skipWhitespace();
[133] Fix | Delete
} else {
[134] Fix | Delete
$combinator = ' ';
[135] Fix | Delete
}
[136] Fix | Delete
list($nextSelector, $pseudoElement) = $this->parseSimpleSelector($stream);
[137] Fix | Delete
$result = new Node\CombinedSelectorNode($result, $combinator, $nextSelector);
[138] Fix | Delete
}
[139] Fix | Delete
return new Node\SelectorNode($result, $pseudoElement);
[140] Fix | Delete
}
[141] Fix | Delete
/**
[142] Fix | Delete
* Parses next simple node (hash, class, pseudo, negation).
[143] Fix | Delete
*
[144] Fix | Delete
* @param TokenStream $stream
[145] Fix | Delete
* @param bool $insideNegation
[146] Fix | Delete
*
[147] Fix | Delete
* @return array
[148] Fix | Delete
*
[149] Fix | Delete
* @throws SyntaxErrorException
[150] Fix | Delete
*/
[151] Fix | Delete
private function parseSimpleSelector(TokenStream $stream, $insideNegation = \false)
[152] Fix | Delete
{
[153] Fix | Delete
$stream->skipWhitespace();
[154] Fix | Delete
$selectorStart = \count($stream->getUsed());
[155] Fix | Delete
$result = $this->parseElementNode($stream);
[156] Fix | Delete
$pseudoElement = null;
[157] Fix | Delete
while (\true) {
[158] Fix | Delete
$peek = $stream->getPeek();
[159] Fix | Delete
if ($peek->isWhitespace() || $peek->isFileEnd() || $peek->isDelimiter(array(',', '+', '>', '~')) || $insideNegation && $peek->isDelimiter(array(')'))) {
[160] Fix | Delete
break;
[161] Fix | Delete
}
[162] Fix | Delete
if (null !== $pseudoElement) {
[163] Fix | Delete
throw SyntaxErrorException::pseudoElementFound($pseudoElement, 'not at the end of a selector');
[164] Fix | Delete
}
[165] Fix | Delete
if ($peek->isHash()) {
[166] Fix | Delete
$result = new Node\HashNode($result, $stream->getNext()->getValue());
[167] Fix | Delete
} elseif ($peek->isDelimiter(array('.'))) {
[168] Fix | Delete
$stream->getNext();
[169] Fix | Delete
$result = new Node\ClassNode($result, $stream->getNextIdentifier());
[170] Fix | Delete
} elseif ($peek->isDelimiter(array('['))) {
[171] Fix | Delete
$stream->getNext();
[172] Fix | Delete
$result = $this->parseAttributeNode($result, $stream);
[173] Fix | Delete
} elseif ($peek->isDelimiter(array(':'))) {
[174] Fix | Delete
$stream->getNext();
[175] Fix | Delete
if ($stream->getPeek()->isDelimiter(array(':'))) {
[176] Fix | Delete
$stream->getNext();
[177] Fix | Delete
$pseudoElement = $stream->getNextIdentifier();
[178] Fix | Delete
continue;
[179] Fix | Delete
}
[180] Fix | Delete
$identifier = $stream->getNextIdentifier();
[181] Fix | Delete
if (\in_array(\strtolower($identifier), array('first-line', 'first-letter', 'before', 'after'))) {
[182] Fix | Delete
// Special case: CSS 2.1 pseudo-elements can have a single ':'.
[183] Fix | Delete
// Any new pseudo-element must have two.
[184] Fix | Delete
$pseudoElement = $identifier;
[185] Fix | Delete
continue;
[186] Fix | Delete
}
[187] Fix | Delete
if (!$stream->getPeek()->isDelimiter(array('('))) {
[188] Fix | Delete
$result = new Node\PseudoNode($result, $identifier);
[189] Fix | Delete
continue;
[190] Fix | Delete
}
[191] Fix | Delete
$stream->getNext();
[192] Fix | Delete
$stream->skipWhitespace();
[193] Fix | Delete
if ('not' === \strtolower($identifier)) {
[194] Fix | Delete
if ($insideNegation) {
[195] Fix | Delete
throw SyntaxErrorException::nestedNot();
[196] Fix | Delete
}
[197] Fix | Delete
list($argument, $argumentPseudoElement) = $this->parseSimpleSelector($stream, \true);
[198] Fix | Delete
$next = $stream->getNext();
[199] Fix | Delete
if (null !== $argumentPseudoElement) {
[200] Fix | Delete
throw SyntaxErrorException::pseudoElementFound($argumentPseudoElement, 'inside ::not()');
[201] Fix | Delete
}
[202] Fix | Delete
if (!$next->isDelimiter(array(')'))) {
[203] Fix | Delete
throw SyntaxErrorException::unexpectedToken('")"', $next);
[204] Fix | Delete
}
[205] Fix | Delete
$result = new Node\NegationNode($result, $argument);
[206] Fix | Delete
} else {
[207] Fix | Delete
$arguments = array();
[208] Fix | Delete
$next = null;
[209] Fix | Delete
while (\true) {
[210] Fix | Delete
$stream->skipWhitespace();
[211] Fix | Delete
$next = $stream->getNext();
[212] Fix | Delete
if ($next->isIdentifier() || $next->isString() || $next->isNumber() || $next->isDelimiter(array('+', '-'))) {
[213] Fix | Delete
$arguments[] = $next;
[214] Fix | Delete
} elseif ($next->isDelimiter(array(')'))) {
[215] Fix | Delete
break;
[216] Fix | Delete
} else {
[217] Fix | Delete
throw SyntaxErrorException::unexpectedToken('an argument', $next);
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
if (empty($arguments)) {
[221] Fix | Delete
throw SyntaxErrorException::unexpectedToken('at least one argument', $next);
[222] Fix | Delete
}
[223] Fix | Delete
$result = new Node\FunctionNode($result, $identifier, $arguments);
[224] Fix | Delete
}
[225] Fix | Delete
} else {
[226] Fix | Delete
throw SyntaxErrorException::unexpectedToken('selector', $peek);
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
if (\count($stream->getUsed()) === $selectorStart) {
[230] Fix | Delete
throw SyntaxErrorException::unexpectedToken('selector', $stream->getPeek());
[231] Fix | Delete
}
[232] Fix | Delete
return array($result, $pseudoElement);
[233] Fix | Delete
}
[234] Fix | Delete
/**
[235] Fix | Delete
* Parses next element node.
[236] Fix | Delete
*
[237] Fix | Delete
* @param TokenStream $stream
[238] Fix | Delete
*
[239] Fix | Delete
* @return Node\ElementNode
[240] Fix | Delete
*/
[241] Fix | Delete
private function parseElementNode(TokenStream $stream)
[242] Fix | Delete
{
[243] Fix | Delete
$peek = $stream->getPeek();
[244] Fix | Delete
if ($peek->isIdentifier() || $peek->isDelimiter(array('*'))) {
[245] Fix | Delete
if ($peek->isIdentifier()) {
[246] Fix | Delete
$namespace = $stream->getNext()->getValue();
[247] Fix | Delete
} else {
[248] Fix | Delete
$stream->getNext();
[249] Fix | Delete
$namespace = null;
[250] Fix | Delete
}
[251] Fix | Delete
if ($stream->getPeek()->isDelimiter(array('|'))) {
[252] Fix | Delete
$stream->getNext();
[253] Fix | Delete
$element = $stream->getNextIdentifierOrStar();
[254] Fix | Delete
} else {
[255] Fix | Delete
$element = $namespace;
[256] Fix | Delete
$namespace = null;
[257] Fix | Delete
}
[258] Fix | Delete
} else {
[259] Fix | Delete
$element = $namespace = null;
[260] Fix | Delete
}
[261] Fix | Delete
return new Node\ElementNode($namespace, $element);
[262] Fix | Delete
}
[263] Fix | Delete
/**
[264] Fix | Delete
* Parses next attribute node.
[265] Fix | Delete
*
[266] Fix | Delete
* @param Node\NodeInterface $selector
[267] Fix | Delete
* @param TokenStream $stream
[268] Fix | Delete
*
[269] Fix | Delete
* @return Node\AttributeNode
[270] Fix | Delete
*
[271] Fix | Delete
* @throws SyntaxErrorException
[272] Fix | Delete
*/
[273] Fix | Delete
private function parseAttributeNode(Node\NodeInterface $selector, TokenStream $stream)
[274] Fix | Delete
{
[275] Fix | Delete
$stream->skipWhitespace();
[276] Fix | Delete
$attribute = $stream->getNextIdentifierOrStar();
[277] Fix | Delete
if (null === $attribute && !$stream->getPeek()->isDelimiter(array('|'))) {
[278] Fix | Delete
throw SyntaxErrorException::unexpectedToken('"|"', $stream->getPeek());
[279] Fix | Delete
}
[280] Fix | Delete
if ($stream->getPeek()->isDelimiter(array('|'))) {
[281] Fix | Delete
$stream->getNext();
[282] Fix | Delete
if ($stream->getPeek()->isDelimiter(array('='))) {
[283] Fix | Delete
$namespace = null;
[284] Fix | Delete
$stream->getNext();
[285] Fix | Delete
$operator = '|=';
[286] Fix | Delete
} else {
[287] Fix | Delete
$namespace = $attribute;
[288] Fix | Delete
$attribute = $stream->getNextIdentifier();
[289] Fix | Delete
$operator = null;
[290] Fix | Delete
}
[291] Fix | Delete
} else {
[292] Fix | Delete
$namespace = $operator = null;
[293] Fix | Delete
}
[294] Fix | Delete
if (null === $operator) {
[295] Fix | Delete
$stream->skipWhitespace();
[296] Fix | Delete
$next = $stream->getNext();
[297] Fix | Delete
if ($next->isDelimiter(array(']'))) {
[298] Fix | Delete
return new Node\AttributeNode($selector, $namespace, $attribute, 'exists', null);
[299] Fix | Delete
} elseif ($next->isDelimiter(array('='))) {
[300] Fix | Delete
$operator = '=';
[301] Fix | Delete
} elseif ($next->isDelimiter(array('^', '$', '*', '~', '|', '!')) && $stream->getPeek()->isDelimiter(array('='))) {
[302] Fix | Delete
$operator = $next->getValue() . '=';
[303] Fix | Delete
$stream->getNext();
[304] Fix | Delete
} else {
[305] Fix | Delete
throw SyntaxErrorException::unexpectedToken('operator', $next);
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
$stream->skipWhitespace();
[309] Fix | Delete
$value = $stream->getNext();
[310] Fix | Delete
if ($value->isNumber()) {
[311] Fix | Delete
// if the value is a number, it's casted into a string
[312] Fix | Delete
$value = new Token(Token::TYPE_STRING, (string) $value->getValue(), $value->getPosition());
[313] Fix | Delete
}
[314] Fix | Delete
if (!($value->isIdentifier() || $value->isString())) {
[315] Fix | Delete
throw SyntaxErrorException::unexpectedToken('string or identifier', $value);
[316] Fix | Delete
}
[317] Fix | Delete
$stream->skipWhitespace();
[318] Fix | Delete
$next = $stream->getNext();
[319] Fix | Delete
if (!$next->isDelimiter(array(']'))) {
[320] Fix | Delete
throw SyntaxErrorException::unexpectedToken('"]"', $next);
[321] Fix | Delete
}
[322] Fix | Delete
return new Node\AttributeNode($selector, $namespace, $attribute, $operator, $value->getValue());
[323] Fix | Delete
}
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function