scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 86  →  ?path2? @ 87
/vendor/symfony/css-selector/Parser/Handler/CommentHandler.php
@@ -0,0 +1,48 @@
<?php
 
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Symfony\Component\CssSelector\Parser\Handler;
 
use Symfony\Component\CssSelector\Parser\Reader;
use Symfony\Component\CssSelector\Parser\TokenStream;
 
/**
* CSS selector comment handler.
*
* This component is a port of the Python cssselect library,
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*
* @internal
*/
class CommentHandler implements HandlerInterface
{
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
{
if ('/*' !== $reader->getSubstring(2)) {
return false;
}
 
$offset = $reader->getOffset('*/');
 
if (false === $offset) {
$reader->moveToEnd();
} else {
$reader->moveForward($offset + 2);
}
 
return true;
}
}
/vendor/symfony/css-selector/Parser/Handler/HandlerInterface.php
@@ -0,0 +1,36 @@
<?php
 
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Symfony\Component\CssSelector\Parser\Handler;
 
use Symfony\Component\CssSelector\Parser\Reader;
use Symfony\Component\CssSelector\Parser\TokenStream;
 
/**
* CSS selector handler interface.
*
* This component is a port of the Python cssselect library,
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*
* @internal
*/
interface HandlerInterface
{
/**
* @param Reader $reader
* @param TokenStream $stream
*
* @return bool
*/
public function handle(Reader $reader, TokenStream $stream);
}
/vendor/symfony/css-selector/Parser/Handler/HashHandler.php
@@ -0,0 +1,69 @@
<?php
 
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Symfony\Component\CssSelector\Parser\Handler;
 
use Symfony\Component\CssSelector\Parser\Reader;
use Symfony\Component\CssSelector\Parser\Token;
use Symfony\Component\CssSelector\Parser\TokenStream;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns;
 
/**
* CSS selector comment handler.
*
* This component is a port of the Python cssselect library,
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*
* @internal
*/
class HashHandler implements HandlerInterface
{
/**
* @var TokenizerPatterns
*/
private $patterns;
 
/**
* @var TokenizerEscaping
*/
private $escaping;
 
/**
* @param TokenizerPatterns $patterns
* @param TokenizerEscaping $escaping
*/
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
{
$this->patterns = $patterns;
$this->escaping = $escaping;
}
 
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
{
$match = $reader->findPattern($this->patterns->getHashPattern());
 
if (!$match) {
return false;
}
 
$value = $this->escaping->escapeUnicode($match[1]);
$stream->push(new Token(Token::TYPE_HASH, $value, $reader->getPosition()));
$reader->moveForward(strlen($match[0]));
 
return true;
}
}
/vendor/symfony/css-selector/Parser/Handler/IdentifierHandler.php
@@ -0,0 +1,69 @@
<?php
 
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Symfony\Component\CssSelector\Parser\Handler;
 
use Symfony\Component\CssSelector\Parser\Reader;
use Symfony\Component\CssSelector\Parser\Token;
use Symfony\Component\CssSelector\Parser\TokenStream;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns;
 
/**
* CSS selector comment handler.
*
* This component is a port of the Python cssselect library,
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*
* @internal
*/
class IdentifierHandler implements HandlerInterface
{
/**
* @var TokenizerPatterns
*/
private $patterns;
 
/**
* @var TokenizerEscaping
*/
private $escaping;
 
/**
* @param TokenizerPatterns $patterns
* @param TokenizerEscaping $escaping
*/
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
{
$this->patterns = $patterns;
$this->escaping = $escaping;
}
 
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
{
$match = $reader->findPattern($this->patterns->getIdentifierPattern());
 
if (!$match) {
return false;
}
 
$value = $this->escaping->escapeUnicode($match[0]);
$stream->push(new Token(Token::TYPE_IDENTIFIER, $value, $reader->getPosition()));
$reader->moveForward(strlen($match[0]));
 
return true;
}
}
/vendor/symfony/css-selector/Parser/Handler/NumberHandler.php
@@ -0,0 +1,60 @@
<?php
 
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Symfony\Component\CssSelector\Parser\Handler;
 
