Update Twig from 1.35.0 to 1.42.4 (PHP 5.5 is now required!)

This fixes some errors on PHP 7.4 and contains even more fixes
Also bumped PHP version to 5.5 as Twig requires it.
This commit is contained in:
slawkens
2020-02-15 05:41:38 +01:00
parent d9e449b6cf
commit 8021308822
414 changed files with 9276 additions and 5531 deletions

View File

@@ -10,6 +10,10 @@
* file that was distributed with this source code.
*/
namespace Twig;
use Twig\Error\SyntaxError;
/**
* Represents a token stream.
*
@@ -17,7 +21,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_TokenStream
class TokenStream
{
protected $tokens;
protected $current = 0;
@@ -32,11 +36,11 @@ class Twig_TokenStream
*/
public function __construct(array $tokens, $name = null, $source = null)
{
if (!$name instanceof Twig_Source) {
if (!$name instanceof Source) {
if (null !== $name || null !== $source) {
@trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
@trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
}
$this->source = new Twig_Source($source, $name);
$this->source = new Source($source, $name);
} else {
$this->source = $name;
}
@@ -54,18 +58,18 @@ class Twig_TokenStream
public function injectTokens(array $tokens)
{
$this->tokens = array_merge(array_slice($this->tokens, 0, $this->current), $tokens, array_slice($this->tokens, $this->current));
$this->tokens = array_merge(\array_slice($this->tokens, 0, $this->current), $tokens, \array_slice($this->tokens, $this->current));
}
/**
* Sets the pointer to the next token and returns the old one.
*
* @return Twig_Token
* @return Token
*/
public function next()
{
if (!isset($this->tokens[++$this->current])) {
throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source);
throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source);
}
return $this->tokens[$this->current - 1];
@@ -74,7 +78,7 @@ class Twig_TokenStream
/**
* Tests a token, sets the pointer to the next one and returns it or throws a syntax error.
*
* @return Twig_Token|null The next token if the condition is true, null otherwise
* @return Token|null The next token if the condition is true, null otherwise
*/
public function nextIf($primary, $secondary = null)
{
@@ -86,17 +90,18 @@ class Twig_TokenStream
/**
* Tests a token and returns it or throws a syntax error.
*
* @return Twig_Token
* @return Token
*/
public function expect($type, $value = null, $message = null)
{
$token = $this->tokens[$this->current];
if (!$token->test($type, $value)) {
$line = $token->getLine();
throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).',
throw new SyntaxError(sprintf('%sUnexpected token "%s"%s ("%s" expected%s).',
$message ? $message.'. ' : '',
Twig_Token::typeToEnglish($token->getType()), $token->getValue(),
Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
Token::typeToEnglish($token->getType()),
$token->getValue() ? sprintf(' of value "%s"', $token->getValue()) : '',
Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
$line,
$this->source
);
@@ -111,12 +116,12 @@ class Twig_TokenStream
*
* @param int $number
*
* @return Twig_Token
* @return Token
*/
public function look($number = 1)
{
if (!isset($this->tokens[$this->current + $number])) {
throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source);
throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source);
}
return $this->tokens[$this->current + $number];
@@ -139,11 +144,11 @@ class Twig_TokenStream
*/
public function isEOF()
{
return $this->tokens[$this->current]->getType() === Twig_Token::EOF_TYPE;
return Token::EOF_TYPE === $this->tokens[$this->current]->getType();
}
/**
* @return Twig_Token
* @return Token
*/
public function getCurrent()
{
@@ -183,7 +188,7 @@ class Twig_TokenStream
/**
* Gets the source associated with this stream.
*
* @return Twig_Source
* @return Source
*
* @internal
*/
@@ -193,4 +198,4 @@ class Twig_TokenStream
}
}
class_alias('Twig_TokenStream', 'Twig\TokenStream', false);
class_alias('Twig\TokenStream', 'Twig_TokenStream');