Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various small bugs #2939

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ public function loadClass($cls, $name, $index = null)
$this->cache->load($key);
}

$source = null;
if (!class_exists($cls, false)) {
$loader = $this->getLoader();
if (!$loader instanceof SourceContextLoaderInterface) {
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ function twig_constant_is_defined($constant, $object = null)
function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
{
if (!twig_test_iterable($items)) {
throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
}

$size = ceil($size);
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/StringLoaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader

namespace {
use Twig\Environment;
use Twig\Template;
use Twig\TemplateWrapper;

/**
* Loads a template from a string.
Expand All @@ -45,7 +45,7 @@ class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader
* @param string $template A template as a string or object implementing __toString()
* @param string $name An optional name of the template to be used in error messages
*
* @return Template
* @return TemplateWrapper
*/
function twig_template_from_string(Environment $env, $template, $name = null)
{
Expand Down
28 changes: 14 additions & 14 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ protected function lexData()

case $this->options['tag_block'][0]:
// raw data?
if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) {
if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) {
$this->moveCursor($match[0]);
$this->lexRawData($match[1]);
// {% line \d+ %}
} elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) {
} elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) {
$this->moveCursor($match[0]);
$this->lineno = (int) $match[1];
} else {
Expand All @@ -301,7 +301,7 @@ protected function lexData()

protected function lexBlock()
{
if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) {
if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) {
$this->pushToken(Token::BLOCK_END_TYPE);
$this->moveCursor($match[0]);
$this->popState();
Expand All @@ -312,7 +312,7 @@ protected function lexBlock()

protected function lexVar()
{
if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) {
if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) {
$this->pushToken(Token::VAR_END_TYPE);
$this->moveCursor($match[0]);
$this->popState();
Expand All @@ -324,7 +324,7 @@ protected function lexVar()
protected function lexExpression()
{
// whitespace
if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) {
if (preg_match('/\s+/A', $this->code, $match, 0, $this->cursor)) {
$this->moveCursor($match[0]);

if ($this->cursor >= $this->end) {
Expand All @@ -333,17 +333,17 @@ protected function lexExpression()
}

// operators
if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) {
if (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) {
$this->pushToken(Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0]));
$this->moveCursor($match[0]);
}
// names
elseif (preg_match(self::REGEX_NAME, $this->code, $match, null, $this->cursor)) {
elseif (preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) {
$this->pushToken(Token::NAME_TYPE, $match[0]);
$this->moveCursor($match[0]);
}
// numbers
elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, null, $this->cursor)) {
elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) {
$number = (float) $match[0]; // floats
if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
$number = (int) $match[0]; // integers lower than the maximum
Expand Down Expand Up @@ -373,12 +373,12 @@ protected function lexExpression()
++$this->cursor;
}
// strings
elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) {
elseif (preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) {
$this->pushToken(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)));
$this->moveCursor($match[0]);
}
// opening double quoted string
elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
$this->brackets[] = ['"', $this->lineno];
$this->pushState(self::STATE_STRING);
$this->moveCursor($match[0]);
Expand Down Expand Up @@ -428,15 +428,15 @@ protected function lexComment()

protected function lexString()
{
if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) {
if (preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) {
$this->brackets[] = [$this->options['interpolation'][0], $this->lineno];
$this->pushToken(Token::INTERPOLATION_START_TYPE);
$this->moveCursor($match[0]);
$this->pushState(self::STATE_INTERPOLATION);
} elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && \strlen($match[0]) > 0) {
} elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) {
$this->pushToken(Token::STRING_TYPE, stripcslashes($match[0]));
$this->moveCursor($match[0]);
} elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
} elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
list($expect, $lineno) = array_pop($this->brackets);
if ('"' != $this->code[$this->cursor]) {
throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
Expand All @@ -453,7 +453,7 @@ protected function lexString()
protected function lexInterpolation()
{
$bracket = end($this->brackets);
if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) {
if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) {
array_pop($this->brackets);
$this->pushToken(Token::INTERPOLATION_END_TYPE);
$this->moveCursor($match[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/Test/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e
$message = $e->getMessage();
$this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message)));
$last = substr($message, \strlen($message) - 1);
$this->assertTrue('.' === $last || '?' === $last, $message, 'Exception message must end with a dot or a question mark.');
$this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.');

return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Test/NodeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function getVariableGetter($name, $line = false)
$line = $line > 0 ? "// line {$line}\n" : '';

if (\PHP_VERSION_ID >= 70000) {
return sprintf('%s($context["%s"] ?? null)', $line, $name, $name);
return sprintf('%s($context["%s"] ?? null)', $line, $name);
}

if (\PHP_VERSION_ID >= 50400) {
Expand Down