* removed support for {{ 1 < i < 3 }} (use {{ i > 1 and i < 3 }} instead)
Changes:
- * made error message for strict variables more useful
+ * added file and line to Twig_Error_Runtime exceptions thrown from Twig_Template
* changed trans tag to accept any variable for the plural count
* fixed sandbox mode (__toString() method check was not enforced if called implicitly from complex statements)
* added the ** (power) operator
*/
class Twig_Error extends Exception
{
+ protected $lineno;
+ protected $filename;
+ protected $rawMessage;
+
+ public function __construct($message, $lineno = -1, $filename = 'n/a')
+ {
+ $this->lineno = $lineno;
+ $this->filename = $filename;
+ $this->rawMessage = $message;
+
+ $this->updateRepr();
+
+ parent::__construct($this->message);
+ }
+
+ public function getFilename()
+ {
+ return $this->filename;
+ }
+
+ public function setFilename($filename)
+ {
+ $this->filename = $filename;
+
+ $this->updateRepr();
+ }
+
+ protected function updateRepr()
+ {
+ $this->message = $this->rawMessage;
+
+ if ('n/a' != $this->filename) {
+ $this->message .= sprintf(' in %s', $this->filename);
+ }
+
+ if ($this->lineno >= 0) {
+ $this->message .= sprintf(' at line %d', $this->lineno);
+ }
+ }
}
*/
class Twig_Error_Syntax extends Twig_Error
{
- protected $lineno;
- protected $filename;
- protected $rawMessage;
-
- public function __construct($message, $lineno, $filename = null)
- {
- $this->lineno = $lineno;
- $this->filename = $filename;
- $this->rawMessage = $message;
-
- $this->updateRepr();
-
- parent::__construct($this->message, $lineno);
- }
-
- public function getFilename()
- {
- return $this->filename;
- }
-
- public function setFilename($filename)
- {
- $this->filename = $filename;
-
- $this->updateRepr();
- }
-
- protected function updateRepr()
- {
- $this->message = $this->rawMessage.' in '.($this->filename ? $this->filename : 'n/a').' at line '.$this->lineno;
- }
}
if (false !== $parent = $this->getParent($context)) {
return $parent->getBlock($name, $context, $blocks);
} else {
- throw new Twig_Error_Runtime('This template has no parent.');
+ throw new Twig_Error_Runtime('This template has no parent', -1, $this->getTemplateName());
}
}
protected function getContext($context, $item, $line = -1)
{
if (!array_key_exists($item, $context)) {
- throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist in "%s" at line %s.', $item, $this->getTemplateName(), $line));
+ throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item), $line, $this->getTemplateName());
}
return $context[$item];
return null;
}
- throw new Twig_Error_Runtime(sprintf('Key "%s" for array "%s" does not exist.', $item, $object));
+ throw new Twig_Error_Runtime(sprintf('Key "%s" for array "%s" does not exist', $item, $object), -1, $this->getTemplateName());
}
}
if (!$this->env->isStrictVariables() || $noStrictCheck) {
return null;
}
- throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist.', $item, $object));
+ throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist', $item, $object), -1, $this->getTemplateName());
}
// get some information about the object
return null;
}
- throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist.', $item, get_class($object)));
+ throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName());
}
if ($this->env->hasExtension('sandbox')) {