mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
Merge branch '1.x' into 2.x
* 1.x: removed -2 magic number tried to avoid guessing template info on errors
This commit is contained in:
+2
-2
@@ -61,7 +61,7 @@ class Error extends \Exception
|
||||
* @param Source|string|null $source The source context where the error occurred
|
||||
* @param \Exception $previous The previous exception
|
||||
*/
|
||||
public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null)
|
||||
public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null, $autoGuess = true)
|
||||
{
|
||||
parent::__construct('', 0, $previous);
|
||||
|
||||
@@ -79,7 +79,7 @@ class Error extends \Exception
|
||||
$this->lineno = $lineno;
|
||||
$this->name = $name;
|
||||
|
||||
if (-1 === $lineno || null === $name || null === $this->sourcePath) {
|
||||
if ($autoGuess && (-1 === $lineno || null === $name || null === $this->sourcePath)) {
|
||||
$this->guessTemplateInfo();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,7 @@ class LoaderError extends Error
|
||||
{
|
||||
public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null)
|
||||
{
|
||||
\Exception::__construct('', 0, $previous);
|
||||
$this->appendMessage($message);
|
||||
$this->setTemplateLine(-2);
|
||||
parent::__construct($message, $lineno, $source, $previous, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
$named = true;
|
||||
$name = $this->normalizeName($name);
|
||||
} elseif ($named) {
|
||||
throw new SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine());
|
||||
throw new SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine(), null, null, false);
|
||||
}
|
||||
|
||||
$parameters[$name] = $node;
|
||||
@@ -157,14 +157,14 @@ abstract class CallExpression extends AbstractExpression
|
||||
|
||||
if (\array_key_exists($name, $parameters)) {
|
||||
if (\array_key_exists($pos, $parameters)) {
|
||||
throw new SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine());
|
||||
throw new SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), null, null, false);
|
||||
}
|
||||
|
||||
if (\count($missingArguments)) {
|
||||
throw new SyntaxError(sprintf(
|
||||
'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".',
|
||||
$name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments)
|
||||
), $this->getTemplateLine());
|
||||
), $this->getTemplateLine(), null, null, false);
|
||||
}
|
||||
|
||||
$arguments = array_merge($arguments, $optionalArguments);
|
||||
@@ -186,7 +186,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
$missingArguments[] = $name;
|
||||
}
|
||||
} else {
|
||||
throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine());
|
||||
throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), null, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
throw new SyntaxError(sprintf(
|
||||
'Unknown argument%s "%s" for %s "%s(%s)".',
|
||||
\count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names)
|
||||
), $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine());
|
||||
), $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine(), null, null, false);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
|
||||
@@ -48,7 +48,7 @@ class DefinedTest extends TestExpression
|
||||
} elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) {
|
||||
$node = new ConstantExpression(true, $node->getTemplateLine());
|
||||
} else {
|
||||
throw new SyntaxError('The "defined" test only works with simple variables.', $this->getTemplateLine());
|
||||
throw new SyntaxError('The "defined" test only works with simple variables.', $this->getTemplateLine(), null, null, false);
|
||||
}
|
||||
|
||||
parent::__construct($node, $name, $arguments, $lineno);
|
||||
|
||||
@@ -27,7 +27,7 @@ class MacroNode extends Node
|
||||
{
|
||||
foreach ($arguments as $argumentName => $argument) {
|
||||
if (self::VARARGS_NAME === $argumentName) {
|
||||
throw new SyntaxError(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine());
|
||||
throw new SyntaxError(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine(), null, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -189,8 +189,7 @@ abstract class Template
|
||||
|
||||
// this is mostly useful for \Twig\Error\LoaderError exceptions
|
||||
// see \Twig\Error\LoaderError
|
||||
if (-2 === $e->getTemplateLine()) {
|
||||
$e->setTemplateLine(-1);
|
||||
if (-1 === $e->getTemplateLine()) {
|
||||
$e->guess();
|
||||
}
|
||||
|
||||
@@ -376,8 +375,7 @@ abstract class Template
|
||||
|
||||
// this is mostly useful for \Twig\Error\LoaderError exceptions
|
||||
// see \Twig\Error\LoaderError
|
||||
if (-2 === $e->getTemplateLine()) {
|
||||
$e->setTemplateLine(-1);
|
||||
if (-1 === $e->getTemplateLine()) {
|
||||
$e->guess();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user