From: Fabien Potencier Date: Sun, 7 Nov 2010 21:18:31 +0000 (+0100) Subject: moved all exceptions to Twig_Error_* X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=7ea98b6c90f6d853efce978e313983e3fa430a40;p=web%2Fkonrad%2Ftwig.git moved all exceptions to Twig_Error_* --- diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 4b91a34..c0d94c2 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -308,7 +308,7 @@ class Twig_Environment public function getExtension($name) { if (!isset($this->extensions[$name])) { - throw new LogicException(sprintf('The "%s" extension is not enabled.', $name)); + throw new Twig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $name)); } return $this->extensions[$name]; @@ -357,7 +357,7 @@ class Twig_Environment } else if ($parser instanceof Twig_TokenParserBrokerInterface) { $this->parsers->addTokenParserBroker($parser); } else { - throw new InvalidArgumentException('getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances'); + throw new Twig_Error_Runtime('getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances'); } } } @@ -441,6 +441,6 @@ class Twig_Environment } } - throw new RuntimeException(sprintf('Failed to write cache file "%s".', $file)); + throw new Twig_Error_Runtime(sprintf('Failed to write cache file "%s".', $file)); } } diff --git a/lib/Twig/RuntimeError.php b/lib/Twig/Error/Loader.php similarity index 65% copy from lib/Twig/RuntimeError.php copy to lib/Twig/Error/Loader.php index f2b90e3..facaf2d 100644 --- a/lib/Twig/RuntimeError.php +++ b/lib/Twig/Error/Loader.php @@ -3,19 +3,18 @@ /* * This file is part of Twig. * - * (c) 2009 Fabien Potencier - * (c) 2009 Armin Ronacher + * (c) 2010 Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** - * Exception thrown when an error occurs at runtime. + * Exception thrown when an error occurs during template loading. * * @package twig * @author Fabien Potencier */ -class Twig_RuntimeError extends Twig_Error +class Twig_Error_Loader extends Twig_Error { } diff --git a/lib/Twig/RuntimeError.php b/lib/Twig/Error/Runtime.php similarity index 89% rename from lib/Twig/RuntimeError.php rename to lib/Twig/Error/Runtime.php index f2b90e3..262f8f0 100644 --- a/lib/Twig/RuntimeError.php +++ b/lib/Twig/Error/Runtime.php @@ -16,6 +16,6 @@ * @package twig * @author Fabien Potencier */ -class Twig_RuntimeError extends Twig_Error +class Twig_Error_Runtime extends Twig_Error { } diff --git a/lib/Twig/SyntaxError.php b/lib/Twig/Error/Syntax.php similarity index 96% rename from lib/Twig/SyntaxError.php rename to lib/Twig/Error/Syntax.php index 591f6fc..7ef10ff 100644 --- a/lib/Twig/SyntaxError.php +++ b/lib/Twig/Error/Syntax.php @@ -16,7 +16,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_SyntaxError extends Twig_Error +class Twig_Error_Syntax extends Twig_Error { protected $lineno; protected $filename; diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 137f084..8a76372 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -288,7 +288,7 @@ class Twig_ExpressionParser $node = $this->parseExpression(); $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ')'); } else { - throw new Twig_SyntaxError(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::getTypeAsString($token->getType()), $token->getValue()), $token->getLine()); + throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::getTypeAsString($token->getType()), $token->getValue()), $token->getLine()); } } @@ -424,7 +424,7 @@ class Twig_ExpressionParser $arguments = new Twig_Node(); } } else { - throw new Twig_SyntaxError('Expected name or number', $lineno); + throw new Twig_Error_Syntax('Expected name or number', $lineno); } } else { $type = Twig_Node_Expression_GetAttr::TYPE_ARRAY; diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 72d1735..c061c1f 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -235,7 +235,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $type = 'html') } if (null === $string = preg_replace_callback('#[^\p{L}\p{N} ]#u', '_twig_escape_js_callback', $string)) { - throw new InvalidArgumentException('The string to escape is not a valid UTF-8 string.'); + throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); } if ('UTF-8' != $charset) { @@ -248,7 +248,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $type = 'html') return htmlspecialchars($string, ENT_QUOTES, $env->getCharset()); default: - throw new Exception(sprintf('Invalid escape type "%s".', $type)); + throw new Twig_Error_Runtime(sprintf('Invalid escape type "%s".', $type)); } } @@ -280,7 +280,7 @@ if (function_exists('iconv')) { } else { function _twig_convert_encoding($string, $to, $from) { - throw new RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); + throw new Twig_Error_Runtime('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); } } diff --git a/lib/Twig/Grammar/Switch.php b/lib/Twig/Grammar/Switch.php new file mode 100644 index 0000000..c5e5ff8 --- /dev/null +++ b/lib/Twig/Grammar/Switch.php @@ -0,0 +1,24 @@ +', $this->name); + } + + public function parse(Twig_Token $token) + { + $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, $this->name); + + return new Twig_Node_Expression_Constant(true, $token->getLine()); + } +} diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 4157b77..c3a2bcf 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -198,7 +198,7 @@ class Twig_Lexer implements Twig_LexerInterface switch ($token) { case $this->options['tag_comment'][0]: if (!preg_match('/(.*?)'.preg_quote($this->options['tag_comment'][1], '/').'/As', $this->code, $match, null, $this->cursor)) { - throw new Twig_SyntaxError('unclosed comment', $this->lineno, $this->filename); + throw new Twig_Error_Syntax('unclosed comment', $this->lineno, $this->filename); } $this->moveCursor($match[0]); $this->moveLineNo($match[0]); @@ -266,7 +266,7 @@ class Twig_Lexer implements Twig_LexerInterface // sanity check if ($this->cursor >= $this->end) { - throw new Twig_SyntaxError('Unexpected end of stream', $this->lineno, $this->filename); + throw new Twig_Error_Syntax('Unexpected end of stream', $this->lineno, $this->filename); } // first parse operators @@ -301,7 +301,7 @@ class Twig_Lexer implements Twig_LexerInterface } // unlexable - throw new Twig_SyntaxError(sprintf("Unexpected character '%s'", $this->code[$this->cursor]), $this->lineno, $this->filename); + throw new Twig_Error_Syntax(sprintf("Unexpected character '%s'", $this->code[$this->cursor]), $this->lineno, $this->filename); } protected function moveLineNo($text) diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index 16cb2a9..8b74310 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -49,7 +49,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface public function getSource($name) { if (!isset($this->templates[$name])) { - throw new LogicException(sprintf('Template "%s" is not defined.', $name)); + throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); } return $this->templates[$name]; @@ -65,7 +65,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface public function getCacheKey($name) { if (!isset($this->templates[$name])) { - throw new LogicException(sprintf('Template "%s" is not defined.', $name)); + throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); } return $this->templates[$name]; diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index b993d29..91d8844 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -57,7 +57,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface $this->paths = array(); foreach ($paths as $path) { if (!is_dir($path)) { - throw new InvalidArgumentException(sprintf('The "%s" directory does not exist.', $path)); + throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path)); } $this->paths[] = realpath($path); @@ -114,12 +114,12 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface // simple security check if (0 !== strpos($file, $path)) { - throw new RuntimeException('Looks like you try to load a template outside configured directories.'); + throw new Twig_Error_Loader('Looks like you try to load a template outside configured directories.'); } return $this->cache[$name] = $file; } - throw new RuntimeException(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths))); + throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths))); } } diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index 632e563..350896c 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -139,7 +139,7 @@ class Twig_Node implements Twig_NodeInterface, Countable, IteratorAggregate public function getAttribute($name) { if (!array_key_exists($name, $this->attributes)) { - throw new InvalidArgumentException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this))); + throw new Twig_Error_Runtime(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this))); } return $this->attributes[$name]; @@ -188,7 +188,7 @@ class Twig_Node implements Twig_NodeInterface, Countable, IteratorAggregate public function getNode($name) { if (!array_key_exists($name, $this->nodes)) { - throw new InvalidArgumentException(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this))); + throw new Twig_Error_Runtime(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this))); } return $this->nodes[$name]; diff --git a/lib/Twig/Node/Expression/Filter.php b/lib/Twig/Node/Expression/Filter.php index 204e791..a291a05 100644 --- a/lib/Twig/Node/Expression/Filter.php +++ b/lib/Twig/Node/Expression/Filter.php @@ -25,7 +25,7 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression $name = $this->getNode('filters')->getNode($i - 1)->getAttribute('value'); $attrs = $this->getNode('filters')->getNode($i); if (!isset($filterMap[$name])) { - throw new Twig_SyntaxError(sprintf('The filter "%s" does not exist', $name), $this->getLine()); + throw new Twig_Error_Syntax(sprintf('The filter "%s" does not exist', $name), $this->getLine()); } else { $compiler->raw($filterMap[$name]->compile().($filterMap[$name]->needsEnvironment() ? '($this->env, ' : '(')); } diff --git a/lib/Twig/Node/Expression/Test.php b/lib/Twig/Node/Expression/Test.php index 1b34039..1354dc5 100644 --- a/lib/Twig/Node/Expression/Test.php +++ b/lib/Twig/Node/Expression/Test.php @@ -19,7 +19,7 @@ class Twig_Node_Expression_Test extends Twig_Node_Expression { $testMap = $compiler->getEnvironment()->getTests(); if (!isset($testMap[$this->getAttribute('name')])) { - throw new Twig_SyntaxError(sprintf('The test "%s" does not exist', $this->getAttribute('name')), $this->getLine()); + throw new Twig_Error_Syntax(sprintf('The test "%s" does not exist', $this->getAttribute('name')), $this->getLine()); } $compiler diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index dfe8242..c79a476 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -61,7 +61,7 @@ class Twig_Parser implements Twig_ParserInterface try { $body = $this->subparse(null); - } catch (Twig_SyntaxError $e) { + } catch (Twig_Error_Syntax $e) { if (is_null($e->getFilename())) { $e->setFilename($this->stream->getFilename()); } @@ -103,7 +103,7 @@ class Twig_Parser implements Twig_ParserInterface $token = $this->getCurrentToken(); if ($token->getType() !== Twig_Token::NAME_TYPE) { - throw new Twig_SyntaxError('A block must start with a tag name', $token->getLine()); + throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine()); } if (!is_null($test) && call_user_func($test, $token)) { @@ -116,7 +116,7 @@ class Twig_Parser implements Twig_ParserInterface $subparser = $this->handlers->getTokenParser($token->getValue()); if (null === $subparser) { - throw new Twig_SyntaxError(sprintf('Unknown tag name "%s"', $token->getValue()), $token->getLine()); + throw new Twig_Error_Syntax(sprintf('Unknown tag name "%s"', $token->getValue()), $token->getLine()); } $this->stream->next(); @@ -128,7 +128,7 @@ class Twig_Parser implements Twig_ParserInterface break; default: - throw new LogicException('Lexer or parser ended up in unsupported state.'); + throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.'); } } @@ -220,7 +220,7 @@ class Twig_Parser implements Twig_ParserInterface || (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && !$node instanceof Twig_Node_Import) ) { - throw new Twig_SyntaxError('A template that extends another one cannot have a body', $node->getLine(), $this->stream->getFilename()); + throw new Twig_Error_Syntax('A template that extends another one cannot have a body', $node->getLine(), $this->stream->getFilename()); } } } diff --git a/lib/Twig/SimpleTokenParser.php b/lib/Twig/SimpleTokenParser.php index 9a12ef5..9a681cb 100644 --- a/lib/Twig/SimpleTokenParser.php +++ b/lib/Twig/SimpleTokenParser.php @@ -104,7 +104,7 @@ abstract class Twig_SimpleTokenParser extends Twig_TokenParser } elseif (preg_match('/<(\w+)(?:\:(\w+))?>/A', $str, $match, null, $cursor)) { $class = sprintf('Twig_Grammar_%s', ucfirst(isset($match[2]) ? $match[2] : 'Expression')); if (!class_exists($class)) { - throw new InvalidArgumentException(sprintf('Unable to understand "%s" in grammar (%s class does not exist)', $match[0], $class)); + throw new Twig_Error_Runtime(sprintf('Unable to understand "%s" in grammar (%s class does not exist)', $match[0], $class)); } $grammar->addGrammar(new $class($match[1])); $cursor += strlen($match[0]); @@ -119,7 +119,7 @@ abstract class Twig_SimpleTokenParser extends Twig_TokenParser return $grammar; } else { - throw new InvalidArgumentException(sprintf('Unable to parse grammar "%s" near "...%s..."', $str, substr($str, $cursor, 10))); + throw new Twig_Error_Runtime(sprintf('Unable to parse grammar "%s" near "...%s..."', $str, substr($str, $cursor, 10))); } } diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 8e5abe0..2e4fd2f 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -37,7 +37,7 @@ abstract class Twig_Template implements Twig_TemplateInterface if (false !== $parent = $this->getParent($context)) { return $parent->getBlock($name, $context, $blocks); } else { - throw new LogicException('This template has no parent.'); + throw new Twig_Error_Runtime('This template has no parent.'); } } @@ -90,7 +90,7 @@ abstract class Twig_Template implements Twig_TemplateInterface protected function getContext($context, $item) { if (!array_key_exists($item, $context)) { - throw new InvalidArgumentException(sprintf('Variable "%s" does not exist.', $item)); + throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist.', $item)); } return $context[$item]; @@ -109,7 +109,7 @@ abstract class Twig_Template implements Twig_TemplateInterface return null; } - throw new InvalidArgumentException(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)); } } @@ -118,7 +118,7 @@ abstract class Twig_Template implements Twig_TemplateInterface return null; } - throw new InvalidArgumentException(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)); } // get some information about the object @@ -159,7 +159,7 @@ abstract class Twig_Template implements Twig_TemplateInterface return null; } - throw new InvalidArgumentException(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))); } if ($this->env->hasExtension('sandbox')) { diff --git a/lib/Twig/Token.php b/lib/Twig/Token.php index e900850..3b36b66 100644 --- a/lib/Twig/Token.php +++ b/lib/Twig/Token.php @@ -113,7 +113,7 @@ class Twig_Token $name = 'OPERATOR_TYPE'; break; default: - throw new InvalidArgumentException(sprintf('Token of type %s does not exist.', $type)); + throw new Twig_Error_Syntax(sprintf('Token of type %s does not exist.', $type)); } return $short ? $name : 'Twig_Token::'.$name; diff --git a/lib/Twig/TokenParser/AutoEscape.php b/lib/Twig/TokenParser/AutoEscape.php index ac3791b..43bccb0 100644 --- a/lib/Twig/TokenParser/AutoEscape.php +++ b/lib/Twig/TokenParser/AutoEscape.php @@ -22,13 +22,13 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser $lineno = $token->getLine(); $value = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); if (!in_array($value, array('on', 'off'))) { - throw new Twig_SyntaxError("Autoescape value must be 'on' or 'off'", $lineno); + throw new Twig_Error_Syntax("Autoescape value must be 'on' or 'off'", $lineno); } $value = 'on' === $value ? 'html' : false; if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE)) { if (false === $value) { - throw new Twig_SyntaxError(sprintf('Unexpected escaping strategy as you set autoescaping to off.', $lineno), -1); + throw new Twig_Error_Syntax(sprintf('Unexpected escaping strategy as you set autoescaping to off.', $lineno), -1); } $value = $this->parser->getStream()->next()->getValue(); diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php index ab80c3e..37d6457 100644 --- a/lib/Twig/TokenParser/Block.php +++ b/lib/Twig/TokenParser/Block.php @@ -24,7 +24,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser $stream = $this->parser->getStream(); $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); if ($this->parser->hasBlock($name)) { - throw new Twig_SyntaxError("The block '$name' has already been defined", $lineno); + throw new Twig_Error_Syntax("The block '$name' has already been defined", $lineno); } $this->parser->pushBlockStack($name); @@ -36,7 +36,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser $value = $stream->next()->getValue(); if ($value != $name) { - throw new Twig_SyntaxError(sprintf("Expected endblock for block '$name' (but %s given)", $value), $lineno); + throw new Twig_Error_Syntax(sprintf("Expected endblock for block '$name' (but %s given)", $value), $lineno); } } } else { diff --git a/lib/Twig/TokenParser/Extends.php b/lib/Twig/TokenParser/Extends.php index 69722fe..8115aa7 100644 --- a/lib/Twig/TokenParser/Extends.php +++ b/lib/Twig/TokenParser/Extends.php @@ -21,7 +21,7 @@ class Twig_TokenParser_Extends extends Twig_TokenParser public function parse(Twig_Token $token) { if (null !== $this->parser->getParent()) { - throw new Twig_SyntaxError('Multiple extends tags are forbidden', $token->getLine()); + throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine()); } $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); diff --git a/lib/Twig/TokenParser/If.php b/lib/Twig/TokenParser/If.php index 2cc61b9..1621c13 100644 --- a/lib/Twig/TokenParser/If.php +++ b/lib/Twig/TokenParser/If.php @@ -48,7 +48,7 @@ class Twig_TokenParser_If extends Twig_TokenParser break; default: - throw new Twig_SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), -1); + throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), -1); } } diff --git a/lib/Twig/TokenParser/Parent.php b/lib/Twig/TokenParser/Parent.php index 7867cb4..d9204e6 100644 --- a/lib/Twig/TokenParser/Parent.php +++ b/lib/Twig/TokenParser/Parent.php @@ -21,7 +21,7 @@ class Twig_TokenParser_Parent extends Twig_TokenParser public function parse(Twig_Token $token) { if (!count($this->parser->getBlockStack())) { - throw new Twig_SyntaxError('Calling "parent" outside a block is forbidden', $token->getLine()); + throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden', $token->getLine()); } $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); diff --git a/lib/Twig/TokenParser/Set.php b/lib/Twig/TokenParser/Set.php index 04bc178..7bf935e 100644 --- a/lib/Twig/TokenParser/Set.php +++ b/lib/Twig/TokenParser/Set.php @@ -31,13 +31,13 @@ class Twig_TokenParser_Set extends Twig_TokenParser $stream->expect(Twig_Token::BLOCK_END_TYPE); if (count($names) !== count($values)) { - throw new Twig_SyntaxError("When using set, you must have the same number of variables and assignements.", $lineno); + throw new Twig_Error_Syntax("When using set, you must have the same number of variables and assignements.", $lineno); } } else { $capture = true; if (count($names) > 1) { - throw new Twig_SyntaxError("When using set with a block, you cannot have a multi-target.", $lineno); + throw new Twig_Error_Syntax("When using set with a block, you cannot have a multi-target.", $lineno); } $stream->expect(Twig_Token::BLOCK_END_TYPE); diff --git a/lib/Twig/TokenParser/Trans.php b/lib/Twig/TokenParser/Trans.php index f520c25..d542417 100644 --- a/lib/Twig/TokenParser/Trans.php +++ b/lib/Twig/TokenParser/Trans.php @@ -74,7 +74,7 @@ class Twig_TokenParser_Trans extends Twig_TokenParser continue; } - throw new Twig_SyntaxError(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno); + throw new Twig_Error_Syntax(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno); } } } diff --git a/lib/Twig/TokenParserBroker.php b/lib/Twig/TokenParserBroker.php index 07b80f3..163620d 100644 --- a/lib/Twig/TokenParserBroker.php +++ b/lib/Twig/TokenParserBroker.php @@ -32,15 +32,13 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface { foreach($parsers as $parser) { if (!$parser instanceof Twig_TokenParserInterface) { - throw new InvalidArgumentException( - '$parsers must a an array of Twig_TokenParserInterface'); + throw new Twig_Error('$parsers must a an array of Twig_TokenParserInterface'); } $this->parsers[$parser->getTag()] = $parser; } foreach($brokers as $broker) { if (!$broker instanceof Twig_TokenParserBrokerInterface) { - throw new InvalidArgumentException( - '$brokers must a an array of Twig_TokenParserBrokerInterface'); + throw new Twig_Error('$brokers must a an array of Twig_TokenParserBrokerInterface'); } $this->brokers[] = $broker; } diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index 5974014..fa32497 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -60,7 +60,7 @@ class Twig_TokenStream } if (null === $token) { - throw new Twig_SyntaxError('Unexpected end of template', -1); + throw new Twig_Error_Syntax('Unexpected end of template', -1); } // trim blocks @@ -124,7 +124,7 @@ class Twig_TokenStream { $token = $this->current; if (!$token->test($primary, $secondary)) { - throw new Twig_SyntaxError(sprintf('Unexpected token "%s" of value "%s" ("%s" expected%s)', + throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s" ("%s" expected%s)', Twig_Token::getTypeAsString($token->getType()), $token->getValue(), Twig_Token::getTypeAsString($primary), $secondary ? sprintf(' with value "%s"', $secondary) : ''), $this->current->getLine() diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php index 1134d90..42e58d0 100644 --- a/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/test/Twig/Tests/Node/Expression/FilterTest.php @@ -146,7 +146,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Tests_Node_TestCase $node->compile($this->getCompiler()); $this->fail(); } catch (Exception $e) { - $this->assertEquals('Twig_SyntaxError', get_class($e)); + $this->assertEquals('Twig_Error_Syntax', get_class($e)); } } diff --git a/test/Twig/Tests/SimpleTokenParserTest.php b/test/Twig/Tests/SimpleTokenParserTest.php index 8ccb4c7..a1abbfe 100644 --- a/test/Twig/Tests/SimpleTokenParserTest.php +++ b/test/Twig/Tests/SimpleTokenParserTest.php @@ -25,21 +25,21 @@ class Twig_Tests_SimpleTokenParserTest extends PHPUnit_Framework_TestCase Twig_SimpleTokenParser::parseGrammar(''); $this->fail(); } catch (Exception $e) { - $this->assertEquals('InvalidArgumentException', get_class($e)); + $this->assertEquals('Twig_Error_Runtime', get_class($e)); } try { Twig_SimpleTokenParser::parseGrammar('fail(); } catch (Exception $e) { - $this->assertEquals('InvalidArgumentException', get_class($e)); + $this->assertEquals('Twig_Error_Runtime', get_class($e)); } try { Twig_SimpleTokenParser::parseGrammar(' (with'); $this->fail(); } catch (Exception $e) { - $this->assertEquals('InvalidArgumentException', get_class($e)); + $this->assertEquals('Twig_Error_Runtime', get_class($e)); } } diff --git a/test/Twig/Tests/grammarTest.php b/test/Twig/Tests/grammarTest.php index 11bd95a..0a63d13 100644 --- a/test/Twig/Tests/grammarTest.php +++ b/test/Twig/Tests/grammarTest.php @@ -48,12 +48,12 @@ class grammarTest extends PHPUnit_Framework_TestCase { return array( array('foo1', '', '{% foo1 %}', '|', false), - array('foo2', '', '{% foo2 "bar" %}', '|', 'Twig_SyntaxError'), + array('foo2', '', '{% foo2 "bar" %}', '|', 'Twig_Error_Syntax'), array('foo3', '', '{% foo3 "bar" %}', '|bar|', false), array('foo4', '', '{% foo4 1 + 2 %}', '|3|', false), array('foo5', '', '{% foo5 1 + 2 %}', '|3|', false), - array('foo6', '', '{% foo6 1 + 2 %}', '|3|', 'Twig_SyntaxError'), - array('foo7', '', '{% foo7 %}', '|3|', 'Twig_SyntaxError'), + array('foo6', '', '{% foo6 1 + 2 %}', '|3|', 'Twig_Error_Syntax'), + array('foo7', '', '{% foo7 %}', '|3|', 'Twig_Error_Syntax'), array('foo8', '', '{% foo8 [1, 2] %}', '|Array|', false), array('foo9', ' with ', '{% foo9 "bar" with "foobar" %}', '|bar|with|foobar|', false), array('foo10', ' [with ]', '{% foo10 "bar" with "foobar" %}', '|bar|with|foobar|', false),