use Symfony\Component\CssSelector\Parser\Reader;
use Symfony\Component\CssSelector\Parser\Token;
use Symfony\Component\CssSelector\Parser\TokenStream;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns;
 
/**
* CSS selector comment handler.
*
* This component is a port of the Python cssselect library,
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*
* @internal
*/
class NumberHandler implements HandlerInterface
{
/**
* @var TokenizerPatterns
*/
private $patterns;
 
/**
* @param TokenizerPatterns $patterns
*/
public function __construct(TokenizerPatterns $patterns)
{
$this->patterns = $patterns;
}
 
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
{
$match = $reader->findPattern($this->patterns->getNumberPattern());
 
if (!$match) {
return false;
}
 
$stream->push(new Token(Token::TYPE_NUMBER, $match[0], $reader->getPosition()));
$reader->moveForward(strlen($match[0]));
 
return true;
}
}
/vendor/symfony/css-selector/Parser/Handler/StringHandler.php
@@ -0,0 +1,88 @@
<?php
 
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Symfony\Component\CssSelector\Parser\Handler;
 
use Symfony\Component\CssSelector\Exception\InternalErrorException;
use Symfony\Component\CssSelector\Exception\SyntaxErrorException;
use Symfony\Component\CssSelector\Parser\Reader;
use Symfony\Component\CssSelector\Parser\Token;
use Symfony\Component\CssSelector\Parser\TokenStream;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns;
 
/**
* CSS selector comment handler.
*
* This component is a port of the Python cssselect library,
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*
* @internal
*/
class StringHandler implements HandlerInterface
{
/**
* @var TokenizerPatterns
*/
private $patterns;
 
/**
* @var TokenizerEscaping
*/
private $escaping;
 
/**
* @param TokenizerPatterns $patterns
* @param TokenizerEscaping $escaping
*/
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
{
$this->patterns = $patterns;
$this->escaping = $escaping;
}
 
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
{
$quote = $reader->getSubstring(1);
 
if (!in_array($quote, array("'", '"'))) {
return false;
}
 
$reader->moveForward(1);
$match = $reader->findPattern($this->patterns->getQuotedStringPattern($quote));
 
if (!$match) {
throw new InternalErrorException(sprintf('Should have found at least an empty match at %s.', $reader->getPosition()));
}
 
// check unclosed strings
if (strlen($match[0]) === $reader->getRemainingLength()) {
throw SyntaxErrorException::unclosedString($reader->getPosition() - 1);
}
 
// check quotes pairs validity
if ($quote !== $reader->getSubstring(1, strlen($match[0]))) {
throw SyntaxErrorException::unclosedString($reader->getPosition() - 1);
}
 
$string = $this->escaping->escapeUnicodeAndNewLine($match[0]);
$stream->push(new Token(Token::TYPE_STRING, $string, $reader->getPosition()));
$reader->moveForward(strlen($match[0]) + 1);
 
return true;
}
}
/vendor/symfony/css-selector/Parser/Handler/WhitespaceHandler.php
@@ -0,0 +1,46 @@
<?php
 
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Symfony\Component\CssSelector\Parser\Handler;
 
use Symfony\Component\CssSelector\Parser\Reader;
use Symfony\Component\CssSelector\Parser\Token;
use Symfony\Component\CssSelector\Parser\TokenStream;
 
/**
* CSS selector whitespace handler.
*
* This component is a port of the Python cssselect library,
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*
* @internal
*/
class WhitespaceHandler implements HandlerInterface
{
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
{
$match = $reader->findPattern('~^[ \t\r\n\f]+~');
 
if (false === $match) {
return false;
}
 
$stream->push(new Token(Token::TYPE_WHITESPACE, $match[0], $reader->getPosition()));
$reader->moveForward(strlen($match[0]));
 
return true;
}
}