mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-18 13:26:37 +00:00
tried to avoid guessing template info on errors
This commit is contained in:
+2
-2
@@ -63,7 +63,7 @@ class Error extends \Exception
|
|||||||
* @param Source|string|null $source The source context where the error occurred
|
* @param Source|string|null $source The source context where the error occurred
|
||||||
* @param \Exception $previous The previous exception
|
* @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)
|
||||||
{
|
{
|
||||||
if (null === $source) {
|
if (null === $source) {
|
||||||
$name = null;
|
$name = null;
|
||||||
@@ -80,7 +80,7 @@ class Error extends \Exception
|
|||||||
$this->lineno = $lineno;
|
$this->lineno = $lineno;
|
||||||
$this->filename = $name;
|
$this->filename = $name;
|
||||||
|
|
||||||
if (-1 === $lineno || null === $name || null === $this->sourcePath) {
|
if ($autoGuess && (-1 === $lineno || null === $name || null === $this->sourcePath)) {
|
||||||
$this->guessTemplateInfo();
|
$this->guessTemplateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ abstract class CallExpression extends AbstractExpression
|
|||||||
$named = true;
|
$named = true;
|
||||||
$name = $this->normalizeName($name);
|
$name = $this->normalizeName($name);
|
||||||
} elseif ($named) {
|
} 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;
|
$parameters[$name] = $node;
|
||||||
@@ -153,14 +153,14 @@ abstract class CallExpression extends AbstractExpression
|
|||||||
|
|
||||||
if (\array_key_exists($name, $parameters)) {
|
if (\array_key_exists($name, $parameters)) {
|
||||||
if (\array_key_exists($pos, $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)) {
|
if (\count($missingArguments)) {
|
||||||
throw new SyntaxError(sprintf(
|
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".',
|
'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)
|
$name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments)
|
||||||
), $this->getTemplateLine());
|
), $this->getTemplateLine(), null, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = array_merge($arguments, $optionalArguments);
|
$arguments = array_merge($arguments, $optionalArguments);
|
||||||
@@ -182,7 +182,7 @@ abstract class CallExpression extends AbstractExpression
|
|||||||
$missingArguments[] = $name;
|
$missingArguments[] = $name;
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ abstract class CallExpression extends AbstractExpression
|
|||||||
throw new SyntaxError(sprintf(
|
throw new SyntaxError(sprintf(
|
||||||
'Unknown argument%s "%s" for %s "%s(%s)".',
|
'Unknown argument%s "%s" for %s "%s(%s)".',
|
||||||
\count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names)
|
\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;
|
return $arguments;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class DefinedTest extends TestExpression
|
|||||||
} elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) {
|
} elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) {
|
||||||
$node = new ConstantExpression(true, $node->getTemplateLine());
|
$node = new ConstantExpression(true, $node->getTemplateLine());
|
||||||
} else {
|
} 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);
|
parent::__construct($node, $name, $arguments, $lineno);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class MacroNode extends Node
|
|||||||
{
|
{
|
||||||
foreach ($arguments as $argumentName => $argument) {
|
foreach ($arguments as $argumentName => $argument) {
|
||||||
if (self::VARARGS_NAME === $argumentName) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user