diff --git a/doc/advanced.rst b/doc/advanced.rst index 7d05883f0e..6b9253a4c9 100644 --- a/doc/advanced.rst +++ b/doc/advanced.rst @@ -114,7 +114,7 @@ Globals A global variable is like any other template variable, except that it's available in all templates and macros:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addGlobal('text', new Text()); You can then use the ``text`` variable anywhere in a template: @@ -129,29 +129,29 @@ Filters Creating a filter is as simple as associating a name with a PHP callable:: // an anonymous function - $filter = new Twig_SimpleFilter('rot13', function ($string) { + $filter = new \Twig\TwigFilter('rot13', function ($string) { return str_rot13($string); }); // or a simple PHP function - $filter = new Twig_SimpleFilter('rot13', 'str_rot13'); + $filter = new \Twig\TwigFilter('rot13', 'str_rot13'); // or a class static method - $filter = new Twig_SimpleFilter('rot13', ['SomeClass', 'rot13Filter']); - $filter = new Twig_SimpleFilter('rot13', 'SomeClass::rot13Filter'); + $filter = new \Twig\TwigFilter('rot13', ['SomeClass', 'rot13Filter']); + $filter = new \Twig\TwigFilter('rot13', 'SomeClass::rot13Filter'); // or a class method - $filter = new Twig_SimpleFilter('rot13', [$this, 'rot13Filter']); + $filter = new \Twig\TwigFilter('rot13', [$this, 'rot13Filter']); // the one below needs a runtime implementation (see below for more information) - $filter = new Twig_SimpleFilter('rot13', ['SomeClass', 'rot13Filter']); + $filter = new \Twig\TwigFilter('rot13', ['SomeClass', 'rot13Filter']); -The first argument passed to the ``Twig_SimpleFilter`` constructor is the name +The first argument passed to the ``\Twig\TwigFilter`` constructor is the name of the filter you will use in templates and the second one is the PHP callable to associate with it. Then, add the filter to your Twig environment:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addFilter($filter); And here is how to use it in a template: @@ -178,10 +178,10 @@ is compiled to something like the following:: -The ``Twig_SimpleFilter`` class takes an array of options as its last +The ``\Twig\TwigFilter`` class takes an array of options as its last argument:: - $filter = new Twig_SimpleFilter('rot13', 'str_rot13', $options); + $filter = new \Twig\TwigFilter('rot13', 'str_rot13', $options); Environment-aware Filters ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -190,7 +190,7 @@ If you want to access the current environment instance in your filter, set the ``needs_environment`` option to ``true``; Twig will pass the current environment as the first argument to the filter call:: - $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $string) { + $filter = new \Twig\TwigFilter('rot13', function (Twig_Environment $env, $string) { // get the current charset for instance $charset = $env->getCharset(); @@ -205,11 +205,11 @@ If you want to access the current context in your filter, set the the first argument to the filter call (or the second one if ``needs_environment`` is also set to ``true``):: - $filter = new Twig_SimpleFilter('rot13', function ($context, $string) { + $filter = new \Twig\TwigFilter('rot13', function ($context, $string) { // ... }, ['needs_context' => true]); - $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $context, $string) { + $filter = new \Twig\TwigFilter('rot13', function (Twig_Environment $env, $context, $string) { // ... }, ['needs_context' => true, 'needs_environment' => true]); @@ -221,14 +221,14 @@ before printing. If your filter acts as an escaper (or explicitly outputs HTML or JavaScript code), you will want the raw output to be printed. In such a case, set the ``is_safe`` option:: - $filter = new Twig_SimpleFilter('nl2br', 'nl2br', ['is_safe' => ['html']]); + $filter = new \Twig\TwigFilter('nl2br', 'nl2br', ['is_safe' => ['html']]); Some filters may need to work on input that is already escaped or safe, for example when adding (safe) HTML tags to originally unsafe output. In such a case, set the ``pre_escape`` option to escape the input data before it is run through your filter:: - $filter = new Twig_SimpleFilter('somefilter', 'somefilter', ['pre_escape' => 'html', 'is_safe' => ['html']]); + $filter = new \Twig\TwigFilter('somefilter', 'somefilter', ['pre_escape' => 'html', 'is_safe' => ['html']]); Variadic Filters ~~~~~~~~~~~~~~~~ @@ -240,7 +240,7 @@ When a filter should accept an arbitrary number of arguments, set the ``is_variadic`` option to ``true``; Twig will pass the extra arguments as the last argument to the filter call as an array:: - $filter = new Twig_SimpleFilter('thumbnail', function ($file, array $options = []) { + $filter = new \Twig\TwigFilter('thumbnail', function ($file, array $options = []) { // ... }, ['is_variadic' => true]); @@ -254,7 +254,7 @@ Dynamic Filters A filter name containing the special ``*`` character is a dynamic filter as the ``*`` can be any string:: - $filter = new Twig_SimpleFilter('*_path', function ($name, $arguments) { + $filter = new \Twig\TwigFilter('*_path', function ($name, $arguments) { // ... }); @@ -265,7 +265,7 @@ The following filters will be matched by the above defined dynamic filter: A dynamic filter can define more than one dynamic parts:: - $filter = new Twig_SimpleFilter('*_path_*', function ($name, $suffix, $arguments) { + $filter = new \Twig\TwigFilter('*_path_*', function ($name, $suffix, $arguments) { // ... }); @@ -284,7 +284,7 @@ You can mark a filter as being deprecated by setting the ``deprecated`` option to ``true``. You can also give an alternative filter that replaces the deprecated one when that makes sense:: - $filter = new Twig_SimpleFilter('obsolete', function () { + $filter = new \Twig\TwigFilter('obsolete', function () { // ... }, ['deprecated' => true, 'alternative' => 'new_one']); @@ -295,10 +295,10 @@ Functions --------- Functions are defined in the exact same way as filters, but you need to create -an instance of ``Twig_SimpleFunction``:: +an instance of ``\Twig\TwigFunction``:: - $twig = new Twig_Environment($loader); - $function = new Twig_SimpleFunction('function_name', function () { + $twig = new \Twig\Environment($loader); + $function = new \Twig\TwigFunction('function_name', function () { // ... }); $twig->addFunction($function); @@ -310,10 +310,10 @@ Tests ----- Tests are defined in the exact same way as filters and functions, but you need -to create an instance of ``Twig_SimpleTest``:: +to create an instance of ``\Twig\TwigTest``:: - $twig = new Twig_Environment($loader); - $test = new Twig_SimpleTest('test_name', function () { + $twig = new \Twig\Environment($loader); + $test = new \Twig\TwigTest('test_name', function () { // ... }); $twig->addTest($test); @@ -322,8 +322,8 @@ Tests allow you to create custom application specific logic for evaluating boolean conditions. As a simple example, let's create a Twig test that checks if objects are 'red':: - $twig = new Twig_Environment($loader); - $test = new Twig_SimpleTest('red', function ($value) { + $twig = new \Twig\Environment($loader); + $test = new \Twig\TwigTest('red', function ($value) { if (isset($value->color) && $value->color == 'red') { return true; } @@ -340,16 +340,16 @@ When creating tests you can use the ``node_class`` option to provide custom test compilation. This is useful if your test can be compiled into PHP primitives. This is used by many of the tests built into Twig:: - $twig = new Twig_Environment($loader); - $test = new Twig_SimpleTest( + $twig = new \Twig\Environment($loader); + $test = new \Twig\TwigTest( 'odd', null, - ['node_class' => 'Twig_Node_Expression_Test_Odd']); + ['node_class' => '\Twig\Node\Expression\Test\OddTest']); $twig->addTest($test); - class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test + class Twig_Node_Expression_Test_Odd extends \Twig\Node\Expression\TestExpression { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('(') @@ -416,9 +416,9 @@ Registering a new tag ~~~~~~~~~~~~~~~~~~~~~ Adding a tag is as simple as calling the ``addTokenParser`` method on the -``Twig_Environment`` instance:: +``\Twig\Environment`` instance:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addTokenParser(new Project_Set_TokenParser()); Defining a Token Parser @@ -426,17 +426,17 @@ Defining a Token Parser Now, let's see the actual code of this class:: - class Project_Set_TokenParser extends Twig_TokenParser + class Project_Set_TokenParser extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $parser = $this->parser; $stream = $parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - $stream->expect(Twig_Token::OPERATOR_TYPE, '='); + $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); + $stream->expect(\Twig\Token::OPERATOR_TYPE, '='); $value = $parser->getExpressionParser()->parseExpression(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); return new Project_Set_Node($name, $value, $token->getLine(), $this->getTag()); } @@ -450,7 +450,7 @@ Now, let's see the actual code of this class:: The ``getTag()`` method must return the tag we want to parse, here ``set``. The ``parse()`` method is invoked whenever the parser encounters a ``set`` -tag. It should return a ``Twig_Node`` instance that represents the node (the +tag. It should return a ``\Twig\Node\Node`` instance that represents the node (the ``Project_Set_Node`` calls creating is explained in the next section). The parsing process is simplified thanks to a bunch of methods you can call @@ -483,14 +483,14 @@ Defining a Node The ``Project_Set_Node`` class itself is rather simple:: - class Project_Set_Node extends Twig_Node + class Project_Set_Node extends \Twig\Node\Node { - public function __construct($name, Twig_Node_Expression $value, $line, $tag = null) + public function __construct($name, \Twig\Node\Expression\AbstractExpression $value, $line, $tag = null) { parent::__construct(['value' => $value], ['name' => $name], $line, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) @@ -514,15 +514,15 @@ developer generate beautiful and readable PHP code: * ``string()``: Writes a quoted string. * ``repr()``: Writes a PHP representation of a given value (see - ``Twig_Node_For`` for a usage example). + ``\Twig\Node\ForNode`` for a usage example). * ``addDebugInfo()``: Adds the line of the original template file related to the current node as a comment. -* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a +* ``indent()``: Indents the generated code (see ``\Twig\Node\BlockNode`` for a usage example). -* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a +* ``outdent()``: Outdents the generated code (see ``\Twig\Node\BlockNode`` for a usage example). .. _creating_extensions: @@ -560,7 +560,7 @@ An extension is a class that implements the following interface:: * * @deprecated since 1.23 (to be removed in 2.0), implement \Twig\Extension\InitRuntimeInterface instead */ - function initRuntime(Twig_Environment $environment); + function initRuntime(\Twig\Environment $environment); /** * Returns the token parser instances to add to the existing list. @@ -572,28 +572,28 @@ An extension is a class that implements the following interface:: /** * Returns the node visitor instances to add to the existing list. * - * @return Twig_NodeVisitorInterface[] + * @return \Twig\NodeVisitor\NodeVisitorInterface[] */ function getNodeVisitors(); /** * Returns a list of filters to add to the existing list. * - * @return Twig_SimpleFilter[] + * @return \Twig\TwigFilter[] */ function getFilters(); /** * Returns a list of tests to add to the existing list. * - * @return Twig_SimpleTest[] + * @return \Twig\TwigTest[] */ function getTests(); /** * Returns a list of functions to add to the existing list. * - * @return Twig_SimpleFunction[] + * @return \Twig\TwigFunction[] */ function getFunctions(); @@ -624,10 +624,10 @@ An extension is a class that implements the following interface:: } To keep your extension class clean and lean, inherit from the built-in -``Twig_Extension`` class instead of implementing the interface as it provides +``\Twig\Extension\AbstractExtension`` class instead of implementing the interface as it provides empty implementations for all methods: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { } @@ -645,7 +645,7 @@ extensions must be registered explicitly to be available in your templates. You can register an extension by using the ``addExtension()`` method on your main ``Environment`` object:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addExtension(new Project_Twig_Extension()); .. tip:: @@ -658,7 +658,7 @@ Globals Global variables can be registered in an extension via the ``getGlobals()`` method:: - class Project_Twig_Extension extends Twig_Extension implements Twig_Extension_GlobalsInterface + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension implements \Twig\Extension\GlobalsInterface { public function getGlobals() { @@ -676,12 +676,12 @@ Functions Functions can be registered in an extension via the ``getFunctions()`` method:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getFunctions() { return [ - new Twig_SimpleFunction('lipsum', 'generate_lipsum'), + new \Twig\TwigFunction('lipsum', 'generate_lipsum'), ]; } @@ -695,12 +695,12 @@ To add a filter to an extension, you need to override the ``getFilters()`` method. This method must return an array of filters to add to the Twig environment:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getFilters() { return [ - new Twig_SimpleFilter('rot13', 'str_rot13'), + new \Twig\TwigFilter('rot13', 'str_rot13'), ]; } @@ -714,7 +714,7 @@ Adding a tag in an extension can be done by overriding the ``getTokenParsers()`` method. This method must return an array of tags to add to the Twig environment:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getTokenParsers() { @@ -734,17 +734,17 @@ Operators The ``getOperators()`` methods lets you add new operators. Here is how to add ``!``, ``||``, and ``&&`` operators:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getOperators() { return [ [ - '!' => ['precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'], + '!' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'], ], [ - '||' => ['precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '&&' => ['precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], + '||' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '&&' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], ], ]; } @@ -757,12 +757,12 @@ Tests The ``getTests()`` method lets you add new test functions:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getTests() { return [ - new Twig_SimpleTest('even', 'twig_test_even'), + new \Twig\TwigTest('even', 'twig_test_even'), ]; } @@ -786,7 +786,7 @@ any valid PHP callable: The simplest way to use methods is to define them on the extension itself:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { private $rot13Provider; @@ -798,7 +798,7 @@ The simplest way to use methods is to define them on the extension itself:: public function getFunctions() { return [ - new Twig_SimpleFunction('rot13', [$this, 'rot13']), + new \Twig\TwigFunction('rot13', [$this, 'rot13']), ]; } @@ -813,11 +813,11 @@ depend on runtime dependencies even if they are not needed (think for instance as a dependency that connects to a database engine). As of Twig 1.26, you can easily decouple the extension definitions from their -runtime implementations by registering a ``Twig_RuntimeLoaderInterface`` +runtime implementations by registering a ``\Twig\RuntimeLoader\RuntimeLoaderInterface`` instance on the environment that knows how to instantiate such runtime classes (runtime classes must be autoload-able):: - class RuntimeLoader implements Twig_RuntimeLoaderInterface + class RuntimeLoader implements \Twig\RuntimeLoader\RuntimeLoaderInterface { public function load($class) { @@ -837,7 +837,7 @@ instance on the environment that knows how to instantiate such runtime classes .. note:: As of Twig 1.32, Twig comes with a PSR-11 compatible runtime loader - (``Twig_ContainerRuntimeLoader``) that works on PHP 5.3+. + (``\Twig\RuntimeLoader\ContainerRuntimeLoader``) that works on PHP 5.3+. It is now possible to move the runtime logic to a new ``Project_Twig_RuntimeExtension`` class and use it directly in the extension:: @@ -857,14 +857,14 @@ It is now possible to move the runtime logic to a new } } - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getFunctions() { return [ - new Twig_SimpleFunction('rot13', ['Project_Twig_RuntimeExtension', 'rot13']), + new \Twig\TwigFunction('rot13', ['Project_Twig_RuntimeExtension', 'rot13']), // or - new Twig_SimpleFunction('rot13', 'Project_Twig_RuntimeExtension::rot13'), + new \Twig\TwigFunction('rot13', 'Project_Twig_RuntimeExtension::rot13'), ]; } } @@ -876,12 +876,12 @@ To overload an already defined filter, test, operator, global variable, or function, re-define it in an extension and register it **as late as possible** (order matters):: - class MyCoreExtension extends Twig_Extension + class MyCoreExtension extends \Twig\Extension\AbstractExtension { public function getFilters() { return [ - new Twig_SimpleFilter('date', [$this, 'dateFilter']), + new \Twig\TwigFilter('date', [$this, 'dateFilter']), ]; } @@ -891,16 +891,16 @@ possible** (order matters):: } } - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addExtension(new MyCoreExtension()); Here, we have overloaded the built-in ``date`` filter with a custom one. -If you do the same on the ``Twig_Environment`` itself, beware that it takes +If you do the same on the ``\Twig\Environment`` itself, beware that it takes precedence over any other registered extensions:: - $twig = new Twig_Environment($loader); - $twig->addFilter(new Twig_SimpleFilter('date', function ($timestamp, $format = 'F j, Y H:i') { + $twig = new \Twig\Environment($loader); + $twig->addFilter(new \Twig\TwigFilter('date', function ($timestamp, $format = 'F j, Y H:i') { // do something different from the built-in date filter })); // the date filter will come from the above registration, not @@ -935,7 +935,7 @@ following file structure in your test directory:: The ``IntegrationTest.php`` file should look like this:: - class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase + class Project_Tests_IntegrationTest extends \Twig\Test\IntegrationTestCase { public function getExtensions() { @@ -958,7 +958,7 @@ Node Tests ~~~~~~~~~~ Testing the node visitors can be complex, so extend your test cases from -``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository +``\Twig\Test\NodeTestCase``. Examples can be found in the Twig repository `tests/Twig/Node`_ directory. .. _`rot13`: https://secure.php.net/manual/en/function.str-rot13.php diff --git a/doc/advanced_legacy.rst b/doc/advanced_legacy.rst index 3fb8297e07..5e4f01b3cd 100644 --- a/doc/advanced_legacy.rst +++ b/doc/advanced_legacy.rst @@ -115,7 +115,7 @@ Globals A global variable is like any other template variable, except that it's available in all templates and macros:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addGlobal('text', new Text()); You can then use the ``text`` variable anywhere in a template: @@ -176,9 +176,9 @@ expected output: {# should displays Gjvt #} Adding a filter is as simple as calling the ``addFilter()`` method on the -``Twig_Environment`` instance:: +``\Twig\Environment`` instance:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addFilter('rot13', new Twig_Filter_Function('str_rot13')); The second argument of ``addFilter()`` is an instance of ``Twig_Filter``. @@ -232,7 +232,7 @@ if you want access to the current environment instance in your filter, set the Twig will then pass the current environment as the first argument to the filter call:: - function twig_compute_rot13(Twig_Environment $env, $string) + function twig_compute_rot13(\Twig\Environment $env, $string) { // get the current charset for instance $charset = $env->getCharset(); @@ -311,15 +311,15 @@ compilation, the generated PHP code is roughly equivalent to: Adding a function is similar to adding a filter. This can be done by calling the -``addFunction()`` method on the ``Twig_Environment`` instance:: +``addFunction()`` method on the ``\Twig\Environment`` instance:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addFunction('functionName', new Twig_Function_Function('someFunction')); You can also expose extension methods as functions in your templates:: - // $this is an object that implements Twig_ExtensionInterface. - $twig = new Twig_Environment($loader); + // $this is an object that implements \Twig\Extension\ExtensionInterface. + $twig = new \Twig\Environment($loader); $twig->addFunction('otherFunction', new Twig_Function_Method($this, 'someMethod')); Functions also support ``needs_environment`` and ``is_safe`` parameters. @@ -395,9 +395,9 @@ Registering a new tag ~~~~~~~~~~~~~~~~~~~~~ Adding a tag is as simple as calling the ``addTokenParser`` method on the -``Twig_Environment`` instance:: +``\Twig\Environment`` instance:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addTokenParser(new Project_Set_TokenParser()); Defining a Token Parser @@ -405,16 +405,16 @@ Defining a Token Parser Now, let's see the actual code of this class:: - class Project_Set_TokenParser extends Twig_TokenParser + class Project_Set_TokenParser extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); - $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); - $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, '='); + $name = $this->parser->getStream()->expect(\Twig\Token::NAME_TYPE)->getValue(); + $this->parser->getStream()->expect(\Twig\Token::OPERATOR_TYPE, '='); $value = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); return new Project_Set_Node($name, $value, $lineno, $this->getTag()); } @@ -428,7 +428,7 @@ Now, let's see the actual code of this class:: The ``getTag()`` method must return the tag we want to parse, here ``set``. The ``parse()`` method is invoked whenever the parser encounters a ``set`` -tag. It should return a ``Twig_Node`` instance that represents the node (the +tag. It should return a ``\Twig\Node\Node`` instance that represents the node (the ``Project_Set_Node`` calls creating is explained in the next section). The parsing process is simplified thanks to a bunch of methods you can call @@ -461,14 +461,14 @@ Defining a Node The ``Project_Set_Node`` class itself is rather simple:: - class Project_Set_Node extends Twig_Node + class Project_Set_Node extends \Twig\Node\Node { - public function __construct($name, Twig_Node_Expression $value, $lineno, $tag = null) + public function __construct($name, \Twig\Node\Expression\AbstractExpression $value, $lineno, $tag = null) { parent::__construct(['value' => $value], ['name' => $name], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) @@ -492,15 +492,15 @@ developer generate beautiful and readable PHP code: * ``string()``: Writes a quoted string. * ``repr()``: Writes a PHP representation of a given value (see - ``Twig_Node_For`` for a usage example). + ``\Twig\Node\ForNode`` for a usage example). * ``addDebugInfo()``: Adds the line of the original template file related to the current node as a comment. -* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a +* ``indent()``: Indents the generated code (see ``\Twig\Node\BlockNode`` for a usage example). -* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a +* ``outdent()``: Outdents the generated code (see ``\Twig\Node\BlockNode`` for a usage example). .. _creating_extensions: @@ -540,7 +540,7 @@ An extension is a class that implements the following interface:: * * This is where you can load some file that contains filter functions for instance. */ - function initRuntime(Twig_Environment $environment); + function initRuntime(\Twig\Environment $environment); /** * Returns the token parser instances to add to the existing list. @@ -552,28 +552,28 @@ An extension is a class that implements the following interface:: /** * Returns the node visitor instances to add to the existing list. * - * @return Twig_NodeVisitorInterface[] + * @return \Twig\NodeVisitor\NodeVisitorInterface[] */ function getNodeVisitors(); /** * Returns a list of filters to add to the existing list. * - * @return Twig_SimpleFilter[] + * @return \Twig\TwigFilter[] */ function getFilters(); /** * Returns a list of tests to add to the existing list. * - * @return Twig_SimpleTest[] + * @return \Twig\TwigTest[] */ function getTests(); /** * Returns a list of functions to add to the existing list. * - * @return Twig_SimpleFunction[] + * @return \Twig\TwigFunction[] */ function getFunctions(); @@ -600,16 +600,16 @@ An extension is a class that implements the following interface:: } To keep your extension class clean and lean, it can inherit from the built-in -``Twig_Extension`` class instead of implementing the whole interface. That +``\Twig\Extension\AbstractExtension`` class instead of implementing the whole interface. That way, you just need to implement the ``getName()`` method as the -``Twig_Extension`` provides empty implementations for all other methods. +``\Twig\Extension\AbstractExtension`` provides empty implementations for all other methods. The ``getName()`` method must return a unique identifier for your extension. Now, with this information in mind, let's create the most basic extension possible:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getName() { @@ -628,7 +628,7 @@ extensions must be registered explicitly to be available in your templates. You can register an extension by using the ``addExtension()`` method on your main ``Environment`` object:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addExtension(new Project_Twig_Extension()); Of course, you need to first load the extension file by either using @@ -644,7 +644,7 @@ Globals Global variables can be registered in an extension via the ``getGlobals()`` method:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getGlobals() { @@ -662,7 +662,7 @@ Functions Functions can be registered in an extension via the ``getFunctions()`` method:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getFunctions() { @@ -681,7 +681,7 @@ To add a filter to an extension, you need to override the ``getFilters()`` method. This method must return an array of filters to add to the Twig environment:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getFilters() { @@ -705,7 +705,7 @@ $twig->addFilter('rot13', new Twig_Filter_Function('Project_Twig_Extension::rot1 You can also use ``Twig_Filter_Method`` instead of ``Twig_Filter_Function`` when defining a filter to use a method:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getFilters() { @@ -737,7 +737,7 @@ If some default core filters do not suit your needs, you can easily override them by creating your own extension. Just use the same names as the one you want to override:: - class MyCoreExtension extends Twig_Extension + class MyCoreExtension extends \Twig\Extension\AbstractExtension { public function getFilters() { @@ -762,7 +762,7 @@ Here, we override the ``date`` filter with a custom one. Using this extension is as simple as registering the ``MyCoreExtension`` extension by calling the ``addExtension()`` method on the environment instance:: - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addExtension(new MyCoreExtension()); Tags @@ -772,7 +772,7 @@ Adding a tag in an extension can be done by overriding the ``getTokenParsers()`` method. This method must return an array of tags to add to the Twig environment:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getTokenParsers() { @@ -792,17 +792,17 @@ Operators The ``getOperators()`` methods allows to add new operators. Here is how to add ``!``, ``||``, and ``&&`` operators:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getOperators() { return [ [ - '!' => ['precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'], + '!' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'], ), [ - '||' => ['precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '&&' => ['precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], + '||' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '&&' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], ], ]; } @@ -815,7 +815,7 @@ Tests The ``getTests()`` methods allows to add new test functions:: - class Project_Twig_Extension extends Twig_Extension + class Project_Twig_Extension extends \Twig\Extension\AbstractExtension { public function getTests() { @@ -853,7 +853,7 @@ following file structure in your test directory:: The ``IntegrationTest.php`` file should look like this:: - class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase + class Project_Tests_IntegrationTest extends \Twig\Test\IntegrationTestCase { public function getExtensions() { @@ -876,7 +876,7 @@ Node Tests ~~~~~~~~~~ Testing the node visitors can be complex, so extend your test cases from -``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository +``\Twig\Test\NodeTestCase``. Examples can be found in the Twig repository `tests/Twig/Node`_ directory. .. _`spl_autoload_register()`: https://secure.php.net/spl_autoload_register diff --git a/doc/api.rst b/doc/api.rst index 5852ee8c84..d861ba4f5c 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -9,11 +9,11 @@ Basics ------ Twig uses a central object called the **environment** (of class -``Twig_Environment``). Instances of this class are used to store the +``\Twig\Environment``). Instances of this class are used to store the configuration and extensions, and are used to load templates from the file system or other locations. -Most applications will create one ``Twig_Environment`` object on application +Most applications will create one ``\Twig\Environment`` object on application initialization and use that to load templates. In some cases it's however useful to have multiple environments side by side, if different configurations are in use. @@ -24,8 +24,8 @@ looks roughly like this:: require_once '/path/to/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); - $loader = new Twig_Loader_Filesystem('/path/to/templates'); - $twig = new Twig_Environment($loader, [ + $loader = new \Twig\Loader\FilesystemLoader('/path/to/templates'); + $twig = new \Twig\Environment($loader, [ 'cache' => '/path/to/compilation_cache', ]); @@ -47,14 +47,14 @@ Rendering Templates ------------------- To load a template from a Twig environment, call the ``load()`` method which -returns a ``Twig_TemplateWrapper`` instance:: +returns a ``\Twig\TemplateWrapper`` instance:: $template = $twig->load('index.html'); .. note:: Before Twig 1.28, you should use ``loadTemplate()`` instead which returns a - ``Twig_Template`` instance. + ``\Twig\Template`` instance. To render the template with some variables, call the ``render()`` method:: @@ -81,10 +81,10 @@ If a template defines blocks, they can be rendered individually via the Environment Options ------------------- -When creating a new ``Twig_Environment`` instance, you can pass an array of +When creating a new ``\Twig\Environment`` instance, you can pass an array of options as the constructor second argument:: - $twig = new Twig_Environment($loader, ['debug' => true]); + $twig = new \Twig\Environment($loader, ['debug' => true]); The following options are available: @@ -98,7 +98,7 @@ The following options are available: The charset used by the templates. -* ``base_template_class`` *string* (defaults to ``Twig_Template``) +* ``base_template_class`` *string* (defaults to ``\Twig\Template``) The base template class to use for generated templates. @@ -158,7 +158,7 @@ Compilation Cache All template loaders can cache the compiled templates on the filesystem for future reuse. It speeds up Twig a lot as templates are only compiled once; and the performance boost is even larger if you use a PHP accelerator such as APC. -See the ``cache`` and ``auto_reload`` options of ``Twig_Environment`` above +See the ``cache`` and ``auto_reload`` options of ``\Twig\Environment`` above for more information. Built-in Loaders @@ -166,7 +166,7 @@ Built-in Loaders Here is a list of the built-in loaders Twig provides: -``Twig_Loader_Filesystem`` +``\Twig\Loader\FilesystemLoader`` .......................... .. versionadded:: 1.10 @@ -175,15 +175,15 @@ Here is a list of the built-in loaders Twig provides: .. versionadded:: 1.27 Relative paths support was added in Twig 1.27. -``Twig_Loader_Filesystem`` loads templates from the file system. This loader +``\Twig\Loader\FilesystemLoader`` loads templates from the file system. This loader can find templates in folders on the file system and is the preferred way to load them:: - $loader = new Twig_Loader_Filesystem($templateDir); + $loader = new \Twig\Loader\FilesystemLoader($templateDir); It can also look for templates in an array of directories:: - $loader = new Twig_Loader_Filesystem([$templateDir1, $templateDir2]); + $loader = new \Twig\Loader\FilesystemLoader([$templateDir1, $templateDir2]); With such a configuration, Twig will first look for templates in ``$templateDir1`` and if they do not exist, it will fallback to look for them @@ -209,28 +209,28 @@ Namespaced templates can be accessed via the special $twig->render('@admin/index.html', []); -``Twig_Loader_Filesystem`` support absolute and relative paths. Using relative +``\Twig\Loader\FilesystemLoader`` support absolute and relative paths. Using relative paths is preferred as it makes the cache keys independent of the project root directory (for instance, it allows warming the cache from a build server where the directory might be different from the one used on production servers):: - $loader = new Twig_Loader_Filesystem('templates', getcwd().'/..'); + $loader = new \Twig\Loader\FilesystemLoader('templates', getcwd().'/..'); .. note:: When not passing the root path as a second argument, Twig uses ``getcwd()`` for relative paths. -``Twig_Loader_Array`` +``\Twig\Loader\ArrayLoader`` ..................... -``Twig_Loader_Array`` loads a template from a PHP array. It's passed an array +``\Twig\Loader\ArrayLoader`` loads a template from a PHP array. It's passed an array of strings bound to template names:: - $loader = new Twig_Loader_Array([ + $loader = new \Twig\Loader\ArrayLoader([ 'index.html' => 'Hello {{ name }}!', ]); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); echo $twig->render('index.html', ['name' => 'Fabien']); @@ -245,30 +245,30 @@ projects where storing all templates in a single PHP file might make sense. don't want to see your cache grows out of control, you need to take care of clearing the old cache file by yourself. -``Twig_Loader_Chain`` +``\Twig\Loader\ChainLoader`` ..................... -``Twig_Loader_Chain`` delegates the loading of templates to other loaders:: +``\Twig\Loader\ChainLoader`` delegates the loading of templates to other loaders:: - $loader1 = new Twig_Loader_Array([ + $loader1 = new \Twig\Loader\ArrayLoader([ 'base.html' => '{% block content %}{% endblock %}', ]); - $loader2 = new Twig_Loader_Array([ + $loader2 = new \Twig\Loader\ArrayLoader([ 'index.html' => '{% extends "base.html" %}{% block content %}Hello {{ name }}{% endblock %}', 'base.html' => 'Will never be loaded', ]); - $loader = new Twig_Loader_Chain([$loader1, $loader2]); + $loader = new \Twig\Loader\ChainLoader([$loader1, $loader2]); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); When looking for a template, Twig will try each loader in turn and it will return as soon as the template is found. When rendering the ``index.html`` template from the above example, Twig will load it with ``$loader2`` but the ``base.html`` template will be loaded from ``$loader1``. -``Twig_Loader_Chain`` accepts any loader that implements -``Twig_LoaderInterface``. +``\Twig\Loader\ChainLoader`` accepts any loader that implements +``\Twig\Loader\LoaderInterface``. .. note:: @@ -277,7 +277,7 @@ template from the above example, Twig will load it with ``$loader2`` but the Create your own Loader ~~~~~~~~~~~~~~~~~~~~~~ -All loaders implement the ``Twig_LoaderInterface``:: +All loaders implement the ``\Twig\Loader\LoaderInterface``:: interface Twig_LoaderInterface { @@ -316,11 +316,11 @@ is still fresh, given the last modification time, or ``false`` otherwise. .. note:: As of Twig 1.27, you should also implement - ``Twig_SourceContextLoaderInterface`` to avoid deprecation notices. + ``\Twig\Loader\SourceContextLoaderInterface`` to avoid deprecation notices. .. tip:: - As of Twig 1.11.0, you can also implement ``Twig_ExistsLoaderInterface`` + As of Twig 1.11.0, you can also implement ``\Twig\Loader\ExistsLoaderInterface`` to make your loader faster when used with the chain loader. Using Extensions @@ -329,7 +329,7 @@ Using Extensions Twig extensions are packages that add new features to Twig. Using an extension is as simple as using the ``addExtension()`` method:: - $twig->addExtension(new Twig_Extension_Sandbox()); + $twig->addExtension(new \Twig\Extension\SandboxExtension()); Twig comes bundled with the following extensions: @@ -378,7 +378,7 @@ tag, ``autoescape``, and a filter, ``raw``. When creating the escaper extension, you can switch on or off the global output escaping strategy:: - $escaper = new Twig_Extension_Escaper('html'); + $escaper = new \Twig\Extension\EscaperExtension('html'); $twig->addExtension($escaper); If set to ``html``, all variables in templates are escaped (using the ``html`` @@ -473,7 +473,7 @@ Sandbox Extension The ``sandbox`` extension can be used to evaluate untrusted code. Access to unsafe attributes and methods is prohibited. The sandbox security is managed by a policy instance. By default, Twig comes with one policy class: -``Twig_Sandbox_SecurityPolicy``. This class allows you to white-list some +``\Twig\Sandbox\SecurityPolicy``. This class allows you to white-list some tags, filters, properties, and methods:: $tags = ['if']; @@ -485,17 +485,17 @@ tags, filters, properties, and methods:: 'Article' => ['title', 'body'], ]; $functions = ['range']; - $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions); + $policy = new \Twig\Sandbox\SecurityPolicy($tags, $filters, $methods, $properties, $functions); With the previous configuration, the security policy will only allow usage of the ``if`` tag, and the ``upper`` filter. Moreover, the templates will only be able to call the ``getTitle()`` and ``getBody()`` methods on ``Article`` objects, and the ``title`` and ``body`` public properties. Everything else -won't be allowed and will generate a ``Twig_Sandbox_SecurityError`` exception. +won't be allowed and will generate a ``\Twig\Sandbox\SecurityError`` exception. The policy object is the first argument of the sandbox constructor:: - $sandbox = new Twig_Extension_Sandbox($policy); + $sandbox = new \Twig\Extension\SandboxExtension($policy); $twig->addExtension($sandbox); By default, the sandbox mode is disabled and should be enabled when including @@ -510,7 +510,7 @@ untrusted template code by using the ``sandbox`` tag: You can sandbox all templates by passing ``true`` as the second argument of the extension constructor:: - $sandbox = new Twig_Extension_Sandbox($policy, true); + $sandbox = new \Twig\Extension\SandboxExtension($policy, true); Profiler Extension ~~~~~~~~~~~~~~~~~~ @@ -521,10 +521,10 @@ Profiler Extension The ``profiler`` extension enables a profiler for Twig templates; it should only be used on your development machines as it adds some overhead:: - $profile = new Twig_Profiler_Profile(); - $twig->addExtension(new Twig_Extension_Profiler($profile)); + $profile = new \Twig\Profiler\Profile(); + $twig->addExtension(new \Twig\Extension\ProfilerExtension($profile)); - $dumper = new Twig_Profiler_Dumper_Text(); + $dumper = new \Twig\Profiler\Dumper\TextDumper(); echo $dumper->dump($profile); A profile contains information about time and memory consumption for template, @@ -533,7 +533,7 @@ block, and macro executions. You can also dump the data in a `Blackfire.io `_ compatible format:: - $dumper = new Twig_Profiler_Dumper_Blackfire(); + $dumper = new \Twig\Profiler\Dumper\BlackfireDumper(); file_put_contents('/path/to/profile.prof', $dumper->dump($profile)); Upload the profile to visualize it (create a `free account @@ -548,27 +548,27 @@ Optimizer Extension The ``optimizer`` extension optimizes the node tree before compilation:: - $twig->addExtension(new Twig_Extension_Optimizer()); + $twig->addExtension(new \Twig\Extension\OptimizerExtension()); By default, all optimizations are turned on. You can select the ones you want to enable by passing them to the constructor:: - $optimizer = new Twig_Extension_Optimizer(Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR); + $optimizer = new \Twig\Extension\OptimizerExtension(\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_FOR); $twig->addExtension($optimizer); Twig supports the following optimizations: -* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_ALL``, enables all optimizations +* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_ALL``, enables all optimizations (this is the default value). -* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_NONE``, disables all optimizations. +* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_NONE``, disables all optimizations. This reduces the compilation time, but it can increase the execution time and the consumed memory. -* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR``, optimizes the ``for`` tag by +* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_FOR``, optimizes the ``for`` tag by removing the ``loop`` variable creation whenever possible. -* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_RAW_FILTER``, removes the ``raw`` +* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_RAW_FILTER``, removes the ``raw`` filter whenever possible. -* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_VAR_ACCESS``, simplifies the creation +* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_VAR_ACCESS``, simplifies the creation and access of variables in the compiled templates whenever possible. Exceptions @@ -576,15 +576,15 @@ Exceptions Twig can throw exceptions: -* ``Twig_Error``: The base exception for all errors. +* ``\Twig\Error\Error``: The base exception for all errors. -* ``Twig_Error_Syntax``: Thrown to tell the user that there is a problem with +* ``\Twig\Error\SyntaxError``: Thrown to tell the user that there is a problem with the template syntax. -* ``Twig_Error_Runtime``: Thrown when an error occurs at runtime (when a filter +* ``\Twig\Error\RuntimeError``: Thrown when an error occurs at runtime (when a filter does not exist for instance). -* ``Twig_Error_Loader``: Thrown when an error occurs during template loading. +* ``\Twig\Error\LoaderError``: Thrown when an error occurs during template loading. -* ``Twig_Sandbox_SecurityError``: Thrown when an unallowed tag, filter, or +* ``\Twig\Sandbox\SecurityError``: Thrown when an unallowed tag, filter, or method is called in a sandboxed template. diff --git a/doc/deprecated.rst b/doc/deprecated.rst index 8b25cc4104..135b85bb70 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -27,29 +27,29 @@ Token Parsers * ``Twig_TokenParserBrokerInterface`` * ``Twig_TokenParserBroker`` -* As of Twig 1.27, ``Twig_Parser::getFilename()`` is deprecated. From a token +* As of Twig 1.27, ``\Twig\Parser::getFilename()`` is deprecated. From a token parser, use ``$this->parser->getStream()->getSourceContext()->getPath()`` instead. -* As of Twig 1.27, ``Twig_Parser::getEnvironment()`` is deprecated. +* As of Twig 1.27, ``\Twig\Parser::getEnvironment()`` is deprecated. Extensions ---------- * As of Twig 1.x, the ability to remove an extension is deprecated and the - ``Twig_Environment::removeExtension()`` method will be removed in 2.0. + ``\Twig\Environment::removeExtension()`` method will be removed in 2.0. -* As of Twig 1.23, the ``Twig_ExtensionInterface::initRuntime()`` method is +* As of Twig 1.23, the ``\Twig\Extension\ExtensionInterface::initRuntime()`` method is deprecated. You have two options to avoid the deprecation notice: if you implement this method to store the environment for your custom filters, functions, or tests, use the ``needs_environment`` option instead; if you have more complex needs, explicitly implement - ``Twig_Extension_InitRuntimeInterface`` (not recommended). + ``\Twig\Extension\InitRuntimeInterface`` (not recommended). -* As of Twig 1.23, the ``Twig_ExtensionInterface::getGlobals()`` method is - deprecated. Implement ``Twig_Extension_GlobalsInterface`` to avoid +* As of Twig 1.23, the ``\Twig\Extension\ExtensionInterface::getGlobals()`` method is + deprecated. Implement ``\Twig\Extension\GlobalsInterface`` to avoid deprecation notices. -* As of Twig 1.26, the ``Twig_ExtensionInterface::getName()`` method is +* As of Twig 1.26, the ``\Twig\Extension\ExtensionInterface::getName()`` method is deprecated and it is not used internally anymore. PEAR @@ -61,7 +61,7 @@ provided anymore. Use Composer instead. Filters ------- -* As of Twig 1.x, use ``Twig_SimpleFilter`` to add a filter. The following +* As of Twig 1.x, use ``\Twig\TwigFilter`` to add a filter. The following classes and interfaces will be removed in 2.0: * ``Twig_FilterInterface`` @@ -71,14 +71,14 @@ Filters * ``Twig_Filter_Method`` * ``Twig_Filter_Node`` -* As of Twig 2.x, the ``Twig_SimpleFilter`` class is deprecated and will be +* As of Twig 2.x, the ``\Twig\TwigFilter`` class is deprecated and will be removed in Twig 3.x (use ``Twig_Filter`` instead). In Twig 2.x, - ``Twig_SimpleFilter`` is just an alias for ``Twig_Filter``. + ``\Twig\TwigFilter`` is just an alias for ``Twig_Filter``. Functions --------- -* As of Twig 1.x, use ``Twig_SimpleFunction`` to add a function. The following +* As of Twig 1.x, use ``\Twig\TwigFunction`` to add a function. The following classes and interfaces will be removed in 2.0: * ``Twig_FunctionInterface`` @@ -88,14 +88,14 @@ Functions * ``Twig_Function_Method`` * ``Twig_Function_Node`` -* As of Twig 2.x, the ``Twig_SimpleFunction`` class is deprecated and will be +* As of Twig 2.x, the ``\Twig\TwigFunction`` class is deprecated and will be removed in Twig 3.x (use ``Twig_Function`` instead). In Twig 2.x, - ``Twig_SimpleFunction`` is just an alias for ``Twig_Function``. + ``\Twig\TwigFunction`` is just an alias for ``Twig_Function``. Tests ----- -* As of Twig 1.x, use ``Twig_SimpleTest`` to add a test. The following classes +* As of Twig 1.x, use ``\Twig\TwigTest`` to add a test. The following classes and interfaces will be removed in 2.0: * ``Twig_TestInterface`` @@ -105,9 +105,9 @@ Tests * ``Twig_Test_Method`` * ``Twig_Test_Node`` -* As of Twig 2.x, the ``Twig_SimpleTest`` class is deprecated and will be +* As of Twig 2.x, the ``\Twig\TwigTest`` class is deprecated and will be removed in Twig 3.x (use ``Twig_Test`` instead). In Twig 2.x, - ``Twig_SimpleTest`` is just an alias for ``Twig_Test``. + ``\Twig\TwigTest`` is just an alias for ``Twig_Test``. * The ``sameas`` and ``divisibleby`` tests are deprecated in favor of ``same as`` and ``divisible by`` respectively. @@ -124,16 +124,16 @@ Nodes * As of Twig 1.x, ``Node::toXml()`` is deprecated and will be removed in Twig 2.0. -* As of Twig 1.26, ``Node::$nodes`` should only contains ``Twig_Node`` +* As of Twig 1.26, ``Node::$nodes`` should only contains ``\Twig\Node\Node`` instances, storing a ``null`` value is deprecated and won't be possible in Twig 2.x. -* As of Twig 1.27, the ``filename`` attribute on ``Twig_Node_Module`` is +* As of Twig 1.27, the ``filename`` attribute on ``\Twig\Node\ModuleNode`` is deprecated. Use ``getName()`` instead. -* As of Twig 1.27, the ``Twig_Node::getFilename()/Twig_Node::getLine()`` +* As of Twig 1.27, the ``\Twig\Node\Node::getFilename()/\Twig\Node\Node::getLine()`` methods are deprecated, use - ``Twig_Node::getTemplateName()/Twig_Node::getTemplateLine()`` instead. + ``\Twig\Node\Node::getTemplateName()/\Twig\Node\Node::getTemplateLine()`` instead. Interfaces ---------- @@ -141,40 +141,40 @@ Interfaces * As of Twig 2.x, the following interfaces are deprecated and empty (they will be removed in Twig 3.0): -* ``Twig_CompilerInterface`` (use ``Twig_Compiler`` instead) -* ``Twig_LexerInterface`` (use ``Twig_Lexer`` instead) -* ``Twig_NodeInterface`` (use ``Twig_Node`` instead) -* ``Twig_ParserInterface`` (use ``Twig_Parser`` instead) -* ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``) -* ``Twig_SourceContextLoaderInterface`` (merged with ``Twig_LoaderInterface``) -* ``Twig_TemplateInterface`` (use ``Twig_Template`` instead, and use - those constants Twig_Template::ANY_CALL, Twig_Template::ARRAY_CALL, - Twig_Template::METHOD_CALL) +* ``Twig_CompilerInterface`` (use ``\Twig\Compiler`` instead) +* ``Twig_LexerInterface`` (use ``\Twig\Lexer`` instead) +* ``Twig_NodeInterface`` (use ``\Twig\Node\Node`` instead) +* ``Twig_ParserInterface`` (use ``\Twig\Parser`` instead) +* ``\Twig\Loader\ExistsLoaderInterface`` (merged with ``\Twig\Loader\LoaderInterface``) +* ``\Twig\Loader\SourceContextLoaderInterface`` (merged with ``\Twig\Loader\LoaderInterface``) +* ``Twig_TemplateInterface`` (use ``\Twig\Template`` instead, and use + those constants \Twig\Template::ANY_CALL, \Twig\Template::ARRAY_CALL, + \Twig\Template::METHOD_CALL) Compiler -------- -* As of Twig 1.26, the ``Twig_Compiler::getFilename()`` has been deprecated. +* As of Twig 1.26, the ``\Twig\Compiler::getFilename()`` has been deprecated. You should not use it anyway as its values is not reliable. -* As of Twig 1.27, the ``Twig_Compiler::addIndentation()`` has been deprecated. - Use ``Twig_Compiler::write('')`` instead. +* As of Twig 1.27, the ``\Twig\Compiler::addIndentation()`` has been deprecated. + Use ``\Twig\Compiler::write('')`` instead. Loaders ------- * As of Twig 1.x, ``Twig_Loader_String`` is deprecated and will be removed in - 2.0. You can render a string via ``Twig_Environment::createTemplate()``. + 2.0. You can render a string via ``\Twig\Environment::createTemplate()``. -* As of Twig 1.27, ``Twig_LoaderInterface::getSource()`` is deprecated. - Implement ``Twig_SourceContextLoaderInterface`` instead and use +* As of Twig 1.27, ``\Twig\Loader\LoaderInterface::getSource()`` is deprecated. + Implement ``\Twig\Loader\SourceContextLoaderInterface`` instead and use ``getSourceContext()``. Node Visitors ------------- * Because of the removal of ``Twig_NodeInterface`` in 2.0, you need to extend - ``Twig_BaseNodeVisitor`` instead of implementing ``Twig_NodeVisitorInterface`` + ``\Twig\NodeVisitor\AbstractNodeVisitor`` instead of implementing ``\Twig\NodeVisitor\NodeVisitorInterface`` directly to make your node visitors compatible with both Twig 1.x and 2.x. Globals @@ -185,40 +185,40 @@ Globals changing the value of an already registered global is possible). * As of Twig 1.x, using the ``_self`` global variable to get access to the - current ``Twig_Template`` instance is deprecated; most usages only need the + current ``\Twig\Template`` instance is deprecated; most usages only need the current template name, which will continue to work in Twig 2.0. In Twig 2.0, ``_self`` returns the current template name instead of the current - ``Twig_Template`` instance. If you are using ``{{ _self.templateName }}``, + ``\Twig\Template`` instance. If you are using ``{{ _self.templateName }}``, just replace it with ``{{ _self }}``. Miscellaneous ------------- -* As of Twig 1.x, ``Twig_Environment::clearTemplateCache()``, - ``Twig_Environment::writeCacheFile()``, - ``Twig_Environment::clearCacheFiles()``, - ``Twig_Environment::getCacheFilename()``, - ``Twig_Environment::getTemplateClassPrefix()``, - ``Twig_Environment::getLexer()``, ``Twig_Environment::getParser()``, and - ``Twig_Environment::getCompiler()`` are deprecated and will be removed in 2.0. +* As of Twig 1.x, ``\Twig\Environment::clearTemplateCache()``, + ``\Twig\Environment::writeCacheFile()``, + ``\Twig\Environment::clearCacheFiles()``, + ``\Twig\Environment::getCacheFilename()``, + ``\Twig\Environment::getTemplateClassPrefix()``, + ``\Twig\Environment::getLexer()``, ``\Twig\Environment::getParser()``, and + ``\Twig\Environment::getCompiler()`` are deprecated and will be removed in 2.0. -* As of Twig 1.x, ``Twig_Template::getEnvironment()`` and +* As of Twig 1.x, ``\Twig\Template::getEnvironment()`` and ``Twig_TemplateInterface::getEnvironment()`` are deprecated and will be removed in 2.0. * As of Twig 1.21, setting the environment option ``autoescape`` to ``true`` is deprecated and will be removed in 2.0. Use ``"html"`` instead. -* As of Twig 1.27, ``Twig_Error::getTemplateFile()`` and - ``Twig_Error::setTemplateFile()`` are deprecated. Use - ``Twig_Error::getTemplateName()`` and ``Twig_Error::setTemplateName()`` +* As of Twig 1.27, ``\Twig\Error\Error::getTemplateFile()`` and + ``\Twig\Error\Error::setTemplateFile()`` are deprecated. Use + ``\Twig\Error\Error::getTemplateName()`` and ``\Twig\Error\Error::setTemplateName()`` instead. -* As of Twig 1.27, ``Twig_Template::getSource()`` is deprecated. Use - ``Twig_Template::getSourceContext()`` instead. +* As of Twig 1.27, ``\Twig\Template::getSource()`` is deprecated. Use + ``\Twig\Template::getSourceContext()`` instead. -* As of Twig 1.27, ``Twig_Parser::addHandler()`` and - ``Twig_Parser::addNodeVisitor()`` are deprecated and will be removed in 2.0. +* As of Twig 1.27, ``\Twig\Parser::addHandler()`` and + ``\Twig\Parser::addNodeVisitor()`` are deprecated and will be removed in 2.0. * As of Twig 1.29, some classes are marked as being final via the `@final` annotation. Those classes will be marked as final in 2.0. diff --git a/doc/filters/date.rst b/doc/filters/date.rst index 811fd41bd9..5f4f202d88 100644 --- a/doc/filters/date.rst +++ b/doc/filters/date.rst @@ -53,8 +53,8 @@ dates and the second one is the default format for date intervals: .. code-block:: php - $twig = new Twig_Environment($loader); - $twig->getExtension('Twig_Extension_Core')->setDateFormat('d/m/Y', '%d days'); + $twig = new \Twig\Environment($loader); + $twig->getExtension('\Twig\Extension\CoreExtension')->setDateFormat('d/m/Y', '%d days'); // before Twig 1.26 $twig->getExtension('core')->setDateFormat('d/m/Y', '%d days'); @@ -81,8 +81,8 @@ The default timezone can also be set globally by calling ``setTimezone()``: .. code-block:: php - $twig = new Twig_Environment($loader); - $twig->getExtension('Twig_Extension_Core')->setTimezone('Europe/Paris'); + $twig = new \Twig\Environment($loader); + $twig->getExtension('\Twig\Extension\CoreExtension')->setTimezone('Europe/Paris'); // before Twig 1.26 $twig->getExtension('core')->setTimezone('Europe/Paris'); diff --git a/doc/filters/escape.rst b/doc/filters/escape.rst index 6d6f40ef38..1a41d0985f 100644 --- a/doc/filters/escape.rst +++ b/doc/filters/escape.rst @@ -96,8 +96,8 @@ used in the ``escape`` call) and the second one must be a valid PHP callable: .. code-block:: php - $twig = new Twig_Environment($loader); - $twig->getExtension('Twig_Extension_Core')->setEscaper('csv', 'csv_escaper'); + $twig = new \Twig\Environment($loader); + $twig->getExtension('\Twig\Extension\CoreExtension')->setEscaper('csv', 'csv_escaper'); // before Twig 1.26 $twig->getExtension('core')->setEscaper('csv', 'csv_escaper'); diff --git a/doc/filters/number_format.rst b/doc/filters/number_format.rst index 4db1ec938f..a5d71ee5ea 100644 --- a/doc/filters/number_format.rst +++ b/doc/filters/number_format.rst @@ -37,8 +37,8 @@ These defaults can be easily changed through the core extension: .. code-block:: php - $twig = new Twig_Environment($loader); - $twig->getExtension('Twig_Extension_Core')->setNumberFormat(3, '.', ','); + $twig = new \Twig\Environment($loader); + $twig->getExtension('\Twig\Extension\CoreExtension')->setNumberFormat(3, '.', ','); // before Twig 1.26 $twig->getExtension('core')->setNumberFormat(3, '.', ','); diff --git a/doc/functions/date.rst b/doc/functions/date.rst index 7801ad8a7e..704ccaba6f 100644 --- a/doc/functions/date.rst +++ b/doc/functions/date.rst @@ -40,8 +40,8 @@ If no argument is passed, the function returns the current date: .. code-block:: php - $twig = new Twig_Environment($loader); - $twig->getExtension('Twig_Extension_Core')->setTimezone('Europe/Paris'); + $twig = new \Twig\Environment($loader); + $twig->getExtension('\Twig\Extension\CoreExtension')->setTimezone('Europe/Paris'); // before Twig 1.26 $twig->getExtension('core')->setTimezone('Europe/Paris'); diff --git a/doc/functions/dump.rst b/doc/functions/dump.rst index e2476e1e94..89fc96918e 100644 --- a/doc/functions/dump.rst +++ b/doc/functions/dump.rst @@ -15,14 +15,14 @@ introspecting its variables: .. note:: The ``dump`` function is not available by default. You must add the - ``Twig_Extension_Debug`` extension explicitly when creating your Twig + ``\Twig\Extension\DebugExtension`` extension explicitly when creating your Twig environment:: - $twig = new Twig_Environment($loader, [ + $twig = new \Twig\Environment($loader, [ 'debug' => true, // ... ]); - $twig->addExtension(new Twig_Extension_Debug()); + $twig->addExtension(new \Twig\Extension\DebugExtension()); Even when enabled, the ``dump`` function won't display anything if the ``debug`` option on the environment is not enabled (to avoid leaking debug diff --git a/doc/functions/include.rst b/doc/functions/include.rst index 2d76b8f7cc..d7fbc5955d 100644 --- a/doc/functions/include.rst +++ b/doc/functions/include.rst @@ -37,8 +37,8 @@ You can disable access to the context by setting ``with_context`` to {# no variables will be accessible #} {{ include('template.html', with_context = false) }} -And if the expression evaluates to a ``Twig_Template`` or a -``Twig_TemplateWrapper`` instance, Twig will use it directly:: +And if the expression evaluates to a ``\Twig\Template`` or a +``\Twig\TemplateWrapper`` instance, Twig will use it directly:: // {{ include(template) }} diff --git a/doc/functions/template_from_string.rst b/doc/functions/template_from_string.rst index ce6a60dc0b..db7db805b1 100644 --- a/doc/functions/template_from_string.rst +++ b/doc/functions/template_from_string.rst @@ -14,11 +14,11 @@ The ``template_from_string`` function loads a template from a string: .. note:: The ``template_from_string`` function is not available by default. You - must add the ``Twig_Extension_StringLoader`` extension explicitly when + must add the ``\Twig\Extension\StringLoaderExtension`` extension explicitly when creating your Twig environment:: - $twig = new Twig_Environment(...); - $twig->addExtension(new Twig_Extension_StringLoader()); + $twig = new \Twig\Environment(...); + $twig->addExtension(new \Twig\Extension\StringLoaderExtension()); .. note:: diff --git a/doc/installation.rst b/doc/installation.rst index 31a280552c..d0889a9b09 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -109,7 +109,7 @@ Finally, enable the extension in your ``php.ini`` configuration file: And from now on, Twig will automatically compile your templates to take advantage of the C extension. Note that this extension does not replace the PHP code but only provides an optimized version of the -``Twig_Template::getAttribute()`` method. +``\Twig\Template::getAttribute()`` method. .. _`download page`: https://github.com/twigphp/Twig/tags .. _`Composer`: https://getcomposer.org/download/ diff --git a/doc/internals.rst b/doc/internals.rst index c8e000ff1e..f0b4f34ea2 100644 --- a/doc/internals.rst +++ b/doc/internals.rst @@ -27,27 +27,27 @@ The Lexer --------- The lexer tokenizes a template source code into a token stream (each token is -an instance of ``Twig_Token``, and the stream is an instance of -``Twig_TokenStream``). The default lexer recognizes 13 different token types: - -* ``Twig_Token::BLOCK_START_TYPE``, ``Twig_Token::BLOCK_END_TYPE``: Delimiters for blocks (``{% %}``) -* ``Twig_Token::VAR_START_TYPE``, ``Twig_Token::VAR_END_TYPE``: Delimiters for variables (``{{ }}``) -* ``Twig_Token::TEXT_TYPE``: A text outside an expression; -* ``Twig_Token::NAME_TYPE``: A name in an expression; -* ``Twig_Token::NUMBER_TYPE``: A number in an expression; -* ``Twig_Token::STRING_TYPE``: A string in an expression; -* ``Twig_Token::OPERATOR_TYPE``: An operator; -* ``Twig_Token::PUNCTUATION_TYPE``: A punctuation sign; -* ``Twig_Token::INTERPOLATION_START_TYPE``, ``Twig_Token::INTERPOLATION_END_TYPE`` (as of Twig 1.5): Delimiters for string interpolation; -* ``Twig_Token::EOF_TYPE``: Ends of template. +an instance of ``\Twig\Token``, and the stream is an instance of +``\Twig\TokenStream``). The default lexer recognizes 13 different token types: + +* ``\Twig\Token::BLOCK_START_TYPE``, ``\Twig\Token::BLOCK_END_TYPE``: Delimiters for blocks (``{% %}``) +* ``\Twig\Token::VAR_START_TYPE``, ``\Twig\Token::VAR_END_TYPE``: Delimiters for variables (``{{ }}``) +* ``\Twig\Token::TEXT_TYPE``: A text outside an expression; +* ``\Twig\Token::NAME_TYPE``: A name in an expression; +* ``\Twig\Token::NUMBER_TYPE``: A number in an expression; +* ``\Twig\Token::STRING_TYPE``: A string in an expression; +* ``\Twig\Token::OPERATOR_TYPE``: An operator; +* ``\Twig\Token::PUNCTUATION_TYPE``: A punctuation sign; +* ``\Twig\Token::INTERPOLATION_START_TYPE``, ``\Twig\Token::INTERPOLATION_END_TYPE`` (as of Twig 1.5): Delimiters for string interpolation; +* ``\Twig\Token::EOF_TYPE``: Ends of template. You can manually convert a source code into a token stream by calling the ``tokenize()`` method of an environment:: - $stream = $twig->tokenize(new Twig_Source($source, $identifier)); + $stream = $twig->tokenize(new \Twig\Source($source, $identifier)); .. versionadded:: 1.27 - ``Twig_Source`` was introduced in version 1.27, pass the source and the + ``\Twig\Source`` was introduced in version 1.27, pass the source and the identifier directly on previous versions. As the stream has a ``__toString()`` method, you can have a textual @@ -67,7 +67,7 @@ Here is the output for the ``Hello {{ name }}`` template: .. note:: - The default lexer (``Twig_Lexer``) can be changed by calling + The default lexer (``\Twig\Lexer``) can be changed by calling the ``setLexer()`` method:: $twig->setLexer($lexer); @@ -76,7 +76,7 @@ The Parser ---------- The parser converts the token stream into an AST (Abstract Syntax Tree), or a -node tree (an instance of ``Twig_Node_Module``). The core extension defines +node tree (an instance of ``\Twig\Node\ModuleNode``). The core extension defines the basic nodes like: ``for``, ``if``, ... and the expression nodes. You can manually convert a token stream into a node tree by calling the @@ -101,7 +101,7 @@ Here is the output for the ``Hello {{ name }}`` template: .. note:: - The default parser (``Twig_TokenParser``) can be changed by calling the + The default parser (``\Twig\TokenParser\AbstractTokenParser``) can be changed by calling the ``setParser()`` method:: $twig->setParser($parser); @@ -122,7 +122,7 @@ The generated template for a ``Hello {{ name }}`` template reads as follows using):: /* Hello {{ name }} */ - class __TwigTemplate_1121b6f109fe93ebe8c6e22e3712bceb extends Twig_Template + class __TwigTemplate_1121b6f109fe93ebe8c6e22e3712bceb extends \Twig\Template { protected function doDisplay(array $context, array $blocks = []) { @@ -136,7 +136,7 @@ using):: .. note:: - The default compiler (``Twig_Compiler``) can be changed by calling the + The default compiler (``\Twig\Compiler``) can be changed by calling the ``setCompiler()`` method:: $twig->setCompiler($compiler); diff --git a/doc/intro.rst b/doc/intro.rst index 5264c54696..4407ea0c64 100644 --- a/doc/intro.rst +++ b/doc/intro.rst @@ -55,15 +55,15 @@ This section gives you a brief introduction to the PHP API for Twig. require_once '/path/to/vendor/autoload.php'; - $loader = new Twig_Loader_Array([ + $loader = new \Twig\Loader\ArrayLoader([ 'index' => 'Hello {{ name }}!', ]); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); echo $twig->render('index', ['name' => 'Fabien']); -Twig uses a loader (``Twig_Loader_Array``) to locate templates, and an -environment (``Twig_Environment``) to store the configuration. +Twig uses a loader (``\Twig\Loader\ArrayLoader``) to locate templates, and an +environment (``\Twig\Environment``) to store the configuration. The ``render()`` method loads the template passed as a first argument and renders it with the variables passed as a second argument. @@ -71,8 +71,8 @@ renders it with the variables passed as a second argument. As templates are generally stored on the filesystem, Twig also comes with a filesystem loader:: - $loader = new Twig_Loader_Filesystem('/path/to/templates'); - $twig = new Twig_Environment($loader, [ + $loader = new \Twig\Loader\FilesystemLoader('/path/to/templates'); + $twig = new \Twig\Environment($loader, [ 'cache' => '/path/to/compilation_cache', ]); diff --git a/doc/recipes.rst b/doc/recipes.rst index b4208c482e..89fffc366d 100644 --- a/doc/recipes.rst +++ b/doc/recipes.rst @@ -20,7 +20,7 @@ run a script along the lines of the following:: $twig = create_your_twig_env(); - $deprecations = new Twig_Util_DeprecationCollector($twig); + $deprecations = new \Twig\Util\DeprecationCollector($twig); print_r($deprecations->collectDir(__DIR__.'/templates')); @@ -32,7 +32,7 @@ catches deprecation notices, and return them. If your templates are not stored on the filesystem, use the ``collect()`` method instead. ``collect()`` takes a ``Traversable`` which must return template names as keys and template contents as values (as done by - ``Twig_Util_TemplateDirIterator``). + ``\Twig\Util\TemplateDirIterator``). However, this code won't find all deprecations (like using deprecated some Twig classes). To catch all notices, register a custom error handler like the one @@ -161,9 +161,9 @@ syntax. But for specific projects, it can make sense to change the defaults. To change the block delimiters, you need to create your own lexer object:: - $twig = new Twig_Environment(); + $twig = new \Twig\Environment(); - $lexer = new Twig_Lexer($twig, [ + $lexer = new \Twig\Lexer($twig, [ 'tag_comment' => ['{#', '#}'], 'tag_block' => ['{%', '%}'], 'tag_variable' => ['{{', '}}'], @@ -175,21 +175,21 @@ Here are some configuration example that simulates some other template engines syntax:: // Ruby erb syntax - $lexer = new Twig_Lexer($twig, [ + $lexer = new \Twig\Lexer($twig, [ 'tag_comment' => ['<%#', '%>'], 'tag_block' => ['<%', '%>'], 'tag_variable' => ['<%=', '%>'], ]); // SGML Comment Syntax - $lexer = new Twig_Lexer($twig, [ + $lexer = new \Twig\Lexer($twig, [ 'tag_comment' => [''], 'tag_block' => [''], 'tag_variable' => ['${', '}'], ]); // Smarty like - $lexer = new Twig_Lexer($twig, [ + $lexer = new \Twig\Lexer($twig, [ 'tag_comment' => ['{*', '*}'], 'tag_block' => ['{', '}'], 'tag_variable' => ['{$', '}'], @@ -270,7 +270,7 @@ Defining undefined Functions and Filters on the Fly --------------------------------------------------- When a function (or a filter) is not defined, Twig defaults to throw a -``Twig_Error_Syntax`` exception. However, it can also call a `callback`_ (any +``\Twig\Error\SyntaxError`` exception. However, it can also call a `callback`_ (any valid PHP callable) which should return a function (or a filter). For filters, register callbacks with ``registerUndefinedFilterCallback()``. @@ -280,7 +280,7 @@ For functions, use ``registerUndefinedFunctionCallback()``:: // don't try this at home as it's not secure at all! $twig->registerUndefinedFunctionCallback(function ($name) { if (function_exists($name)) { - return new Twig_SimpleFunction($name, $name); + return new \Twig\TwigFunction($name, $name); } return false; @@ -306,10 +306,10 @@ saving it. If the template code is stored in a `$template` variable, here is how you can do it:: try { - $twig->parse($twig->tokenize(new Twig_Source($template))); + $twig->parse($twig->tokenize(new \Twig\Source($template))); // the $template is valid - } catch (Twig_Error_Syntax $e) { + } catch (\Twig\Error\SyntaxError $e) { // $template contains one or more syntax errors } @@ -318,16 +318,16 @@ If you iterate over a set of files, you can pass the filename to the foreach ($files as $file) { try { - $twig->parse($twig->tokenize(new Twig_Source($template, $file->getFilename(), $file))); + $twig->parse($twig->tokenize(new \Twig\Source($template, $file->getFilename(), $file))); // the $template is valid - } catch (Twig_Error_Syntax $e) { + } catch (\Twig\Error\SyntaxError $e) { // $template contains one or more syntax errors } } .. versionadded:: 1.27 - ``Twig_Source`` was introduced in version 1.27, pass the source and the + ``\Twig\Source`` was introduced in version 1.27, pass the source and the identifier directly on previous versions. .. note:: @@ -345,16 +345,16 @@ cache won't update the cache. To get around this, force Twig to invalidate the bytecode cache:: - $twig = new Twig_Environment($loader, [ - 'cache' => new Twig_Cache_Filesystem('/some/cache/path', Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION), + $twig = new \Twig\Environment($loader, [ + 'cache' => new \Twig\Cache\FilesystemCache('/some/cache/path', \Twig\Cache\FilesystemCache::FORCE_BYTECODE_INVALIDATION), // ... ]); .. note:: - Before Twig 1.22, you should extend ``Twig_Environment`` instead:: + Before Twig 1.22, you should extend ``\Twig\Environment`` instead:: - class OpCacheAwareTwigEnvironment extends Twig_Environment + class OpCacheAwareTwigEnvironment extends \Twig\Environment { protected function writeCacheFile($file, $content) { @@ -372,7 +372,7 @@ To get around this, force Twig to invalidate the bytecode cache:: Reusing a stateful Node Visitor ------------------------------- -When attaching a visitor to a ``Twig_Environment`` instance, Twig uses it to +When attaching a visitor to a ``\Twig\Environment`` instance, Twig uses it to visit *all* templates it compiles. If you need to keep some state information around, you probably want to reset it when visiting a new template. @@ -380,9 +380,9 @@ This can be easily achieved with the following code:: protected $someTemplateState = []; - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Module) { + if ($node instanceof \Twig\Node\ModuleNode) { // reset the state as we are entering a new template $this->someTemplateState = []; } @@ -429,7 +429,7 @@ Now, let's define a loader able to use this database:: public function getSource($name) { if (false === $source = $this->getValue('source', $name)) { - throw new Twig_Error_Loader(sprintf('Template "%s" does not exist.', $name)); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" does not exist.', $name)); } return $source; @@ -439,10 +439,10 @@ Now, let's define a loader able to use this database:: public function getSourceContext($name) { if (false === $source = $this->getValue('source', $name)) { - throw new Twig_Error_Loader(sprintf('Template "%s" does not exist.', $name)); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" does not exist.', $name)); } - return new Twig_Source($source, $name); + return new \Twig\Source($source, $name); } // \Twig\Loader\ExistsLoaderInterface as of Twig 1.11 @@ -477,7 +477,7 @@ Now, let's define a loader able to use this database:: Finally, here is an example on how you can use it:: $loader = new DatabaseTwigLoader($dbh); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); echo $twig->render('index.twig', ['name' => 'Fabien']); @@ -487,7 +487,7 @@ Using different Template Sources This recipe is the continuation of the previous one. Even if you store the contributed templates in a database, you might want to keep the original/base templates on the filesystem. When templates can be loaded from different -sources, you need to use the ``Twig_Loader_Chain`` loader. +sources, you need to use the ``\Twig\Loader\ChainLoader`` loader. As you can see in the previous recipe, we reference the template in the exact same way as we would have done it with a regular filesystem loader. This is @@ -496,12 +496,12 @@ filesystem, or any other loader for that matter: the template name should be a logical name, and not the path from the filesystem:: $loader1 = new DatabaseTwigLoader($dbh); - $loader2 = new Twig_Loader_Array([ + $loader2 = new \Twig\Loader\ArrayLoader([ 'base.twig' => '{% block content %}{% endblock %}', ]); - $loader = new Twig_Loader_Chain([$loader1, $loader2]); + $loader = new \Twig\Loader\ChainLoader([$loader1, $loader2]); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); echo $twig->render('index.twig', ['name' => 'Fabien']); @@ -513,14 +513,14 @@ Loading a Template from a String From a template, you can easily load a template stored in a string via the ``template_from_string`` function (available as of Twig 1.11 via the -``Twig_Extension_StringLoader`` extension): +``\Twig\Extension\StringLoaderExtension`` extension): .. code-block:: jinja {{ include(template_from_string("Hello {{ name }}")) }} From PHP, it's also possible to load a template stored in a string via -``Twig_Environment::createTemplate()`` (available as of Twig 1.18):: +``\Twig\Environment::createTemplate()`` (available as of Twig 1.18):: $template = $twig->createTemplate('hello {{ name }}'); echo $template->render(['name' => 'Fabien']); @@ -561,7 +561,7 @@ include in your templates: .. code-block:: php - $env->setLexer(new Twig_Lexer($env, [ + $env->setLexer(new \Twig\Lexer($env, [ 'tag_variable' => ['{[', ']}'], ])); diff --git a/doc/tags/extends.rst b/doc/tags/extends.rst index 0fe4a31e20..2906167201 100644 --- a/doc/tags/extends.rst +++ b/doc/tags/extends.rst @@ -153,7 +153,7 @@ Twig supports dynamic inheritance by using a variable as the base template: {% extends some_var %} -If the variable evaluates to a ``Twig_Template`` or a ``Twig_TemplateWrapper`` +If the variable evaluates to a ``\Twig\Template`` or a ``\Twig\TemplateWrapper`` instance, Twig will use it as the parent template:: // {% extends layout %} diff --git a/doc/tags/include.rst b/doc/tags/include.rst index bbb9b4f604..2200c87a6a 100644 --- a/doc/tags/include.rst +++ b/doc/tags/include.rst @@ -74,8 +74,8 @@ The template name can be any valid Twig expression: {% include some_var %} {% include ajax ? 'ajax.html' : 'not_ajax.html' %} -And if the expression evaluates to a ``Twig_Template`` or a -``Twig_TemplateWrapper`` instance, Twig will use it directly:: +And if the expression evaluates to a ``\Twig\Template`` or a +``\Twig\TemplateWrapper`` instance, Twig will use it directly:: // {% include template %} diff --git a/doc/templates.rst b/doc/templates.rst index df8c31ba51..91db45aa56 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -316,7 +316,7 @@ will be available in the included template too: The included template ``render_box.html`` is able to access the ``box`` variable. The name of the template depends on the template loader. For instance, the -``Twig_Loader_Filesystem`` allows you to access other templates by giving the +``\Twig\Loader\FilesystemLoader`` allows you to access other templates by giving the filename. You can access templates in subdirectories with a slash: .. code-block:: jinja diff --git a/ext/twig/twig.c b/ext/twig/twig.c index 17af426fa3..171ed10bb8 100644 --- a/ext/twig/twig.c +++ b/ext/twig/twig.c @@ -733,7 +733,7 @@ PHP_FUNCTION(twig_template_get_attributes) /* // array - if (Twig_Template::METHOD_CALL !== $type) { + if (\Twig\Template::METHOD_CALL !== $type) { $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; if ((is_array($object) && array_key_exists($arrayItem, $object)) @@ -771,7 +771,7 @@ PHP_FUNCTION(twig_template_get_attributes) return; } /* - if (Twig_Template::ARRAY_CALL === $type) { + if (\Twig\Template::ARRAY_CALL === $type) { if ($isDefinedTest) { return false; } @@ -799,7 +799,7 @@ PHP_FUNCTION(twig_template_get_attributes) } else { $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); } - } elseif (Twig_Template::ARRAY_CALL === $type) { + } elseif (\Twig\Template::ARRAY_CALL === $type) { if (null === $object) { $message = sprintf('Impossible to access a key ("%s") on a null variable', $item); } else { @@ -810,7 +810,7 @@ PHP_FUNCTION(twig_template_get_attributes) } else { $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object); } - throw new Twig_Error_Runtime($message, -1, $this->getTemplateName()); + throw new \Twig\Error\RuntimeError($message, -1, $this->getTemplateName()); } } */ @@ -876,7 +876,7 @@ PHP_FUNCTION(twig_template_get_attributes) $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object); } - throw new Twig_Error_Runtime($message, -1, $this->getTemplateName()); + throw new \Twig\Error\RuntimeError($message, -1, $this->getTemplateName()); } */ if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { @@ -916,14 +916,14 @@ PHP_FUNCTION(twig_template_get_attributes) /* // object property - if (Twig_Template::METHOD_CALL !== $type && !$object instanceof Twig_Template) { + if (\Twig\Template::METHOD_CALL !== $type && !$object instanceof \Twig\Template) { if (isset($object->$item) || array_key_exists((string) $item, $object)) { if ($isDefinedTest) { return true; } - if ($this->env->hasExtension('Twig_Extension_Sandbox')) { - $this->env->getExtension('Twig_Extension_Sandbox')->checkPropertyAllowed($object, $item); + if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) { + $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkPropertyAllowed($object, $item); } return $object->$item; @@ -1029,7 +1029,7 @@ PHP_FUNCTION(twig_template_get_attributes) return null; } - throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist.', $item, get_class($object)), -1, $this->getTemplateName()); + throw new \Twig\Error\RuntimeError(sprintf('Method "%s" for object "%s" does not exist.', $item, get_class($object)), -1, $this->getTemplateName()); } if ($isDefinedTest) { @@ -1061,8 +1061,8 @@ PHP_FUNCTION(twig_template_get_attributes) RETURN_TRUE; } /* - if ($this->env->hasExtension('Twig_Extension_Sandbox')) { - $this->env->getExtension('Twig_Extension_Sandbox')->checkMethodAllowed($object, $method); + if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) { + $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object, $method); } */ MAKE_STD_ZVAL(zmethod); @@ -1117,7 +1117,7 @@ PHP_FUNCTION(twig_template_get_attributes) } @trigger_error($message, E_USER_DEPRECATED); - return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset()); + return $ret === '' ? '' : new \Twig\Markup($ret, $this->env->getCharset()); } return $ret; diff --git a/lib/Twig/BaseNodeVisitor.php b/lib/Twig/BaseNodeVisitor.php index 333ac7ec15..7cfe672dab 100644 --- a/lib/Twig/BaseNodeVisitor.php +++ b/lib/Twig/BaseNodeVisitor.php @@ -14,20 +14,20 @@ * * @author Fabien Potencier */ -abstract class Twig_BaseNodeVisitor implements Twig_NodeVisitorInterface +abstract class Twig_BaseNodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface { - final public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + final public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env) { - if (!$node instanceof Twig_Node) { + if (!$node instanceof \Twig\Node\Node) { throw new \LogicException(sprintf('%s only supports Twig_Node instances.', __CLASS__)); } return $this->doEnterNode($node, $env); } - final public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + final public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env) { - if (!$node instanceof Twig_Node) { + if (!$node instanceof \Twig\Node\Node) { throw new \LogicException(sprintf('%s only supports Twig_Node instances.', __CLASS__)); } @@ -37,16 +37,16 @@ final public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) /** * Called before child nodes are visited. * - * @return Twig_Node The modified node + * @return \Twig\Node\Node The modified node */ - abstract protected function doEnterNode(Twig_Node $node, Twig_Environment $env); + abstract protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env); /** * Called after child nodes are visited. * - * @return Twig_Node|false The modified node or false if the node must be removed + * @return \Twig\Node\Node|false The modified node or false if the node must be removed */ - abstract protected function doLeaveNode(Twig_Node $node, Twig_Environment $env); + abstract protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env); } class_alias('Twig_BaseNodeVisitor', 'Twig\NodeVisitor\AbstractNodeVisitor', false); diff --git a/lib/Twig/Cache/Filesystem.php b/lib/Twig/Cache/Filesystem.php index 73b0220eb5..51e8188343 100644 --- a/lib/Twig/Cache/Filesystem.php +++ b/lib/Twig/Cache/Filesystem.php @@ -14,7 +14,7 @@ * * @author Andrew Tch */ -class Twig_Cache_Filesystem implements Twig_CacheInterface +class Twig_Cache_Filesystem implements \Twig\Cache\CacheInterface { const FORCE_BYTECODE_INVALIDATION = 1; diff --git a/lib/Twig/Cache/Null.php b/lib/Twig/Cache/Null.php index 69d1d2f98a..59ab7a948f 100644 --- a/lib/Twig/Cache/Null.php +++ b/lib/Twig/Cache/Null.php @@ -16,7 +16,7 @@ * * @author Fabien Potencier */ -class Twig_Cache_Null implements Twig_CacheInterface +class Twig_Cache_Null implements \Twig\Cache\CacheInterface { public function generateKey($name, $className) { diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index fe4983e3f2..aff2f1cfdd 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -27,7 +27,7 @@ class Twig_Compiler implements Twig_CompilerInterface protected $filename; private $varNameSalt = 0; - public function __construct(Twig_Environment $env) + public function __construct(\Twig\Environment $env) { $this->env = $env; } @@ -45,7 +45,7 @@ public function getFilename() /** * Returns the environment instance related to this compiler. * - * @return Twig_Environment + * @return \Twig\Environment */ public function getEnvironment() { @@ -80,7 +80,7 @@ public function compile(Twig_NodeInterface $node, $indentation = 0) $this->indentation = $indentation; $this->varNameSalt = 0; - if ($node instanceof Twig_Node_Module) { + if ($node instanceof \Twig\Node\ModuleNode) { // to be removed in 2.0 $this->filename = $node->getTemplateName(); } diff --git a/lib/Twig/ContainerRuntimeLoader.php b/lib/Twig/ContainerRuntimeLoader.php index 814ab58bc3..fe58e74c2d 100644 --- a/lib/Twig/ContainerRuntimeLoader.php +++ b/lib/Twig/ContainerRuntimeLoader.php @@ -19,7 +19,7 @@ * @author Fabien Potencier * @author Robin Chalas */ -class Twig_ContainerRuntimeLoader implements Twig_RuntimeLoaderInterface +class Twig_ContainerRuntimeLoader implements \Twig\RuntimeLoader\RuntimeLoaderInterface { private $container; diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index b19f9aa658..dfc44a9f4c 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -95,7 +95,7 @@ class Twig_Environment * (default to -1 which means that all optimizations are enabled; * set it to 0 to disable). */ - public function __construct(Twig_LoaderInterface $loader = null, $options = []) + public function __construct(\Twig\Loader\LoaderInterface $loader = null, $options = []) { if (null !== $loader) { $this->setLoader($loader); @@ -106,7 +106,7 @@ public function __construct(Twig_LoaderInterface $loader = null, $options = []) $options = array_merge([ 'debug' => false, 'charset' => 'UTF-8', - 'base_template_class' => 'Twig_Template', + 'base_template_class' => '\Twig\Template', 'strict_variables' => false, 'autoescape' => 'html', 'cache' => false, @@ -121,23 +121,23 @@ public function __construct(Twig_LoaderInterface $loader = null, $options = []) $this->strictVariables = (bool) $options['strict_variables']; $this->setCache($options['cache']); - $this->addExtension(new Twig_Extension_Core()); - $this->addExtension(new Twig_Extension_Escaper($options['autoescape'])); - $this->addExtension(new Twig_Extension_Optimizer($options['optimizations'])); - $this->staging = new Twig_Extension_Staging(); + $this->addExtension(new \Twig\Extension\CoreExtension()); + $this->addExtension(new \Twig\Extension\EscaperExtension($options['autoescape'])); + $this->addExtension(new \Twig\Extension\OptimizerExtension($options['optimizations'])); + $this->staging = new \Twig\Extension\StagingExtension(); // For BC if (\is_string($this->originalCache)) { $r = new \ReflectionMethod($this, 'writeCacheFile'); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error('The Twig_Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + @trigger_error('The \Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); $this->bcWriteCacheFile = true; } $r = new \ReflectionMethod($this, 'getCacheFilename'); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error('The Twig_Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + @trigger_error('The \Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); $this->bcGetCacheFilename = true; } @@ -252,9 +252,9 @@ public function isStrictVariables() * * @param bool $original Whether to return the original cache option or the real cache instance * - * @return Twig_CacheInterface|string|false A Twig_CacheInterface implementation, - * an absolute path to the compiled templates, - * or false to disable cache + * @return \Twig\Cache\CacheInterface|string|false A Twig_CacheInterface implementation, + * an absolute path to the compiled templates, + * or false to disable cache */ public function getCache($original = true) { @@ -264,23 +264,23 @@ public function getCache($original = true) /** * Sets the current cache implementation. * - * @param Twig_CacheInterface|string|false $cache A Twig_CacheInterface implementation, - * an absolute path to the compiled templates, - * or false to disable cache + * @param \Twig\Cache\CacheInterface|string|false $cache A Twig_CacheInterface implementation, + * an absolute path to the compiled templates, + * or false to disable cache */ public function setCache($cache) { if (\is_string($cache)) { $this->originalCache = $cache; - $this->cache = new Twig_Cache_Filesystem($cache); + $this->cache = new \Twig\Cache\FilesystemCache($cache); } elseif (false === $cache) { $this->originalCache = $cache; - $this->cache = new Twig_Cache_Null(); + $this->cache = new \Twig\Cache\NullCache(); } elseif (null === $cache) { @trigger_error('Using "null" as the cache strategy is deprecated since version 1.23 and will be removed in Twig 2.0.', E_USER_DEPRECATED); $this->originalCache = false; - $this->cache = new Twig_Cache_Null(); - } elseif ($cache instanceof Twig_CacheInterface) { + $this->cache = new \Twig\Cache\NullCache(); + } elseif ($cache instanceof \Twig\Cache\CacheInterface) { $this->originalCache = $this->cache = $cache; } else { throw new \LogicException(sprintf('Cache can only be a string, false, or a Twig_CacheInterface implementation.')); @@ -351,9 +351,9 @@ public function getTemplateClassPrefix() * * @return string The rendered template * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation - * @throws Twig_Error_Runtime When an error occurred during rendering + * @throws \Twig\Error\LoaderError When the template cannot be found + * @throws \Twig\Error\SyntaxError When an error occurred during compilation + * @throws \Twig\Error\RuntimeError When an error occurred during rendering */ public function render($name, array $context = []) { @@ -366,9 +366,9 @@ public function render($name, array $context = []) * @param string $name The template name * @param array $context An array of parameters to pass to the template * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation - * @throws Twig_Error_Runtime When an error occurred during rendering + * @throws \Twig\Error\LoaderError When the template cannot be found + * @throws \Twig\Error\SyntaxError When an error occurred during compilation + * @throws \Twig\Error\RuntimeError When an error occurred during rendering */ public function display($name, array $context = []) { @@ -378,25 +378,25 @@ public function display($name, array $context = []) /** * Loads a template. * - * @param string|Twig_TemplateWrapper|Twig_Template $name The template name + * @param string|\Twig\TemplateWrapper|\Twig\Template $name The template name * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Runtime When a previously generated cache is corrupted - * @throws Twig_Error_Syntax When an error occurred during compilation + * @throws \Twig\Error\LoaderError When the template cannot be found + * @throws \Twig\Error\RuntimeError When a previously generated cache is corrupted + * @throws \Twig\Error\SyntaxError When an error occurred during compilation * - * @return Twig_TemplateWrapper + * @return \Twig\TemplateWrapper */ public function load($name) { - if ($name instanceof Twig_TemplateWrapper) { + if ($name instanceof \Twig\TemplateWrapper) { return $name; } - if ($name instanceof Twig_Template) { - return new Twig_TemplateWrapper($this, $name); + if ($name instanceof \Twig\Template) { + return new \Twig\TemplateWrapper($this, $name); } - return new Twig_TemplateWrapper($this, $this->loadTemplate($name)); + return new \Twig\TemplateWrapper($this, $this->loadTemplate($name)); } /** @@ -410,9 +410,9 @@ public function load($name) * * @return Twig_TemplateInterface A template instance representing the given template name * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Runtime When a previously generated cache is corrupted - * @throws Twig_Error_Syntax When an error occurred during compilation + * @throws \Twig\Error\LoaderError When the template cannot be found + * @throws \Twig\Error\RuntimeError When a previously generated cache is corrupted + * @throws \Twig\Error\SyntaxError When an error occurred during compilation * * @internal */ @@ -440,8 +440,8 @@ public function loadTemplate($name, $index = null) if (!class_exists($cls, false)) { $loader = $this->getLoader(); - if (!$loader instanceof Twig_SourceContextLoaderInterface) { - $source = new Twig_Source($loader->getSource($name), $name); + if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface) { + $source = new \Twig\Source($loader->getSource($name), $name); } else { $source = $loader->getSourceContext($name); } @@ -466,7 +466,7 @@ public function loadTemplate($name, $index = null) } if (!class_exists($cls, false)) { - throw new Twig_Error_Runtime(sprintf('Failed to load Twig template "%s", index "%s": cache is corrupted.', $name, $index), -1, $source); + throw new \Twig\Error\RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache is corrupted.', $name, $index), -1, $source); } } @@ -475,7 +475,7 @@ public function loadTemplate($name, $index = null) } if (isset($this->loading[$cls])) { - throw new Twig_Error_Runtime(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, [$name])))); + throw new \Twig\Error\RuntimeError(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, [$name])))); } $this->loading[$cls] = $name; @@ -499,17 +499,17 @@ public function loadTemplate($name, $index = null) * * @param string $template The template name * - * @return Twig_Template A template instance representing the given template name + * @return \Twig\Template A template instance representing the given template name * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation + * @throws \Twig\Error\LoaderError When the template cannot be found + * @throws \Twig\Error\SyntaxError When an error occurred during compilation */ public function createTemplate($template) { $name = sprintf('__string_template__%s', hash('sha256', $template, false)); - $loader = new Twig_Loader_Chain([ - new Twig_Loader_Array([$name => $template]), + $loader = new \Twig\Loader\ChainLoader([ + new \Twig\Loader\ArrayLoader([$name => $template]), $current = $this->getLoader(), ]); @@ -562,12 +562,12 @@ public function isTemplateFresh($name, $time) * Similar to loadTemplate() but it also accepts instances of Twig_Template and * Twig_TemplateWrapper, and an array of templates where each is tried to be loaded. * - * @param string|Twig_Template|Twig_TemplateWrapper|array $names A template or an array of templates to try consecutively + * @param string|\Twig\Template|\Twig\TemplateWrapper|array $names A template or an array of templates to try consecutively * - * @return Twig_Template|Twig_TemplateWrapper + * @return \Twig\Template|Twig_TemplateWrapper * - * @throws Twig_Error_Loader When none of the templates can be found - * @throws Twig_Error_Syntax When an error occurred during compilation + * @throws \Twig\Error\LoaderError When none of the templates can be found + * @throws \Twig\Error\SyntaxError When an error occurred during compilation */ public function resolveTemplate($names) { @@ -576,17 +576,17 @@ public function resolveTemplate($names) } foreach ($names as $name) { - if ($name instanceof Twig_Template) { + if ($name instanceof \Twig\Template) { return $name; } - if ($name instanceof Twig_TemplateWrapper) { + if ($name instanceof \Twig\TemplateWrapper) { return $name; } try { return $this->loadTemplate($name); - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { } } @@ -594,7 +594,7 @@ public function resolveTemplate($names) throw $e; } - throw new Twig_Error_Loader(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); + throw new \Twig\Error\LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); } /** @@ -639,7 +639,7 @@ public function getLexer() @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); if (null === $this->lexer) { - $this->lexer = new Twig_Lexer($this); + $this->lexer = new \Twig\Lexer($this); } return $this->lexer; @@ -653,22 +653,22 @@ public function setLexer(Twig_LexerInterface $lexer) /** * Tokenizes a source code. * - * @param string|Twig_Source $source The template source code - * @param string $name The template name (deprecated) + * @param string|\Twig\Source $source The template source code + * @param string $name The template name (deprecated) * - * @return Twig_TokenStream + * @return \Twig\TokenStream * - * @throws Twig_Error_Syntax When the code is syntactically wrong + * @throws \Twig\Error\SyntaxError When the code is syntactically wrong */ public function tokenize($source, $name = null) { - if (!$source instanceof Twig_Source) { + if (!$source instanceof \Twig\Source) { @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $source = new Twig_Source($source, $name); + $source = new \Twig\Source($source, $name); } if (null === $this->lexer) { - $this->lexer = new Twig_Lexer($this); + $this->lexer = new \Twig\Lexer($this); } return $this->lexer->tokenize($source); @@ -686,7 +686,7 @@ public function getParser() @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); if (null === $this->parser) { - $this->parser = new Twig_Parser($this); + $this->parser = new \Twig\Parser($this); } return $this->parser; @@ -700,14 +700,14 @@ public function setParser(Twig_ParserInterface $parser) /** * Converts a token stream to a node tree. * - * @return Twig_Node_Module + * @return \Twig\Node\ModuleNode * - * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong + * @throws \Twig\Error\SyntaxError When the token stream is syntactically or semantically wrong */ - public function parse(Twig_TokenStream $stream) + public function parse(\Twig\TokenStream $stream) { if (null === $this->parser) { - $this->parser = new Twig_Parser($this); + $this->parser = new \Twig\Parser($this); } return $this->parser->parse($stream); @@ -725,7 +725,7 @@ public function getCompiler() @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); if (null === $this->compiler) { - $this->compiler = new Twig_Compiler($this); + $this->compiler = new \Twig\Compiler($this); } return $this->compiler; @@ -744,7 +744,7 @@ public function setCompiler(Twig_CompilerInterface $compiler) public function compile(Twig_NodeInterface $node) { if (null === $this->compiler) { - $this->compiler = new Twig_Compiler($this); + $this->compiler = new \Twig\Compiler($this); } return $this->compiler->compile($node)->getSource(); @@ -753,33 +753,33 @@ public function compile(Twig_NodeInterface $node) /** * Compiles a template source code. * - * @param string|Twig_Source $source The template source code - * @param string $name The template name (deprecated) + * @param string|\Twig\Source $source The template source code + * @param string $name The template name (deprecated) * * @return string The compiled PHP source code * - * @throws Twig_Error_Syntax When there was an error during tokenizing, parsing or compiling + * @throws \Twig\Error\SyntaxError When there was an error during tokenizing, parsing or compiling */ public function compileSource($source, $name = null) { - if (!$source instanceof Twig_Source) { + if (!$source instanceof \Twig\Source) { @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $source = new Twig_Source($source, $name); + $source = new \Twig\Source($source, $name); } try { return $this->compile($this->parse($this->tokenize($source))); - } catch (Twig_Error $e) { + } catch (\Twig\Error\Error $e) { $e->setSourceContext($source); throw $e; } catch (\Exception $e) { - throw new Twig_Error_Syntax(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); + throw new \Twig\Error\SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); } } - public function setLoader(Twig_LoaderInterface $loader) + public function setLoader(\Twig\Loader\LoaderInterface $loader) { - if (!$loader instanceof Twig_SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) { + if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) { @trigger_error(sprintf('Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED); } @@ -789,7 +789,7 @@ public function setLoader(Twig_LoaderInterface $loader) /** * Gets the Loader instance. * - * @return Twig_LoaderInterface + * @return \Twig\Loader\LoaderInterface */ public function getLoader() { @@ -830,7 +830,7 @@ public function initRuntime() $this->runtimeInitialized = true; foreach ($this->getExtensions() as $name => $extension) { - if (!$extension instanceof Twig_Extension_InitRuntimeInterface) { + if (!$extension instanceof \Twig\Extension\InitRuntimeInterface) { $m = new \ReflectionMethod($extension, 'initRuntime'); if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) { @@ -872,7 +872,7 @@ public function hasExtension($class) /** * Adds a runtime loader. */ - public function addRuntimeLoader(Twig_RuntimeLoaderInterface $loader) + public function addRuntimeLoader(\Twig\RuntimeLoader\RuntimeLoaderInterface $loader) { $this->runtimeLoaders[] = $loader; } @@ -882,7 +882,7 @@ public function addRuntimeLoader(Twig_RuntimeLoaderInterface $loader) * * @param string $class The extension class name * - * @return Twig_ExtensionInterface + * @return \Twig\Extension\ExtensionInterface */ public function getExtension($class) { @@ -902,7 +902,7 @@ public function getExtension($class) } if (!isset($this->extensionsByClass[$class])) { - throw new Twig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $class)); + throw new \Twig\Error\RuntimeError(sprintf('The "%s" extension is not enabled.', $class)); } return $this->extensionsByClass[$class]; @@ -915,7 +915,7 @@ public function getExtension($class) * * @return object The runtime implementation * - * @throws Twig_Error_Runtime When the template cannot be found + * @throws \Twig\Error\RuntimeError When the template cannot be found */ public function getRuntime($class) { @@ -929,10 +929,10 @@ public function getRuntime($class) } } - throw new Twig_Error_Runtime(sprintf('Unable to load the "%s" runtime.', $class)); + throw new \Twig\Error\RuntimeError(sprintf('Unable to load the "%s" runtime.', $class)); } - public function addExtension(Twig_ExtensionInterface $extension) + public function addExtension(\Twig\Extension\ExtensionInterface $extension) { if ($this->extensionInitialized) { throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName())); @@ -1003,14 +1003,14 @@ public function setExtensions(array $extensions) /** * Returns all registered extensions. * - * @return Twig_ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) + * @return \Twig\Extension\ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) */ public function getExtensions() { return $this->extensions; } - public function addTokenParser(Twig_TokenParserInterface $parser) + public function addTokenParser(\Twig\TokenParser\TokenParserInterface $parser) { if ($this->extensionInitialized) { throw new \LogicException('Unable to add a token parser as extensions have already been initialized.'); @@ -1040,7 +1040,7 @@ public function getTokenParsers() * * Be warned that this method cannot return tags defined by Twig_TokenParserBrokerInterface classes. * - * @return Twig_TokenParserInterface[] + * @return \Twig\TokenParser\TokenParserInterface[] * * @internal */ @@ -1048,7 +1048,7 @@ public function getTags() { $tags = []; foreach ($this->getTokenParsers()->getParsers() as $parser) { - if ($parser instanceof Twig_TokenParserInterface) { + if ($parser instanceof \Twig\TokenParser\TokenParserInterface) { $tags[$parser->getTag()] = $parser; } } @@ -1056,7 +1056,7 @@ public function getTags() return $tags; } - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) + public function addNodeVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor) { if ($this->extensionInitialized) { throw new \LogicException('Unable to add a node visitor as extensions have already been initialized.'); @@ -1068,7 +1068,7 @@ public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) /** * Gets the registered Node Visitors. * - * @return Twig_NodeVisitorInterface[] + * @return \Twig\NodeVisitor\NodeVisitorInterface[] * * @internal */ @@ -1084,16 +1084,16 @@ public function getNodeVisitors() /** * Registers a Filter. * - * @param string|Twig_SimpleFilter $name The filter name or a Twig_SimpleFilter instance - * @param Twig_FilterInterface|Twig_SimpleFilter $filter + * @param string|\Twig\TwigFilter $name The filter name or a Twig_SimpleFilter instance + * @param Twig_FilterInterface|\Twig\TwigFilter $filter */ public function addFilter($name, $filter = null) { - if (!$name instanceof Twig_SimpleFilter && !($filter instanceof Twig_SimpleFilter || $filter instanceof Twig_FilterInterface)) { + if (!$name instanceof \Twig\TwigFilter && !($filter instanceof \Twig\TwigFilter || $filter instanceof Twig_FilterInterface)) { throw new \LogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter.'); } - if ($name instanceof Twig_SimpleFilter) { + if ($name instanceof \Twig\TwigFilter) { $filter = $name; $name = $filter->getName(); } else { @@ -1179,16 +1179,16 @@ public function getFilters() /** * Registers a Test. * - * @param string|Twig_SimpleTest $name The test name or a Twig_SimpleTest instance - * @param Twig_TestInterface|Twig_SimpleTest $test A Twig_TestInterface instance or a Twig_SimpleTest instance + * @param string|\Twig\TwigTest $name The test name or a Twig_SimpleTest instance + * @param Twig_TestInterface|\Twig\TwigTest $test A Twig_TestInterface instance or a Twig_SimpleTest instance */ public function addTest($name, $test = null) { - if (!$name instanceof Twig_SimpleTest && !($test instanceof Twig_SimpleTest || $test instanceof Twig_TestInterface)) { + if (!$name instanceof \Twig\TwigTest && !($test instanceof \Twig\TwigTest || $test instanceof Twig_TestInterface)) { throw new \LogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest.'); } - if ($name instanceof Twig_SimpleTest) { + if ($name instanceof \Twig\TwigTest) { $test = $name; $name = $test->getName(); } else { @@ -1256,16 +1256,16 @@ public function getTest($name) /** * Registers a Function. * - * @param string|Twig_SimpleFunction $name The function name or a Twig_SimpleFunction instance - * @param Twig_FunctionInterface|Twig_SimpleFunction $function + * @param string|\Twig\TwigFunction $name The function name or a Twig_SimpleFunction instance + * @param Twig_FunctionInterface|\Twig\TwigFunction $function */ public function addFunction($name, $function = null) { - if (!$name instanceof Twig_SimpleFunction && !($function instanceof Twig_SimpleFunction || $function instanceof Twig_FunctionInterface)) { + if (!$name instanceof \Twig\TwigFunction && !($function instanceof \Twig\TwigFunction || $function instanceof Twig_FunctionInterface)) { throw new \LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction.'); } - if ($name instanceof Twig_SimpleFunction) { + if ($name instanceof \Twig\TwigFunction) { $function = $name; $name = $function->getName(); } else { @@ -1458,7 +1458,7 @@ public function computeAlternatives($name, $items) { @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - return Twig_Error_Syntax::computeAlternatives($name, $items); + return \Twig\Error\SyntaxError::computeAlternatives($name, $items); } /** @@ -1468,7 +1468,7 @@ protected function initGlobals() { $globals = []; foreach ($this->extensions as $name => $extension) { - if (!$extension instanceof Twig_Extension_GlobalsInterface) { + if (!$extension instanceof \Twig\Extension\GlobalsInterface) { $m = new \ReflectionMethod($extension, 'getGlobals'); if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) { @@ -1517,11 +1517,11 @@ protected function initExtensions() /** * @internal */ - protected function initExtension(Twig_ExtensionInterface $extension) + protected function initExtension(\Twig\Extension\ExtensionInterface $extension) { // filters foreach ($extension->getFilters() as $name => $filter) { - if ($filter instanceof Twig_SimpleFilter) { + if ($filter instanceof \Twig\TwigFilter) { $name = $filter->getName(); } else { @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use Twig_SimpleFilter instead.', \get_class($filter), $name), E_USER_DEPRECATED); @@ -1532,7 +1532,7 @@ protected function initExtension(Twig_ExtensionInterface $extension) // functions foreach ($extension->getFunctions() as $name => $function) { - if ($function instanceof Twig_SimpleFunction) { + if ($function instanceof \Twig\TwigFunction) { $name = $function->getName(); } else { @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use Twig_SimpleFunction instead.', \get_class($function), $name), E_USER_DEPRECATED); @@ -1543,7 +1543,7 @@ protected function initExtension(Twig_ExtensionInterface $extension) // tests foreach ($extension->getTests() as $name => $test) { - if ($test instanceof Twig_SimpleTest) { + if ($test instanceof \Twig\TwigTest) { $name = $test->getName(); } else { @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use Twig_SimpleTest instead.', \get_class($test), $name), E_USER_DEPRECATED); @@ -1554,7 +1554,7 @@ protected function initExtension(Twig_ExtensionInterface $extension) // token parsers foreach ($extension->getTokenParsers() as $parser) { - if ($parser instanceof Twig_TokenParserInterface) { + if ($parser instanceof \Twig\TokenParser\TokenParserInterface) { $this->parsers->addTokenParser($parser); } elseif ($parser instanceof Twig_TokenParserBrokerInterface) { @trigger_error('Registering a Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED); diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index 467e019486..81b95e9137 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -53,16 +53,16 @@ class Twig_Error extends \Exception * * By default, automatic guessing is enabled. * - * @param string $message The error message - * @param int $lineno The template line where the error occurred - * @param Twig_Source|string|null $source The source context where the error occurred - * @param \Exception $previous The previous exception + * @param string $message The error message + * @param int $lineno The template line where the error occurred + * @param \Twig\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) { if (null === $source) { $name = null; - } elseif (!$source instanceof Twig_Source) { + } elseif (!$source instanceof \Twig\Source) { // for compat with the Twig C ext., passing the template name as string is accepted $name = $source; } else { @@ -180,17 +180,17 @@ public function setTemplateLine($lineno) /** * Gets the source context of the Twig template where the error occurred. * - * @return Twig_Source|null + * @return \Twig\Source|null */ public function getSourceContext() { - return $this->filename ? new Twig_Source($this->sourceCode, $this->filename, $this->sourcePath) : null; + return $this->filename ? new \Twig\Source($this->sourceCode, $this->filename, $this->sourcePath) : null; } /** * Sets the source context of the Twig template where the error occurred. */ - public function setSourceContext(Twig_Source $source = null) + public function setSourceContext(\Twig\Source $source = null) { if (null === $source) { $this->sourceCode = $this->filename = $this->sourcePath = null; @@ -273,7 +273,7 @@ protected function guessTemplateInfo() $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); foreach ($backtrace as $trace) { - if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== \get_class($trace['object'])) { + if (isset($trace['object']) && $trace['object'] instanceof \Twig\Template && 'Twig_Template' !== \get_class($trace['object'])) { $currentClass = \get_class($trace['object']); $isEmbedContainer = 0 === strpos($templateClass, $currentClass); if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) { diff --git a/lib/Twig/Error/Loader.php b/lib/Twig/Error/Loader.php index 8644bc8772..281be82b11 100644 --- a/lib/Twig/Error/Loader.php +++ b/lib/Twig/Error/Loader.php @@ -16,13 +16,13 @@ * if a template cannot be loaded, there is nothing to guess. * However, when a template is loaded from another one, then, we need * to find the current context and this is automatically done by - * Twig_Template::displayWithErrorHandling(). + * \Twig\Template::displayWithErrorHandling(). * - * This strategy makes Twig_Environment::resolveTemplate() much faster. + * This strategy makes \Twig\Environment::resolveTemplate() much faster. * * @author Fabien Potencier */ -class Twig_Error_Loader extends Twig_Error +class Twig_Error_Loader extends \Twig\Error\Error { public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null) { diff --git a/lib/Twig/Error/Runtime.php b/lib/Twig/Error/Runtime.php index 3b24ad3a4c..841086de3b 100644 --- a/lib/Twig/Error/Runtime.php +++ b/lib/Twig/Error/Runtime.php @@ -15,7 +15,7 @@ * * @author Fabien Potencier */ -class Twig_Error_Runtime extends Twig_Error +class Twig_Error_Runtime extends \Twig\Error\Error { } diff --git a/lib/Twig/Error/Syntax.php b/lib/Twig/Error/Syntax.php index 3534851c42..682eacbeb1 100644 --- a/lib/Twig/Error/Syntax.php +++ b/lib/Twig/Error/Syntax.php @@ -15,7 +15,7 @@ * * @author Fabien Potencier */ -class Twig_Error_Syntax extends Twig_Error +class Twig_Error_Syntax extends \Twig\Error\Error { /** * Tweaks the error message to include suggestions. diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index cab6421561..2e43b7c17d 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -33,11 +33,11 @@ class Twig_ExpressionParser private $env; - public function __construct(Twig_Parser $parser, $env = null) + public function __construct(\Twig\Parser $parser, $env = null) { $this->parser = $parser; - if ($env instanceof Twig_Environment) { + if ($env instanceof \Twig\Environment) { $this->env = $env; $this->unaryOperators = $env->getUnaryOperators(); $this->binaryOperators = $env->getBinaryOperators(); @@ -91,10 +91,10 @@ protected function getPrimary() $class = $operator['class']; return $this->parsePostfixExpression(new $class($expr, $token->getLine())); - } elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '(')) { + } elseif ($token->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { $this->parser->getStream()->next(); $expr = $this->parseExpression(); - $this->parser->getStream()->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed'); + $this->parser->getStream()->expect(\Twig\Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed'); return $this->parsePostfixExpression($expr); } @@ -104,83 +104,83 @@ protected function getPrimary() protected function parseConditionalExpression($expr) { - while ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, '?')) { - if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) { + while ($this->parser->getStream()->nextIf(\Twig\Token::PUNCTUATION_TYPE, '?')) { + if (!$this->parser->getStream()->nextIf(\Twig\Token::PUNCTUATION_TYPE, ':')) { $expr2 = $this->parseExpression(); - if ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) { + if ($this->parser->getStream()->nextIf(\Twig\Token::PUNCTUATION_TYPE, ':')) { $expr3 = $this->parseExpression(); } else { - $expr3 = new Twig_Node_Expression_Constant('', $this->parser->getCurrentToken()->getLine()); + $expr3 = new \Twig\Node\Expression\ConstantExpression('', $this->parser->getCurrentToken()->getLine()); } } else { $expr2 = $expr; $expr3 = $this->parseExpression(); } - $expr = new Twig_Node_Expression_Conditional($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); + $expr = new \Twig\Node\Expression\ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); } return $expr; } - protected function isUnary(Twig_Token $token) + protected function isUnary(\Twig\Token $token) { - return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]); + return $token->test(\Twig\Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]); } - protected function isBinary(Twig_Token $token) + protected function isBinary(\Twig\Token $token) { - return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); + return $token->test(\Twig\Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); } public function parsePrimaryExpression() { $token = $this->parser->getCurrentToken(); switch ($token->getType()) { - case Twig_Token::NAME_TYPE: + case \Twig\Token::NAME_TYPE: $this->parser->getStream()->next(); switch ($token->getValue()) { case 'true': case 'TRUE': - $node = new Twig_Node_Expression_Constant(true, $token->getLine()); + $node = new \Twig\Node\Expression\ConstantExpression(true, $token->getLine()); break; case 'false': case 'FALSE': - $node = new Twig_Node_Expression_Constant(false, $token->getLine()); + $node = new \Twig\Node\Expression\ConstantExpression(false, $token->getLine()); break; case 'none': case 'NONE': case 'null': case 'NULL': - $node = new Twig_Node_Expression_Constant(null, $token->getLine()); + $node = new \Twig\Node\Expression\ConstantExpression(null, $token->getLine()); break; default: if ('(' === $this->parser->getCurrentToken()->getValue()) { $node = $this->getFunctionNode($token->getValue(), $token->getLine()); } else { - $node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine()); + $node = new \Twig\Node\Expression\NameExpression($token->getValue(), $token->getLine()); } } break; - case Twig_Token::NUMBER_TYPE: + case \Twig\Token::NUMBER_TYPE: $this->parser->getStream()->next(); - $node = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); + $node = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $token->getLine()); break; - case Twig_Token::STRING_TYPE: - case Twig_Token::INTERPOLATION_START_TYPE: + case \Twig\Token::STRING_TYPE: + case \Twig\Token::INTERPOLATION_START_TYPE: $node = $this->parseStringExpression(); break; - case Twig_Token::OPERATOR_TYPE: - if (preg_match(Twig_Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { + case \Twig\Token::OPERATOR_TYPE: + if (preg_match(\Twig\Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { // in this context, string operators are variable names $this->parser->getStream()->next(); - $node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine()); + $node = new \Twig\Node\Expression\NameExpression($token->getValue(), $token->getLine()); break; } elseif (isset($this->unaryOperators[$token->getValue()])) { $class = $this->unaryOperators[$token->getValue()]['class']; @@ -189,7 +189,7 @@ public function parsePrimaryExpression() $negClass = 'Twig_Node_Expression_Unary_Neg'; $posClass = 'Twig_Node_Expression_Unary_Pos'; if (!(\in_array($ref->getName(), [$negClass, $posClass]) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) { - throw new Twig_Error_Syntax(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); } $this->parser->getStream()->next(); @@ -201,14 +201,14 @@ public function parsePrimaryExpression() // no break default: - if ($token->test(Twig_Token::PUNCTUATION_TYPE, '[')) { + if ($token->test(\Twig\Token::PUNCTUATION_TYPE, '[')) { $node = $this->parseArrayExpression(); - } elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '{')) { + } elseif ($token->test(\Twig\Token::PUNCTUATION_TYPE, '{')) { $node = $this->parseHashExpression(); - } elseif ($token->test(Twig_Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { - throw new Twig_Error_Syntax(sprintf('Unexpected operator of value "%s". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead.', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + } elseif ($token->test(\Twig\Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { + throw new \Twig\Error\SyntaxError(sprintf('Unexpected operator of value "%s". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead.', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); } else { - throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s".', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('Unexpected token "%s" of value "%s".', \Twig\Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); } } @@ -223,12 +223,12 @@ public function parseStringExpression() // a string cannot be followed by another string in a single expression $nextCanBeString = true; while (true) { - if ($nextCanBeString && $token = $stream->nextIf(Twig_Token::STRING_TYPE)) { - $nodes[] = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); + if ($nextCanBeString && $token = $stream->nextIf(\Twig\Token::STRING_TYPE)) { + $nodes[] = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $token->getLine()); $nextCanBeString = false; - } elseif ($stream->nextIf(Twig_Token::INTERPOLATION_START_TYPE)) { + } elseif ($stream->nextIf(\Twig\Token::INTERPOLATION_START_TYPE)) { $nodes[] = $this->parseExpression(); - $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); + $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); $nextCanBeString = true; } else { break; @@ -237,7 +237,7 @@ public function parseStringExpression() $expr = array_shift($nodes); foreach ($nodes as $node) { - $expr = new Twig_Node_Expression_Binary_Concat($expr, $node, $node->getTemplateLine()); + $expr = new \Twig\Node\Expression\Binary\ConcatBinary($expr, $node, $node->getTemplateLine()); } return $expr; @@ -246,16 +246,16 @@ public function parseStringExpression() public function parseArrayExpression() { $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::PUNCTUATION_TYPE, '[', 'An array element was expected'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, '[', 'An array element was expected'); - $node = new Twig_Node_Expression_Array([], $stream->getCurrent()->getLine()); + $node = new \Twig\Node\Expression\ArrayExpression([], $stream->getCurrent()->getLine()); $first = true; - while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) { + while (!$stream->test(\Twig\Token::PUNCTUATION_TYPE, ']')) { if (!$first) { - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma'); // trailing ,? - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) { + if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, ']')) { break; } } @@ -263,7 +263,7 @@ public function parseArrayExpression() $node->addElement($this->parseExpression()); } - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed'); return $node; } @@ -271,16 +271,16 @@ public function parseArrayExpression() public function parseHashExpression() { $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::PUNCTUATION_TYPE, '{', 'A hash element was expected'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, '{', 'A hash element was expected'); - $node = new Twig_Node_Expression_Array([], $stream->getCurrent()->getLine()); + $node = new \Twig\Node\Expression\ArrayExpression([], $stream->getCurrent()->getLine()); $first = true; - while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, '}')) { + while (!$stream->test(\Twig\Token::PUNCTUATION_TYPE, '}')) { if (!$first) { - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma'); // trailing ,? - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '}')) { + if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '}')) { break; } } @@ -292,22 +292,22 @@ public function parseHashExpression() // * a string -- 'a' // * a name, which is equivalent to a string -- a // * an expression, which must be enclosed in parentheses -- (1 + 2) - if (($token = $stream->nextIf(Twig_Token::STRING_TYPE)) || ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) || $token = $stream->nextIf(Twig_Token::NUMBER_TYPE)) { - $key = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - } elseif ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { + if (($token = $stream->nextIf(\Twig\Token::STRING_TYPE)) || ($token = $stream->nextIf(\Twig\Token::NAME_TYPE)) || $token = $stream->nextIf(\Twig\Token::NUMBER_TYPE)) { + $key = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $token->getLine()); + } elseif ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { $key = $this->parseExpression(); } else { $current = $stream->getCurrent(); - throw new Twig_Error_Syntax(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', Twig_Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', \Twig\Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext()); } - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)'); $value = $this->parseExpression(); $node->addElement($value, $key); } - $stream->expect(Twig_Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed'); return $node; } @@ -316,7 +316,7 @@ public function parsePostfixExpression($node) { while (true) { $token = $this->parser->getCurrentToken(); - if (Twig_Token::PUNCTUATION_TYPE == $token->getType()) { + if (\Twig\Token::PUNCTUATION_TYPE == $token->getType()) { if ('.' == $token->getValue() || '[' == $token->getValue()) { $node = $this->parseSubscriptExpression($node); } elseif ('|' == $token->getValue()) { @@ -338,36 +338,36 @@ public function getFunctionNode($name, $line) case 'parent': $this->parseArguments(); if (!\count($this->parser->getBlockStack())) { - throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + throw new \Twig\Error\SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); } if (!$this->parser->getParent() && !$this->parser->hasTraits()) { - throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + throw new \Twig\Error\SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); } - return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line); + return new \Twig\Node\Expression\ParentExpression($this->parser->peekBlockStack(), $line); case 'block': $args = $this->parseArguments(); if (\count($args) < 1) { - throw new Twig_Error_Syntax('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); + throw new \Twig\Error\SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); } - return new Twig_Node_Expression_BlockReference($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line); + return new \Twig\Node\Expression\BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line); case 'attribute': $args = $this->parseArguments(); if (\count($args) < 2) { - throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); + throw new \Twig\Error\SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); } - return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Twig_Template::ANY_CALL, $line); + return new \Twig\Node\Expression\GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, \Twig\Template::ANY_CALL, $line); default: if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { - $arguments = new Twig_Node_Expression_Array([], $line); + $arguments = new \Twig\Node\Expression\ArrayExpression([], $line); foreach ($this->parseArguments() as $n) { $arguments->addElement($n); } - $node = new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $arguments, $line); + $node = new \Twig\Node\Expression\MethodCallExpression($alias['node'], $alias['name'], $arguments, $line); $node->setAttribute('safe', true); return $node; @@ -385,81 +385,81 @@ public function parseSubscriptExpression($node) $stream = $this->parser->getStream(); $token = $stream->next(); $lineno = $token->getLine(); - $arguments = new Twig_Node_Expression_Array([], $lineno); - $type = Twig_Template::ANY_CALL; + $arguments = new \Twig\Node\Expression\ArrayExpression([], $lineno); + $type = \Twig\Template::ANY_CALL; if ('.' == $token->getValue()) { $token = $stream->next(); if ( - Twig_Token::NAME_TYPE == $token->getType() + \Twig\Token::NAME_TYPE == $token->getType() || - Twig_Token::NUMBER_TYPE == $token->getType() + \Twig\Token::NUMBER_TYPE == $token->getType() || - (Twig_Token::OPERATOR_TYPE == $token->getType() && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) + (\Twig\Token::OPERATOR_TYPE == $token->getType() && preg_match(\Twig\Lexer::REGEX_NAME, $token->getValue())) ) { - $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno); + $arg = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $lineno); - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $type = Twig_Template::METHOD_CALL; + if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { + $type = \Twig\Template::METHOD_CALL; foreach ($this->parseArguments() as $n) { $arguments->addElement($n); } } } else { - throw new Twig_Error_Syntax('Expected name or number.', $lineno, $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext()); } - if ($node instanceof Twig_Node_Expression_Name && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { - if (!$arg instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); + if ($node instanceof \Twig\Node\Expression\NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { + if (!$arg instanceof \Twig\Node\Expression\ConstantExpression) { + throw new \Twig\Error\SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); } $name = $arg->getAttribute('value'); if ($this->parser->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); } - $node = new Twig_Node_Expression_MethodCall($node, 'get'.$name, $arguments, $lineno); + $node = new \Twig\Node\Expression\MethodCallExpression($node, 'get'.$name, $arguments, $lineno); $node->setAttribute('safe', true); return $node; } } else { - $type = Twig_Template::ARRAY_CALL; + $type = \Twig\Template::ARRAY_CALL; // slice? $slice = false; - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ':')) { + if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, ':')) { $slice = true; - $arg = new Twig_Node_Expression_Constant(0, $token->getLine()); + $arg = new \Twig\Node\Expression\ConstantExpression(0, $token->getLine()); } else { $arg = $this->parseExpression(); } - if ($stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) { + if ($stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ':')) { $slice = true; } if ($slice) { - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) { - $length = new Twig_Node_Expression_Constant(null, $token->getLine()); + if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, ']')) { + $length = new \Twig\Node\Expression\ConstantExpression(null, $token->getLine()); } else { $length = $this->parseExpression(); } $class = $this->getFilterNodeClass('slice', $token->getLine()); - $arguments = new Twig_Node([$arg, $length]); - $filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine()); + $arguments = new \Twig\Node\Node([$arg, $length]); + $filter = new $class($node, new \Twig\Node\Expression\ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine()); - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ']'); return $filter; } - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ']'); } - return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $type, $lineno); + return new \Twig\Node\Expression\GetAttrExpression($node, $arg, $arguments, $type, $lineno); } public function parseFilterExpression($node) @@ -472,11 +472,11 @@ public function parseFilterExpression($node) public function parseFilterExpressionRaw($node, $tag = null) { while (true) { - $token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE); + $token = $this->parser->getStream()->expect(\Twig\Token::NAME_TYPE); - $name = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $arguments = new Twig_Node(); + $name = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $token->getLine()); + if (!$this->parser->getStream()->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { + $arguments = new \Twig\Node\Node(); } else { $arguments = $this->parseArguments(true); } @@ -485,7 +485,7 @@ public function parseFilterExpressionRaw($node, $tag = null) $node = new $class($node, $name, $arguments, $token->getLine(), $tag); - if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '|')) { + if (!$this->parser->getStream()->test(\Twig\Token::PUNCTUATION_TYPE, '|')) { break; } @@ -501,32 +501,32 @@ public function parseFilterExpressionRaw($node, $tag = null) * @param bool $namedArguments Whether to allow named arguments or not * @param bool $definition Whether we are parsing arguments for a function definition * - * @return Twig_Node + * @return \Twig\Node\Node * - * @throws Twig_Error_Syntax + * @throws \Twig\Error\SyntaxError */ public function parseArguments($namedArguments = false, $definition = false) { $args = []; $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis'); - while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ')')) { + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis'); + while (!$stream->test(\Twig\Token::PUNCTUATION_TYPE, ')')) { if (!empty($args)) { - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma'); } if ($definition) { - $token = $stream->expect(Twig_Token::NAME_TYPE, null, 'An argument must be a name'); - $value = new Twig_Node_Expression_Name($token->getValue(), $this->parser->getCurrentToken()->getLine()); + $token = $stream->expect(\Twig\Token::NAME_TYPE, null, 'An argument must be a name'); + $value = new \Twig\Node\Expression\NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine()); } else { $value = $this->parseExpression(); } $name = null; - if ($namedArguments && $token = $stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) { - if (!$value instanceof Twig_Node_Expression_Name) { - throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); + if ($namedArguments && $token = $stream->nextIf(\Twig\Token::OPERATOR_TYPE, '=')) { + if (!$value instanceof \Twig\Node\Expression\NameExpression) { + throw new \Twig\Error\SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); } $name = $value->getAttribute('name'); @@ -534,7 +534,7 @@ public function parseArguments($namedArguments = false, $definition = false) $value = $this->parsePrimaryExpression(); if (!$this->checkConstantExpression($value)) { - throw new Twig_Error_Syntax(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext()); } } else { $value = $this->parseExpression(); @@ -544,7 +544,7 @@ public function parseArguments($namedArguments = false, $definition = false) if ($definition) { if (null === $name) { $name = $value->getAttribute('name'); - $value = new Twig_Node_Expression_Constant(null, $this->parser->getCurrentToken()->getLine()); + $value = new \Twig\Node\Expression\ConstantExpression(null, $this->parser->getCurrentToken()->getLine()); } $args[$name] = $value; } else { @@ -555,9 +555,9 @@ public function parseArguments($namedArguments = false, $definition = false) } } } - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis'); + $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis'); - return new Twig_Node($args); + return new \Twig\Node\Node($args); } public function parseAssignmentExpression() @@ -565,19 +565,19 @@ public function parseAssignmentExpression() $stream = $this->parser->getStream(); $targets = []; while (true) { - $token = $stream->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to'); + $token = $stream->expect(\Twig\Token::NAME_TYPE, null, 'Only variables can be assigned to'); $value = $token->getValue(); if (\in_array(strtolower($value), ['true', 'false', 'none', 'null'])) { - throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); } - $targets[] = new Twig_Node_Expression_AssignName($value, $token->getLine()); + $targets[] = new \Twig\Node\Expression\AssignNameExpression($value, $token->getLine()); - if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { + if (!$stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) { break; } } - return new Twig_Node($targets); + return new \Twig\Node\Node($targets); } public function parseMultitargetExpression() @@ -585,17 +585,17 @@ public function parseMultitargetExpression() $targets = []; while (true) { $targets[] = $this->parseExpression(); - if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { + if (!$this->parser->getStream()->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) { break; } } - return new Twig_Node($targets); + return new \Twig\Node\Node($targets); } private function parseNotTestExpression(Twig_NodeInterface $node) { - return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); + return new \Twig\Node\Expression\Unary\NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); } private function parseTestExpression(Twig_NodeInterface $node) @@ -605,7 +605,7 @@ private function parseTestExpression(Twig_NodeInterface $node) $class = $this->getTestNodeClass($test); $arguments = null; - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { + if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { $arguments = $this->parser->getExpressionParser()->parseArguments(true); } @@ -615,13 +615,13 @@ private function parseTestExpression(Twig_NodeInterface $node) private function getTest($line) { $stream = $this->parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); if ($test = $this->env->getTest($name)) { return [$name, $test]; } - if ($stream->test(Twig_Token::NAME_TYPE)) { + if ($stream->test(\Twig\Token::NAME_TYPE)) { // try 2-words tests $name = $name.' '.$this->parser->getCurrentToken()->getValue(); @@ -632,7 +632,7 @@ private function getTest($line) } } - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); + $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); $e->addSuggestions($name, array_keys($this->env->getTests())); throw $e; @@ -640,7 +640,7 @@ private function getTest($line) private function getTestNodeClass($test) { - if ($test instanceof Twig_SimpleTest && $test->isDeprecated()) { + if ($test instanceof \Twig\TwigTest && $test->isDeprecated()) { $stream = $this->parser->getStream(); $message = sprintf('Twig Test "%s" is deprecated', $test->getName()); if (!\is_bool($test->getDeprecatedVersion())) { @@ -655,7 +655,7 @@ private function getTestNodeClass($test) @trigger_error($message, E_USER_DEPRECATED); } - if ($test instanceof Twig_SimpleTest) { + if ($test instanceof \Twig\TwigTest) { return $test->getNodeClass(); } @@ -665,13 +665,13 @@ private function getTestNodeClass($test) protected function getFunctionNodeClass($name, $line) { if (false === $function = $this->env->getFunction($name)) { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); $e->addSuggestions($name, array_keys($this->env->getFunctions())); throw $e; } - if ($function instanceof Twig_SimpleFunction && $function->isDeprecated()) { + if ($function instanceof \Twig\TwigFunction && $function->isDeprecated()) { $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); if (!\is_bool($function->getDeprecatedVersion())) { $message .= sprintf(' since version %s', $function->getDeprecatedVersion()); @@ -685,7 +685,7 @@ protected function getFunctionNodeClass($name, $line) @trigger_error($message, E_USER_DEPRECATED); } - if ($function instanceof Twig_SimpleFunction) { + if ($function instanceof \Twig\TwigFunction) { return $function->getNodeClass(); } @@ -695,13 +695,13 @@ protected function getFunctionNodeClass($name, $line) protected function getFilterNodeClass($name, $line) { if (false === $filter = $this->env->getFilter($name)) { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); $e->addSuggestions($name, array_keys($this->env->getFilters())); throw $e; } - if ($filter instanceof Twig_SimpleFilter && $filter->isDeprecated()) { + if ($filter instanceof \Twig\TwigFilter && $filter->isDeprecated()) { $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); if (!\is_bool($filter->getDeprecatedVersion())) { $message .= sprintf(' since version %s', $filter->getDeprecatedVersion()); @@ -715,7 +715,7 @@ protected function getFilterNodeClass($name, $line) @trigger_error($message, E_USER_DEPRECATED); } - if ($filter instanceof Twig_SimpleFilter) { + if ($filter instanceof \Twig\TwigFilter) { return $filter->getNodeClass(); } @@ -725,8 +725,8 @@ protected function getFilterNodeClass($name, $line) // checks that the node only contains "constant" elements protected function checkConstantExpression(Twig_NodeInterface $node) { - if (!($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array - || $node instanceof Twig_Node_Expression_Unary_Neg || $node instanceof Twig_Node_Expression_Unary_Pos + if (!($node instanceof \Twig\Node\Expression\ConstantExpression || $node instanceof \Twig\Node\Expression\ArrayExpression + || $node instanceof \Twig\Node\Expression\Unary\NegUnary || $node instanceof \Twig\Node\Expression\Unary\PosUnary )) { return false; } diff --git a/lib/Twig/Extension.php b/lib/Twig/Extension.php index 1dffaeb46f..58cc53503d 100644 --- a/lib/Twig/Extension.php +++ b/lib/Twig/Extension.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -abstract class Twig_Extension implements Twig_ExtensionInterface +abstract class Twig_Extension implements \Twig\Extension\ExtensionInterface { /** * @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead */ - public function initRuntime(Twig_Environment $environment) + public function initRuntime(\Twig\Environment $environment) { } diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index c2bfbafe33..cea6546188 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -16,7 +16,7 @@ /** * @final */ -class Twig_Extension_Core extends Twig_Extension +class Twig_Extension_Core extends \Twig\Extension\AbstractExtension { protected $dateFormats = ['F j, Y H:i', '%d days']; protected $numberFormat = [0, '.', ',']; @@ -120,23 +120,23 @@ public function getNumberFormat() public function getTokenParsers() { return [ - new Twig_TokenParser_For(), - new Twig_TokenParser_If(), - new Twig_TokenParser_Extends(), - new Twig_TokenParser_Include(), - new Twig_TokenParser_Block(), - new Twig_TokenParser_Use(), - new Twig_TokenParser_Filter(), - new Twig_TokenParser_Macro(), - new Twig_TokenParser_Import(), - new Twig_TokenParser_From(), - new Twig_TokenParser_Set(), - new Twig_TokenParser_Spaceless(), - new Twig_TokenParser_Flush(), - new Twig_TokenParser_Do(), - new Twig_TokenParser_Embed(), - new Twig_TokenParser_With(), - new Twig_TokenParser_Deprecated(), + new \Twig\TokenParser\ForTokenParser(), + new \Twig\TokenParser\IfTokenParser(), + new \Twig\TokenParser\ExtendsTokenParser(), + new \Twig\TokenParser\IncludeTokenParser(), + new \Twig\TokenParser\BlockTokenParser(), + new \Twig\TokenParser\UseTokenParser(), + new \Twig\TokenParser\FilterTokenParser(), + new \Twig\TokenParser\MacroTokenParser(), + new \Twig\TokenParser\ImportTokenParser(), + new \Twig\TokenParser\FromTokenParser(), + new \Twig\TokenParser\SetTokenParser(), + new \Twig\TokenParser\SpacelessTokenParser(), + new \Twig\TokenParser\FlushTokenParser(), + new \Twig\TokenParser\DoTokenParser(), + new \Twig\TokenParser\EmbedTokenParser(), + new \Twig\TokenParser\WithTokenParser(), + new \Twig\TokenParser\DeprecatedTokenParser(), ]; } @@ -144,54 +144,54 @@ public function getFilters() { $filters = [ // formatting filters - new Twig_SimpleFilter('date', 'twig_date_format_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('format', 'sprintf'), - new Twig_SimpleFilter('replace', 'twig_replace_filter'), - new Twig_SimpleFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('abs', 'abs'), - new Twig_SimpleFilter('round', 'twig_round'), + new \Twig\TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]), + new \Twig\TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), + new \Twig\TwigFilter('format', 'sprintf'), + new \Twig\TwigFilter('replace', 'twig_replace_filter'), + new \Twig\TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), + new \Twig\TwigFilter('abs', 'abs'), + new \Twig\TwigFilter('round', 'twig_round'), // encoding - new Twig_SimpleFilter('url_encode', 'twig_urlencode_filter'), - new Twig_SimpleFilter('json_encode', 'twig_jsonencode_filter'), - new Twig_SimpleFilter('convert_encoding', 'twig_convert_encoding'), + new \Twig\TwigFilter('url_encode', 'twig_urlencode_filter'), + new \Twig\TwigFilter('json_encode', 'twig_jsonencode_filter'), + new \Twig\TwigFilter('convert_encoding', 'twig_convert_encoding'), // string filters - new Twig_SimpleFilter('title', 'twig_title_string_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('upper', 'strtoupper'), - new Twig_SimpleFilter('lower', 'strtolower'), - new Twig_SimpleFilter('striptags', 'strip_tags'), - new Twig_SimpleFilter('trim', 'twig_trim_filter'), - new Twig_SimpleFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), + new \Twig\TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]), + new \Twig\TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), + new \Twig\TwigFilter('upper', 'strtoupper'), + new \Twig\TwigFilter('lower', 'strtolower'), + new \Twig\TwigFilter('striptags', 'strip_tags'), + new \Twig\TwigFilter('trim', 'twig_trim_filter'), + new \Twig\TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), // array helpers - new Twig_SimpleFilter('join', 'twig_join_filter'), - new Twig_SimpleFilter('split', 'twig_split_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('sort', 'twig_sort_filter'), - new Twig_SimpleFilter('merge', 'twig_array_merge'), - new Twig_SimpleFilter('batch', 'twig_array_batch'), + new \Twig\TwigFilter('join', 'twig_join_filter'), + new \Twig\TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]), + new \Twig\TwigFilter('sort', 'twig_sort_filter'), + new \Twig\TwigFilter('merge', 'twig_array_merge'), + new \Twig\TwigFilter('batch', 'twig_array_batch'), // string/array filters - new Twig_SimpleFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('length', 'twig_length_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('slice', 'twig_slice', ['needs_environment' => true]), - new Twig_SimpleFilter('first', 'twig_first', ['needs_environment' => true]), - new Twig_SimpleFilter('last', 'twig_last', ['needs_environment' => true]), + new \Twig\TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), + new \Twig\TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]), + new \Twig\TwigFilter('slice', 'twig_slice', ['needs_environment' => true]), + new \Twig\TwigFilter('first', 'twig_first', ['needs_environment' => true]), + new \Twig\TwigFilter('last', 'twig_last', ['needs_environment' => true]), // iteration and runtime - new Twig_SimpleFilter('default', '_twig_default_filter', ['node_class' => 'Twig_Node_Expression_Filter_Default']), - new Twig_SimpleFilter('keys', 'twig_get_array_keys_filter'), + new \Twig\TwigFilter('default', '_twig_default_filter', ['node_class' => '\Twig\Node\Expression\Filter\DefaultFilter']), + new \Twig\TwigFilter('keys', 'twig_get_array_keys_filter'), // escaping - new Twig_SimpleFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), - new Twig_SimpleFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new \Twig\TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new \Twig\TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), ]; if (\function_exists('mb_get_info')) { - $filters[] = new Twig_SimpleFilter('upper', 'twig_upper_filter', ['needs_environment' => true]); - $filters[] = new Twig_SimpleFilter('lower', 'twig_lower_filter', ['needs_environment' => true]); + $filters[] = new \Twig\TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]); + $filters[] = new \Twig\TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]); } return $filters; @@ -200,33 +200,33 @@ public function getFilters() public function getFunctions() { return [ - new Twig_SimpleFunction('max', 'max'), - new Twig_SimpleFunction('min', 'min'), - new Twig_SimpleFunction('range', 'range'), - new Twig_SimpleFunction('constant', 'twig_constant'), - new Twig_SimpleFunction('cycle', 'twig_cycle'), - new Twig_SimpleFunction('random', 'twig_random', ['needs_environment' => true]), - new Twig_SimpleFunction('date', 'twig_date_converter', ['needs_environment' => true]), - new Twig_SimpleFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), - new Twig_SimpleFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), + new \Twig\TwigFunction('max', 'max'), + new \Twig\TwigFunction('min', 'min'), + new \Twig\TwigFunction('range', 'range'), + new \Twig\TwigFunction('constant', 'twig_constant'), + new \Twig\TwigFunction('cycle', 'twig_cycle'), + new \Twig\TwigFunction('random', 'twig_random', ['needs_environment' => true]), + new \Twig\TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]), + new \Twig\TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), + new \Twig\TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), ]; } public function getTests() { return [ - new Twig_SimpleTest('even', null, ['node_class' => 'Twig_Node_Expression_Test_Even']), - new Twig_SimpleTest('odd', null, ['node_class' => 'Twig_Node_Expression_Test_Odd']), - new Twig_SimpleTest('defined', null, ['node_class' => 'Twig_Node_Expression_Test_Defined']), - new Twig_SimpleTest('sameas', null, ['node_class' => 'Twig_Node_Expression_Test_Sameas', 'deprecated' => '1.21', 'alternative' => 'same as']), - new Twig_SimpleTest('same as', null, ['node_class' => 'Twig_Node_Expression_Test_Sameas']), - new Twig_SimpleTest('none', null, ['node_class' => 'Twig_Node_Expression_Test_Null']), - new Twig_SimpleTest('null', null, ['node_class' => 'Twig_Node_Expression_Test_Null']), - new Twig_SimpleTest('divisibleby', null, ['node_class' => 'Twig_Node_Expression_Test_Divisibleby', 'deprecated' => '1.21', 'alternative' => 'divisible by']), - new Twig_SimpleTest('divisible by', null, ['node_class' => 'Twig_Node_Expression_Test_Divisibleby']), - new Twig_SimpleTest('constant', null, ['node_class' => 'Twig_Node_Expression_Test_Constant']), - new Twig_SimpleTest('empty', 'twig_test_empty'), - new Twig_SimpleTest('iterable', 'twig_test_iterable'), + new \Twig\TwigTest('even', null, ['node_class' => '\Twig\Node\Expression\Test\EvenTest']), + new \Twig\TwigTest('odd', null, ['node_class' => '\Twig\Node\Expression\Test\OddTest']), + new \Twig\TwigTest('defined', null, ['node_class' => '\Twig\Node\Expression\Test\DefinedTest']), + new \Twig\TwigTest('sameas', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest', 'deprecated' => '1.21', 'alternative' => 'same as']), + new \Twig\TwigTest('same as', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest']), + new \Twig\TwigTest('none', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']), + new \Twig\TwigTest('null', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']), + new \Twig\TwigTest('divisibleby', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest', 'deprecated' => '1.21', 'alternative' => 'divisible by']), + new \Twig\TwigTest('divisible by', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest']), + new \Twig\TwigTest('constant', null, ['node_class' => '\Twig\Node\Expression\Test\ConstantTest']), + new \Twig\TwigTest('empty', 'twig_test_empty'), + new \Twig\TwigTest('iterable', 'twig_test_iterable'), ]; } @@ -234,39 +234,39 @@ public function getOperators() { return [ [ - 'not' => ['precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'], - '-' => ['precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Neg'], - '+' => ['precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Pos'], + 'not' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'], + '-' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\NegUnary'], + '+' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\PosUnary'], ], [ - 'or' => ['precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'and' => ['precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-or' => ['precedence' => 16, 'class' => 'Twig_Node_Expression_Binary_BitwiseOr', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-xor' => ['precedence' => 17, 'class' => 'Twig_Node_Expression_Binary_BitwiseXor', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-and' => ['precedence' => 18, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '==' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '!=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '<' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '>' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '>=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '<=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'not in' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotIn', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'in' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_In', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'matches' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Matches', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'starts with' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_StartsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'ends with' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_EndsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '..' => ['precedence' => 25, 'class' => 'Twig_Node_Expression_Binary_Range', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '+' => ['precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Add', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '-' => ['precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Sub', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '~' => ['precedence' => 40, 'class' => 'Twig_Node_Expression_Binary_Concat', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '*' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mul', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '/' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Div', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '//' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_FloorDiv', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '%' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'is' => ['precedence' => 100, 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'is not' => ['precedence' => 100, 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '**' => ['precedence' => 200, 'class' => 'Twig_Node_Expression_Binary_Power', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT], - '??' => ['precedence' => 300, 'class' => 'Twig_Node_Expression_NullCoalesce', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT], + 'or' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'and' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'b-or' => ['precedence' => 16, 'class' => '\Twig\Node\Expression\Binary\BitwiseOrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'b-xor' => ['precedence' => 17, 'class' => '\Twig\Node\Expression\Binary\BitwiseXorBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'b-and' => ['precedence' => 18, 'class' => '\Twig\Node\Expression\Binary\BitwiseAndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '==' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '!=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '<' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '>' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '>=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '<=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'not in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotInBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\InBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'matches' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\MatchesBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'starts with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\StartsWithBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'ends with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EndsWithBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '..' => ['precedence' => 25, 'class' => '\Twig\Node\Expression\Binary\RangeBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '+' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\AddBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '-' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\SubBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '~' => ['precedence' => 40, 'class' => '\Twig\Node\Expression\Binary\ConcatBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '*' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\MulBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '/' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\DivBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '//' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\FloorDivBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '%' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\ModBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'is' => ['precedence' => 100, 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + 'is not' => ['precedence' => 100, 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], + '**' => ['precedence' => 200, 'class' => '\Twig\Node\Expression\Binary\PowerBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_RIGHT], + '??' => ['precedence' => 300, 'class' => '\Twig\Node\Expression\NullCoalesceExpression', 'associativity' => \Twig\ExpressionParser::OPERATOR_RIGHT], ], ]; } @@ -302,7 +302,7 @@ function twig_cycle($values, $position) * * @param \Traversable|array|int|float|string $values The values to pick a random item from * - * @throws Twig_Error_Runtime when $values is an empty array (does not apply to an empty string which is returned as is) + * @throws \Twig\Error\RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is) * * @return mixed A random value from the given sequence */ @@ -346,7 +346,7 @@ function twig_random(Twig_Environment $env, $values = null) } if (0 === \count($values)) { - throw new Twig_Error_Runtime('The random function cannot pick from an empty array.'); + throw new \Twig\Error\RuntimeError('The random function cannot pick from an empty array.'); } return $values[array_rand($values, 1)]; @@ -366,7 +366,7 @@ function twig_random(Twig_Environment $env, $values = null) function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $timezone = null) { if (null === $format) { - $formats = $env->getExtension('Twig_Extension_Core')->getDateFormat(); + $formats = $env->getExtension('\Twig\Extension\CoreExtension')->getDateFormat(); $format = $date instanceof \DateInterval ? $formats[1] : $formats[0]; } @@ -415,7 +415,7 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu // determine the timezone if (false !== $timezone) { if (null === $timezone) { - $timezone = $env->getExtension('Twig_Extension_Core')->getTimezone(); + $timezone = $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone(); } elseif (!$timezone instanceof \DateTimeZone) { $timezone = new \DateTimeZone($timezone); } @@ -436,14 +436,14 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu } if (null === $date || 'now' === $date) { - return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension('Twig_Extension_Core')->getTimezone()); + return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone()); } $asString = (string) $date; if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { $date = new \DateTime('@'.$date); } else { - $date = new \DateTime($date, $env->getExtension('Twig_Extension_Core')->getTimezone()); + $date = new \DateTime($date, $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone()); } if (false !== $timezone) { @@ -471,7 +471,7 @@ function twig_replace_filter($str, $from, $to = null) return strtr($str, $from, $to); } elseif (!\is_array($from)) { - throw new Twig_Error_Runtime(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from))); + throw new \Twig\Error\RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from))); } return strtr($str, $from); @@ -493,7 +493,7 @@ function twig_round($value, $precision = 0, $method = 'common') } if ('ceil' != $method && 'floor' != $method) { - throw new Twig_Error_Runtime('The round filter only supports the "common", "ceil", and "floor" methods.'); + throw new \Twig\Error\RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.'); } return $method($value * pow(10, $precision)) / pow(10, $precision); @@ -515,7 +515,7 @@ function twig_round($value, $precision = 0, $method = 'common') */ function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) { - $defaults = $env->getExtension('Twig_Extension_Core')->getNumberFormat(); + $defaults = $env->getExtension('\Twig\Extension\CoreExtension')->getNumberFormat(); if (null === $decimal) { $decimal = $defaults[0]; } @@ -561,7 +561,7 @@ function twig_urlencode_filter($url) */ function twig_jsonencode_filter($value, $options = 0) { - if ($value instanceof Twig_Markup) { + if ($value instanceof \Twig\Markup) { $value = (string) $value; } elseif (\is_array($value)) { array_walk_recursive($value, '_twig_markup2string'); @@ -572,7 +572,7 @@ function twig_jsonencode_filter($value, $options = 0) function _twig_markup2string(&$value) { - if ($value instanceof Twig_Markup) { + if ($value instanceof \Twig\Markup) { $value = (string) $value; } } @@ -596,13 +596,13 @@ function twig_array_merge($arr1, $arr2) if ($arr1 instanceof \Traversable) { $arr1 = iterator_to_array($arr1); } elseif (!\is_array($arr1)) { - throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1))); + throw new \Twig\Error\RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1))); } if ($arr2 instanceof \Traversable) { $arr2 = iterator_to_array($arr2); } elseif (!\is_array($arr2)) { - throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); + throw new \Twig\Error\RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); } return array_merge($arr1, $arr2); @@ -881,7 +881,7 @@ function twig_sort_filter($array) if ($array instanceof \Traversable) { $array = iterator_to_array($array); } elseif (!\is_array($array)) { - throw new Twig_Error_Runtime(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array))); + throw new \Twig\Error\RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array))); } asort($array); @@ -924,7 +924,7 @@ function twig_in_filter($value, $compare) * * @return string * - * @throws Twig_Error_Runtime When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') + * @throws \Twig\Error\RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') */ function twig_trim_filter($string, $characterMask = null, $side = 'both') { @@ -940,7 +940,7 @@ function twig_trim_filter($string, $characterMask = null, $side = 'both') case 'right': return rtrim($string, $characterMask); default: - throw new Twig_Error_Runtime('Trimming side must be "left", "right" or "both".'); + throw new \Twig\Error\RuntimeError('Trimming side must be "left", "right" or "both".'); } } @@ -956,7 +956,7 @@ function twig_trim_filter($string, $characterMask = null, $side = 'both') */ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) { - if ($autoescape && $string instanceof Twig_Markup) { + if ($autoescape && $string instanceof \Twig\Markup) { return $string; } @@ -1024,7 +1024,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', } if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); + throw new \Twig\Error\RuntimeError('The string to escape is not a valid UTF-8 string.'); } $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', '_twig_escape_js_callback', $string); @@ -1041,7 +1041,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', } if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); + throw new \Twig\Error\RuntimeError('The string to escape is not a valid UTF-8 string.'); } $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string); @@ -1058,7 +1058,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', } if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); + throw new \Twig\Error\RuntimeError('The string to escape is not a valid UTF-8 string.'); } $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', '_twig_escape_html_attr_callback', $string); @@ -1076,7 +1076,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', static $escapers; if (null === $escapers) { - $escapers = $env->getExtension('Twig_Extension_Core')->getEscapers(); + $escapers = $env->getExtension('\Twig\Extension\CoreExtension')->getEscapers(); } if (isset($escapers[$strategy])) { @@ -1085,7 +1085,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers))); - throw new Twig_Error_Runtime(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); + throw new \Twig\Error\RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); } } @@ -1095,7 +1095,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', function twig_escape_filter_is_safe(Twig_Node $filterArgs) { foreach ($filterArgs as $arg) { - if ($arg instanceof Twig_Node_Expression_Constant) { + if ($arg instanceof \Twig\Node\Expression\ConstantExpression) { return [$arg->getAttribute('value')]; } @@ -1118,7 +1118,7 @@ function twig_convert_encoding($string, $to, $from) } else { function twig_convert_encoding($string, $to, $from) { - throw new Twig_Error_Runtime('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); + throw new \Twig\Error\RuntimeError('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); } } @@ -1246,7 +1246,7 @@ function _twig_escape_html_attr_callback($matches) * * @return int The length of the value */ - function twig_length_filter(Twig_Environment $env, $thing) + function twig_length_filter(\Twig\Environment $env, $thing) { if (null === $thing) { return 0; @@ -1282,7 +1282,7 @@ function twig_length_filter(Twig_Environment $env, $thing) * * @return string The uppercased string */ - function twig_upper_filter(Twig_Environment $env, $string) + function twig_upper_filter(\Twig\Environment $env, $string) { if (null !== $charset = $env->getCharset()) { return mb_strtoupper($string, $charset); @@ -1298,7 +1298,7 @@ function twig_upper_filter(Twig_Environment $env, $string) * * @return string The lowercased string */ - function twig_lower_filter(Twig_Environment $env, $string) + function twig_lower_filter(\Twig\Environment $env, $string) { if (null !== $charset = $env->getCharset()) { return mb_strtolower($string, $charset); @@ -1314,7 +1314,7 @@ function twig_lower_filter(Twig_Environment $env, $string) * * @return string The titlecased string */ - function twig_title_string_filter(Twig_Environment $env, $string) + function twig_title_string_filter(\Twig\Environment $env, $string) { if (null !== $charset = $env->getCharset()) { return mb_convert_case($string, MB_CASE_TITLE, $charset); @@ -1330,7 +1330,7 @@ function twig_title_string_filter(Twig_Environment $env, $string) * * @return string The capitalized string */ - function twig_capitalize_string_filter(Twig_Environment $env, $string) + function twig_capitalize_string_filter(\Twig\Environment $env, $string) { if (null !== $charset = $env->getCharset()) { return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, mb_strlen($string, $charset), $charset), $charset); @@ -1348,7 +1348,7 @@ function twig_capitalize_string_filter(Twig_Environment $env, $string) * * @return int The length of the value */ - function twig_length_filter(Twig_Environment $env, $thing) + function twig_length_filter(\Twig\Environment $env, $thing) { if (null === $thing) { return 0; @@ -1384,7 +1384,7 @@ function twig_length_filter(Twig_Environment $env, $thing) * * @return string The titlecased string */ - function twig_title_string_filter(Twig_Environment $env, $string) + function twig_title_string_filter(\Twig\Environment $env, $string) { return ucwords(strtolower($string)); } @@ -1396,7 +1396,7 @@ function twig_title_string_filter(Twig_Environment $env, $string) * * @return string The capitalized string */ - function twig_capitalize_string_filter(Twig_Environment $env, $string) + function twig_capitalize_string_filter(\Twig\Environment $env, $string) { return ucfirst(strtolower($string)); } @@ -1476,8 +1476,8 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = [ $variables = array_merge($context, $variables); } - if ($isSandboxed = $sandboxed && $env->hasExtension('Twig_Extension_Sandbox')) { - $sandbox = $env->getExtension('Twig_Extension_Sandbox'); + if ($isSandboxed = $sandboxed && $env->hasExtension('\Twig\Extension\SandboxExtension')) { + $sandbox = $env->getExtension('\Twig\Extension\SandboxExtension'); if (!$alreadySandboxed = $sandbox->isSandboxed()) { $sandbox->enableSandbox(); } @@ -1486,7 +1486,7 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = [ $result = ''; try { $result = $env->resolveTemplate($template)->render($variables); - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { if (!$ignoreMissing) { if ($isSandboxed && !$alreadySandboxed) { $sandbox->disableSandbox(); @@ -1527,12 +1527,12 @@ function twig_source(Twig_Environment $env, $name, $ignoreMissing = false) { $loader = $env->getLoader(); try { - if (!$loader instanceof Twig_SourceContextLoaderInterface) { + if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface) { return $loader->getSource($name); } else { return $loader->getSourceContext($name)->getCode(); } - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { if (!$ignoreMissing) { throw $e; } diff --git a/lib/Twig/Extension/Debug.php b/lib/Twig/Extension/Debug.php index c3c64a575a..16c4afdda2 100644 --- a/lib/Twig/Extension/Debug.php +++ b/lib/Twig/Extension/Debug.php @@ -12,7 +12,7 @@ /** * @final */ -class Twig_Extension_Debug extends Twig_Extension +class Twig_Extension_Debug extends \Twig\Extension\AbstractExtension { public function getFunctions() { @@ -27,7 +27,7 @@ public function getFunctions() ; return [ - new Twig_SimpleFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true]), + new \Twig\TwigFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true]), ]; } @@ -49,7 +49,7 @@ function twig_var_dump(Twig_Environment $env, $context) if (2 === $count) { $vars = []; foreach ($context as $key => $value) { - if (!$value instanceof Twig_Template) { + if (!$value instanceof \Twig\Template) { $vars[$key] = $value; } } diff --git a/lib/Twig/Extension/Escaper.php b/lib/Twig/Extension/Escaper.php index b77eaad129..a06075c0dc 100644 --- a/lib/Twig/Extension/Escaper.php +++ b/lib/Twig/Extension/Escaper.php @@ -12,7 +12,7 @@ /** * @final */ -class Twig_Extension_Escaper extends Twig_Extension +class Twig_Extension_Escaper extends \Twig\Extension\AbstractExtension { protected $defaultStrategy; @@ -28,18 +28,18 @@ public function __construct($defaultStrategy = 'html') public function getTokenParsers() { - return [new Twig_TokenParser_AutoEscape()]; + return [new \Twig\TokenParser\AutoEscapeTokenParser()]; } public function getNodeVisitors() { - return [new Twig_NodeVisitor_Escaper()]; + return [new \Twig\NodeVisitor\EscaperNodeVisitor()]; } public function getFilters() { return [ - new Twig_SimpleFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), + new \Twig\TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), ]; } diff --git a/lib/Twig/Extension/GlobalsInterface.php b/lib/Twig/Extension/GlobalsInterface.php index 922cd2c933..388216713d 100644 --- a/lib/Twig/Extension/GlobalsInterface.php +++ b/lib/Twig/Extension/GlobalsInterface.php @@ -10,7 +10,7 @@ */ /** - * Enables usage of the deprecated Twig_Extension::getGlobals() method. + * Enables usage of the deprecated \Twig\Extension\AbstractExtension::getGlobals() method. * * Explicitly implement this interface if you really need to implement the * deprecated getGlobals() method in your extensions. diff --git a/lib/Twig/Extension/InitRuntimeInterface.php b/lib/Twig/Extension/InitRuntimeInterface.php index 1549862f4d..e33f544edb 100644 --- a/lib/Twig/Extension/InitRuntimeInterface.php +++ b/lib/Twig/Extension/InitRuntimeInterface.php @@ -10,7 +10,7 @@ */ /** - * Enables usage of the deprecated Twig_Extension::initRuntime() method. + * Enables usage of the deprecated \Twig\Extension\AbstractExtension::initRuntime() method. * * Explicitly implement this interface if you really need to implement the * deprecated initRuntime() method in your extensions. diff --git a/lib/Twig/Extension/Optimizer.php b/lib/Twig/Extension/Optimizer.php index 70a64be3ec..48e53b3ade 100644 --- a/lib/Twig/Extension/Optimizer.php +++ b/lib/Twig/Extension/Optimizer.php @@ -12,7 +12,7 @@ /** * @final */ -class Twig_Extension_Optimizer extends Twig_Extension +class Twig_Extension_Optimizer extends \Twig\Extension\AbstractExtension { protected $optimizers; @@ -23,7 +23,7 @@ public function __construct($optimizers = -1) public function getNodeVisitors() { - return [new Twig_NodeVisitor_Optimizer($this->optimizers)]; + return [new \Twig\NodeVisitor\OptimizerNodeVisitor($this->optimizers)]; } public function getName() diff --git a/lib/Twig/Extension/Profiler.php b/lib/Twig/Extension/Profiler.php index 0f991dca33..1b7004cf4b 100644 --- a/lib/Twig/Extension/Profiler.php +++ b/lib/Twig/Extension/Profiler.php @@ -9,22 +9,22 @@ * file that was distributed with this source code. */ -class Twig_Extension_Profiler extends Twig_Extension +class Twig_Extension_Profiler extends \Twig\Extension\AbstractExtension { private $actives = []; - public function __construct(Twig_Profiler_Profile $profile) + public function __construct(\Twig\Profiler\Profile $profile) { $this->actives[] = $profile; } - public function enter(Twig_Profiler_Profile $profile) + public function enter(\Twig\Profiler\Profile $profile) { $this->actives[0]->addProfile($profile); array_unshift($this->actives, $profile); } - public function leave(Twig_Profiler_Profile $profile) + public function leave(\Twig\Profiler\Profile $profile) { $profile->leave(); array_shift($this->actives); @@ -36,7 +36,7 @@ public function leave(Twig_Profiler_Profile $profile) public function getNodeVisitors() { - return [new Twig_Profiler_NodeVisitor_Profiler(\get_class($this))]; + return [new \Twig\Profiler\NodeVisitor\ProfilerNodeVisitor(\get_class($this))]; } public function getName() diff --git a/lib/Twig/Extension/Sandbox.php b/lib/Twig/Extension/Sandbox.php index 915020257a..a12a563270 100644 --- a/lib/Twig/Extension/Sandbox.php +++ b/lib/Twig/Extension/Sandbox.php @@ -12,13 +12,13 @@ /** * @final */ -class Twig_Extension_Sandbox extends Twig_Extension +class Twig_Extension_Sandbox extends \Twig\Extension\AbstractExtension { protected $sandboxedGlobally; protected $sandboxed; protected $policy; - public function __construct(Twig_Sandbox_SecurityPolicyInterface $policy, $sandboxed = false) + public function __construct(\Twig\Sandbox\SecurityPolicyInterface $policy, $sandboxed = false) { $this->policy = $policy; $this->sandboxedGlobally = $sandboxed; @@ -26,12 +26,12 @@ public function __construct(Twig_Sandbox_SecurityPolicyInterface $policy, $sandb public function getTokenParsers() { - return [new Twig_TokenParser_Sandbox()]; + return [new \Twig\TokenParser\SandboxTokenParser()]; } public function getNodeVisitors() { - return [new Twig_NodeVisitor_Sandbox()]; + return [new \Twig\NodeVisitor\SandboxNodeVisitor()]; } public function enableSandbox() @@ -54,7 +54,7 @@ public function isSandboxedGlobally() return $this->sandboxedGlobally; } - public function setSecurityPolicy(Twig_Sandbox_SecurityPolicyInterface $policy) + public function setSecurityPolicy(\Twig\Sandbox\SecurityPolicyInterface $policy) { $this->policy = $policy; } diff --git a/lib/Twig/Extension/Staging.php b/lib/Twig/Extension/Staging.php index 897b3794ca..84ccf92b57 100644 --- a/lib/Twig/Extension/Staging.php +++ b/lib/Twig/Extension/Staging.php @@ -18,7 +18,7 @@ * * @internal */ -class Twig_Extension_Staging extends Twig_Extension +class Twig_Extension_Staging extends \Twig\Extension\AbstractExtension { protected $functions = []; protected $filters = []; @@ -55,7 +55,7 @@ public function getFilters() return $this->filters; } - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) + public function addNodeVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor) { $this->visitors[] = $visitor; } @@ -65,7 +65,7 @@ public function getNodeVisitors() return $this->visitors; } - public function addTokenParser(Twig_TokenParserInterface $parser) + public function addTokenParser(\Twig\TokenParser\TokenParserInterface $parser) { if (isset($this->tokenParsers[$parser->getTag()])) { @trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED); diff --git a/lib/Twig/Extension/StringLoader.php b/lib/Twig/Extension/StringLoader.php index 0423bcd0d1..0b22139105 100644 --- a/lib/Twig/Extension/StringLoader.php +++ b/lib/Twig/Extension/StringLoader.php @@ -12,12 +12,12 @@ /** * @final */ -class Twig_Extension_StringLoader extends Twig_Extension +class Twig_Extension_StringLoader extends \Twig\Extension\AbstractExtension { public function getFunctions() { return [ - new Twig_SimpleFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]), + new \Twig\TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]), ]; } @@ -34,7 +34,7 @@ public function getName() * * @param string $template A template as a string or object implementing __toString() * - * @return Twig_Template + * @return \Twig\Template */ function twig_template_from_string(Twig_Environment $env, $template) { diff --git a/lib/Twig/ExtensionInterface.php b/lib/Twig/ExtensionInterface.php index 946df500a8..6e8d1960ce 100644 --- a/lib/Twig/ExtensionInterface.php +++ b/lib/Twig/ExtensionInterface.php @@ -23,40 +23,40 @@ interface Twig_ExtensionInterface * * @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead */ - public function initRuntime(Twig_Environment $environment); + public function initRuntime(\Twig\Environment $environment); /** * Returns the token parser instances to add to the existing list. * - * @return Twig_TokenParserInterface[] + * @return \Twig\TokenParser\TokenParserInterface[] */ public function getTokenParsers(); /** * Returns the node visitor instances to add to the existing list. * - * @return Twig_NodeVisitorInterface[] + * @return \Twig\NodeVisitor\NodeVisitorInterface[] */ public function getNodeVisitors(); /** * Returns a list of filters to add to the existing list. * - * @return Twig_SimpleFilter[] + * @return \Twig\TwigFilter[] */ public function getFilters(); /** * Returns a list of tests to add to the existing list. * - * @return Twig_SimpleTest[] + * @return \Twig\TwigTest[] */ public function getTests(); /** * Returns a list of functions to add to the existing list. * - * @return Twig_SimpleFunction[] + * @return \Twig\TwigFunction[] */ public function getFunctions(); diff --git a/lib/Twig/FactoryRuntimeLoader.php b/lib/Twig/FactoryRuntimeLoader.php index 2a8671224e..afd373d55a 100644 --- a/lib/Twig/FactoryRuntimeLoader.php +++ b/lib/Twig/FactoryRuntimeLoader.php @@ -14,7 +14,7 @@ * * @author Robin Chalas */ -class Twig_FactoryRuntimeLoader implements Twig_RuntimeLoaderInterface +class Twig_FactoryRuntimeLoader implements \Twig\RuntimeLoader\RuntimeLoaderInterface { private $map; diff --git a/lib/Twig/Filter.php b/lib/Twig/Filter.php index d04322896f..6a1aa31118 100644 --- a/lib/Twig/Filter.php +++ b/lib/Twig/Filter.php @@ -56,7 +56,7 @@ public function needsContext() return $this->options['needs_context']; } - public function getSafe(Twig_Node $filterArgs) + public function getSafe(\Twig\Node\Node $filterArgs) { if (isset($this->options['is_safe'])) { return $this->options['is_safe']; diff --git a/lib/Twig/Filter/Method.php b/lib/Twig/Filter/Method.php index 088306cc8f..8121e129db 100644 --- a/lib/Twig/Filter/Method.php +++ b/lib/Twig/Filter/Method.php @@ -25,7 +25,7 @@ class Twig_Filter_Method extends Twig_Filter protected $extension; protected $method; - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = []) + public function __construct(\Twig\Extension\ExtensionInterface $extension, $method, array $options = []) { $options['callable'] = [$extension, $method]; diff --git a/lib/Twig/FilterInterface.php b/lib/Twig/FilterInterface.php index 9d7e9ab6ac..94db8dc646 100644 --- a/lib/Twig/FilterInterface.php +++ b/lib/Twig/FilterInterface.php @@ -31,7 +31,7 @@ public function needsEnvironment(); public function needsContext(); - public function getSafe(Twig_Node $filterArgs); + public function getSafe(\Twig\Node\Node $filterArgs); public function getPreservesSafety(); diff --git a/lib/Twig/Function.php b/lib/Twig/Function.php index 58da0433c6..245689ab9e 100644 --- a/lib/Twig/Function.php +++ b/lib/Twig/Function.php @@ -54,7 +54,7 @@ public function needsContext() return $this->options['needs_context']; } - public function getSafe(Twig_Node $functionArgs) + public function getSafe(\Twig\Node\Node $functionArgs) { if (isset($this->options['is_safe'])) { return $this->options['is_safe']; diff --git a/lib/Twig/Function/Method.php b/lib/Twig/Function/Method.php index c8d210fcb1..1c58a87ec8 100644 --- a/lib/Twig/Function/Method.php +++ b/lib/Twig/Function/Method.php @@ -26,7 +26,7 @@ class Twig_Function_Method extends Twig_Function protected $extension; protected $method; - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = []) + public function __construct(\Twig\Extension\ExtensionInterface $extension, $method, array $options = []) { $options['callable'] = [$extension, $method]; diff --git a/lib/Twig/FunctionInterface.php b/lib/Twig/FunctionInterface.php index 00d4f95c7c..9677ca8caa 100644 --- a/lib/Twig/FunctionInterface.php +++ b/lib/Twig/FunctionInterface.php @@ -32,7 +32,7 @@ public function needsEnvironment(); public function needsContext(); - public function getSafe(Twig_Node $filterArgs); + public function getSafe(\Twig\Node\Node $filterArgs); public function setArguments($arguments); diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index dac1c8bbed..363db6c8ca 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -49,7 +49,7 @@ class Twig_Lexer implements Twig_LexerInterface const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; const PUNCTUATION = '()[]{}?:.,|'; - public function __construct(Twig_Environment $env, array $options = []) + public function __construct(\Twig\Environment $env, array $options = []) { $this->env = $env; @@ -77,9 +77,9 @@ public function __construct(Twig_Environment $env, array $options = []) public function tokenize($code, $name = null) { - if (!$code instanceof Twig_Source) { + if (!$code instanceof \Twig\Source) { @trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $this->source = new Twig_Source($code, $name); + $this->source = new \Twig\Source($code, $name); } else { $this->source = $code; } @@ -136,25 +136,25 @@ public function tokenize($code, $name = null) } } - $this->pushToken(Twig_Token::EOF_TYPE); + $this->pushToken(\Twig\Token::EOF_TYPE); if (!empty($this->brackets)) { list($expect, $lineno) = array_pop($this->brackets); - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + throw new \Twig\Error\SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); } if ($mbEncoding) { mb_internal_encoding($mbEncoding); } - return new Twig_TokenStream($this->tokens, $this->source); + return new \Twig\TokenStream($this->tokens, $this->source); } protected function lexData() { // if no matches are left we return the rest of the template as simple text token if ($this->position == \count($this->positions[0]) - 1) { - $this->pushToken(Twig_Token::TEXT_TYPE, substr($this->code, $this->cursor)); + $this->pushToken(\Twig\Token::TEXT_TYPE, substr($this->code, $this->cursor)); $this->cursor = $this->end; return; @@ -174,7 +174,7 @@ protected function lexData() if (isset($this->positions[2][$this->position][0])) { $text = rtrim($text); } - $this->pushToken(Twig_Token::TEXT_TYPE, $text); + $this->pushToken(\Twig\Token::TEXT_TYPE, $text); $this->moveCursor($textContent.$position[0]); switch ($this->positions[1][$this->position][0]) { @@ -192,14 +192,14 @@ protected function lexData() $this->moveCursor($match[0]); $this->lineno = (int) $match[1]; } else { - $this->pushToken(Twig_Token::BLOCK_START_TYPE); + $this->pushToken(\Twig\Token::BLOCK_START_TYPE); $this->pushState(self::STATE_BLOCK); $this->currentVarBlockLine = $this->lineno; } break; case $this->options['tag_variable'][0]: - $this->pushToken(Twig_Token::VAR_START_TYPE); + $this->pushToken(\Twig\Token::VAR_START_TYPE); $this->pushState(self::STATE_VAR); $this->currentVarBlockLine = $this->lineno; break; @@ -209,7 +209,7 @@ protected function lexData() protected function lexBlock() { if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::BLOCK_END_TYPE); + $this->pushToken(\Twig\Token::BLOCK_END_TYPE); $this->moveCursor($match[0]); $this->popState(); } else { @@ -220,7 +220,7 @@ protected function lexBlock() protected function lexVar() { if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::VAR_END_TYPE); + $this->pushToken(\Twig\Token::VAR_END_TYPE); $this->moveCursor($match[0]); $this->popState(); } else { @@ -235,18 +235,18 @@ protected function lexExpression() $this->moveCursor($match[0]); if ($this->cursor >= $this->end) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); + throw new \Twig\Error\SyntaxError(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); } } // operators if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0])); + $this->pushToken(\Twig\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)) { - $this->pushToken(Twig_Token::NAME_TYPE, $match[0]); + $this->pushToken(\Twig\Token::NAME_TYPE, $match[0]); $this->moveCursor($match[0]); } // numbers @@ -255,7 +255,7 @@ protected function lexExpression() if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { $number = (int) $match[0]; // integers lower than the maximum } - $this->pushToken(Twig_Token::NUMBER_TYPE, $number); + $this->pushToken(\Twig\Token::NUMBER_TYPE, $number); $this->moveCursor($match[0]); } // punctuation @@ -267,21 +267,21 @@ protected function lexExpression() // closing bracket elseif (false !== strpos(')]}', $this->code[$this->cursor])) { if (empty($this->brackets)) { - throw new Twig_Error_Syntax(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + throw new \Twig\Error\SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); } list($expect, $lineno) = array_pop($this->brackets); if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + throw new \Twig\Error\SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); } } - $this->pushToken(Twig_Token::PUNCTUATION_TYPE, $this->code[$this->cursor]); + $this->pushToken(\Twig\Token::PUNCTUATION_TYPE, $this->code[$this->cursor]); ++$this->cursor; } // strings elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1))); + $this->pushToken(\Twig\Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1))); $this->moveCursor($match[0]); } // opening double quoted string @@ -292,7 +292,7 @@ protected function lexExpression() } // unlexable else { - throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + throw new \Twig\Error\SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); } } @@ -303,7 +303,7 @@ protected function lexRawData($tag) } if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new Twig_Error_Syntax(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source); + throw new \Twig\Error\SyntaxError(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source); } $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor); @@ -313,13 +313,13 @@ protected function lexRawData($tag) $text = rtrim($text); } - $this->pushToken(Twig_Token::TEXT_TYPE, $text); + $this->pushToken(\Twig\Token::TEXT_TYPE, $text); } protected function lexComment() { if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new Twig_Error_Syntax('Unclosed comment.', $this->lineno, $this->source); + throw new \Twig\Error\SyntaxError('Unclosed comment.', $this->lineno, $this->source); } $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); @@ -329,23 +329,23 @@ protected function lexString() { if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) { $this->brackets[] = [$this->options['interpolation'][0], $this->lineno]; - $this->pushToken(Twig_Token::INTERPOLATION_START_TYPE); + $this->pushToken(\Twig\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) { - $this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[0])); + $this->pushToken(\Twig\Token::STRING_TYPE, stripcslashes($match[0])); $this->moveCursor($match[0]); } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { list($expect, $lineno) = array_pop($this->brackets); if ('"' != $this->code[$this->cursor]) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + throw new \Twig\Error\SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); } $this->popState(); ++$this->cursor; } else { // unlexable - throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + throw new \Twig\Error\SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); } } @@ -354,7 +354,7 @@ 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)) { array_pop($this->brackets); - $this->pushToken(Twig_Token::INTERPOLATION_END_TYPE); + $this->pushToken(\Twig\Token::INTERPOLATION_END_TYPE); $this->moveCursor($match[0]); $this->popState(); } else { @@ -365,11 +365,11 @@ protected function lexInterpolation() protected function pushToken($type, $value = '') { // do not push empty text tokens - if (Twig_Token::TEXT_TYPE === $type && '' === $value) { + if (\Twig\Token::TEXT_TYPE === $type && '' === $value) { return; } - $this->tokens[] = new Twig_Token($type, $value, $this->lineno); + $this->tokens[] = new \Twig\Token($type, $value, $this->lineno); } protected function moveCursor($text) diff --git a/lib/Twig/LexerInterface.php b/lib/Twig/LexerInterface.php index c10bbfec4a..2dbcebc280 100644 --- a/lib/Twig/LexerInterface.php +++ b/lib/Twig/LexerInterface.php @@ -21,12 +21,12 @@ interface Twig_LexerInterface /** * Tokenizes a source code. * - * @param string|Twig_Source $code The source code - * @param string $name A unique identifier for the source code + * @param string|\Twig\Source $code The source code + * @param string $name A unique identifier for the source code * - * @return Twig_TokenStream + * @return \Twig\TokenStream * - * @throws Twig_Error_Syntax When the code is syntactically wrong + * @throws \Twig\Error\SyntaxError When the code is syntactically wrong */ public function tokenize($code, $name = null); } diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index ca2efa833b..1791e18256 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -23,7 +23,7 @@ * * @author Fabien Potencier */ -class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +class Twig_Loader_Array implements \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { protected $templates = []; @@ -52,7 +52,7 @@ public function getSource($name) $name = (string) $name; if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined.', $name)); } return $this->templates[$name]; @@ -62,10 +62,10 @@ public function getSourceContext($name) { $name = (string) $name; if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined.', $name)); } - return new Twig_Source($this->templates[$name], $name); + return new \Twig\Source($this->templates[$name], $name); } public function exists($name) @@ -77,7 +77,7 @@ public function getCacheKey($name) { $name = (string) $name; if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined.', $name)); } return $name.':'.$this->templates[$name]; @@ -87,7 +87,7 @@ public function isFresh($name, $time) { $name = (string) $name; if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined.', $name)); } return true; diff --git a/lib/Twig/Loader/Chain.php b/lib/Twig/Loader/Chain.php index ae6c0333e3..9cc327ff51 100644 --- a/lib/Twig/Loader/Chain.php +++ b/lib/Twig/Loader/Chain.php @@ -16,13 +16,13 @@ * * @author Fabien Potencier */ -class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +class Twig_Loader_Chain implements \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { private $hasSourceCache = []; protected $loaders = []; /** - * @param Twig_LoaderInterface[] $loaders + * @param \Twig\Loader\LoaderInterface[] $loaders */ public function __construct(array $loaders = []) { @@ -31,7 +31,7 @@ public function __construct(array $loaders = []) } } - public function addLoader(Twig_LoaderInterface $loader) + public function addLoader(\Twig\Loader\LoaderInterface $loader) { $this->loaders[] = $loader; $this->hasSourceCache = []; @@ -43,40 +43,40 @@ public function getSource($name) $exceptions = []; foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof \Twig\Loader\ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { return $loader->getSource($name); - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { $exceptions[] = $e->getMessage(); } } - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } public function getSourceContext($name) { $exceptions = []; foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof \Twig\Loader\ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { - if ($loader instanceof Twig_SourceContextLoaderInterface) { + if ($loader instanceof \Twig\Loader\SourceContextLoaderInterface) { return $loader->getSourceContext($name); } - return new Twig_Source($loader->getSource($name), $name); - } catch (Twig_Error_Loader $e) { + return new \Twig\Source($loader->getSource($name), $name); + } catch (\Twig\Error\LoaderError $e) { $exceptions[] = $e->getMessage(); } } - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } public function exists($name) @@ -88,7 +88,7 @@ public function exists($name) } foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface) { + if ($loader instanceof \Twig\Loader\ExistsLoaderInterface) { if ($loader->exists($name)) { return $this->hasSourceCache[$name] = true; } @@ -97,14 +97,14 @@ public function exists($name) } try { - if ($loader instanceof Twig_SourceContextLoaderInterface) { + if ($loader instanceof \Twig\Loader\SourceContextLoaderInterface) { $loader->getSourceContext($name); } else { $loader->getSource($name); } return $this->hasSourceCache[$name] = true; - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { } } @@ -115,36 +115,36 @@ public function getCacheKey($name) { $exceptions = []; foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof \Twig\Loader\ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { return $loader->getCacheKey($name); - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { $exceptions[] = \get_class($loader).': '.$e->getMessage(); } } - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } public function isFresh($name, $time) { $exceptions = []; foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof \Twig\Loader\ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { return $loader->isFresh($name, $time); - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { $exceptions[] = \get_class($loader).': '.$e->getMessage(); } } - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } } diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index 475b9070d4..e4ffd14403 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -14,7 +14,7 @@ * * @author Fabien Potencier */ -class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { /** Identifier of the main namespace. */ const MAIN_NAMESPACE = '__main__'; @@ -89,7 +89,7 @@ public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) * @param string $path A path where to look for templates * @param string $namespace A path namespace * - * @throws Twig_Error_Loader + * @throws \Twig\Error\LoaderError */ public function addPath($path, $namespace = self::MAIN_NAMESPACE) { @@ -98,7 +98,7 @@ public function addPath($path, $namespace = self::MAIN_NAMESPACE) $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; if (!is_dir($checkPath)) { - throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + throw new \Twig\Error\LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); } $this->paths[$namespace][] = rtrim($path, '/\\'); @@ -110,7 +110,7 @@ public function addPath($path, $namespace = self::MAIN_NAMESPACE) * @param string $path A path where to look for templates * @param string $namespace A path namespace * - * @throws Twig_Error_Loader + * @throws \Twig\Error\LoaderError */ public function prependPath($path, $namespace = self::MAIN_NAMESPACE) { @@ -119,7 +119,7 @@ public function prependPath($path, $namespace = self::MAIN_NAMESPACE) $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; if (!is_dir($checkPath)) { - throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + throw new \Twig\Error\LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); } $path = rtrim($path, '/\\'); @@ -142,7 +142,7 @@ public function getSourceContext($name) { $path = $this->findTemplate($name); - return new Twig_Source(file_get_contents($path), $name, $path); + return new \Twig\Source(file_get_contents($path), $name, $path); } public function getCacheKey($name) @@ -166,7 +166,7 @@ public function exists($name) try { return false !== $this->findTemplate($name, false); - } catch (Twig_Error_Loader $exception) { + } catch (\Twig\Error\LoaderError $exception) { @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', \get_class($this)), E_USER_DEPRECATED); return false; @@ -192,14 +192,14 @@ protected function findTemplate($name) return false; } - throw new Twig_Error_Loader($this->errorCache[$name]); + throw new \Twig\Error\LoaderError($this->errorCache[$name]); } try { $this->validateName($name); list($namespace, $shortname) = $this->parseName($name); - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { if (!$throw) { return false; } @@ -214,7 +214,7 @@ protected function findTemplate($name) return false; } - throw new Twig_Error_Loader($this->errorCache[$name]); + throw new \Twig\Error\LoaderError($this->errorCache[$name]); } foreach ($this->paths[$namespace] as $path) { @@ -237,14 +237,14 @@ protected function findTemplate($name) return false; } - throw new Twig_Error_Loader($this->errorCache[$name]); + throw new \Twig\Error\LoaderError($this->errorCache[$name]); } protected function parseName($name, $default = self::MAIN_NAMESPACE) { if (isset($name[0]) && '@' == $name[0]) { if (false === $pos = strpos($name, '/')) { - throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); + throw new \Twig\Error\LoaderError(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); } $namespace = substr($name, 1, $pos - 1); @@ -264,7 +264,7 @@ protected function normalizeName($name) protected function validateName($name) { if (false !== strpos($name, "\0")) { - throw new Twig_Error_Loader('A template name cannot contain NUL bytes.'); + throw new \Twig\Error\LoaderError('A template name cannot contain NUL bytes.'); } $name = ltrim($name, '/'); @@ -278,7 +278,7 @@ protected function validateName($name) } if ($level < 0) { - throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); + throw new \Twig\Error\LoaderError(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); } } } diff --git a/lib/Twig/Loader/String.php b/lib/Twig/Loader/String.php index 1d7544cd1e..571f4b7c47 100644 --- a/lib/Twig/Loader/String.php +++ b/lib/Twig/Loader/String.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use Twig_Loader_Array instead or Twig_Environment::createTemplate().', E_USER_DEPRECATED); +@trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use Twig_Loader_Array instead or \Twig\Environment::createTemplate().', E_USER_DEPRECATED); /** * Loads a template from a string. @@ -27,7 +27,7 @@ * * @author Fabien Potencier */ -class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +class Twig_Loader_String implements \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { public function getSource($name) { @@ -38,7 +38,7 @@ public function getSource($name) public function getSourceContext($name) { - return new Twig_Source($name, $name); + return new \Twig\Source($name, $name); } public function exists($name) diff --git a/lib/Twig/LoaderInterface.php b/lib/Twig/LoaderInterface.php index 459a70abbf..66817f2949 100644 --- a/lib/Twig/LoaderInterface.php +++ b/lib/Twig/LoaderInterface.php @@ -23,7 +23,7 @@ interface Twig_LoaderInterface * * @return string The template source code * - * @throws Twig_Error_Loader When $name is not found + * @throws \Twig\Error\LoaderError When $name is not found * * @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface */ @@ -36,7 +36,7 @@ public function getSource($name); * * @return string The cache key * - * @throws Twig_Error_Loader When $name is not found + * @throws \Twig\Error\LoaderError When $name is not found */ public function getCacheKey($name); @@ -49,7 +49,7 @@ public function getCacheKey($name); * * @return bool true if the template is fresh, false otherwise * - * @throws Twig_Error_Loader When $name is not found + * @throws \Twig\Error\LoaderError When $name is not found */ public function isFresh($name, $time); } diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index 67bdaee7c5..b4853522be 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -111,7 +111,7 @@ public function toXml($asDom = false) return $asDom ? $dom : $dom->saveXML(); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { foreach ($this->nodes as $node) { $node->compile($compiler); @@ -181,7 +181,7 @@ public function hasNode($name) } /** - * @return Twig_Node + * @return \Twig\Node\Node */ public function getNode($name) { diff --git a/lib/Twig/Node/AutoEscape.php b/lib/Twig/Node/AutoEscape.php index 62e0961be1..beb0486c25 100644 --- a/lib/Twig/Node/AutoEscape.php +++ b/lib/Twig/Node/AutoEscape.php @@ -20,14 +20,14 @@ * * @author Fabien Potencier */ -class Twig_Node_AutoEscape extends Twig_Node +class Twig_Node_AutoEscape extends \Twig\Node\Node { public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape') { parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->subcompile($this->getNode('body')); } diff --git a/lib/Twig/Node/Block.php b/lib/Twig/Node/Block.php index 2d0300ba1b..68f8f3121c 100644 --- a/lib/Twig/Node/Block.php +++ b/lib/Twig/Node/Block.php @@ -15,14 +15,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Block extends Twig_Node +class Twig_Node_Block extends \Twig\Node\Node { public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null) { parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/BlockReference.php b/lib/Twig/Node/BlockReference.php index 0b0f7b363e..c56f37ee61 100644 --- a/lib/Twig/Node/BlockReference.php +++ b/lib/Twig/Node/BlockReference.php @@ -15,14 +15,14 @@ * * @author Fabien Potencier */ -class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface +class Twig_Node_BlockReference extends \Twig\Node\Node implements \Twig\Node\NodeOutputInterface { public function __construct($name, $lineno, $tag = null) { parent::__construct([], ['name' => $name], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/Body.php b/lib/Twig/Node/Body.php index 07dfef8b5e..5314fa1c95 100644 --- a/lib/Twig/Node/Body.php +++ b/lib/Twig/Node/Body.php @@ -14,7 +14,7 @@ * * @author Fabien Potencier */ -class Twig_Node_Body extends Twig_Node +class Twig_Node_Body extends \Twig\Node\Node { } diff --git a/lib/Twig/Node/CheckSecurity.php b/lib/Twig/Node/CheckSecurity.php index aecdb8322d..5707359293 100644 --- a/lib/Twig/Node/CheckSecurity.php +++ b/lib/Twig/Node/CheckSecurity.php @@ -12,7 +12,7 @@ /** * @author Fabien Potencier */ -class Twig_Node_CheckSecurity extends Twig_Node +class Twig_Node_CheckSecurity extends \Twig\Node\Node { protected $usedFilters; protected $usedTags; @@ -27,12 +27,12 @@ public function __construct(array $usedFilters, array $usedTags, array $usedFunc parent::__construct(); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $tags = $filters = $functions = []; foreach (['tags', 'filters', 'functions'] as $type) { foreach ($this->{'used'.ucfirst($type)} as $name => $node) { - if ($node instanceof Twig_Node) { + if ($node instanceof \Twig\Node\Node) { ${$type}[$name] = $node->getTemplateLine(); } else { ${$type}[$node] = null; @@ -46,7 +46,7 @@ public function compile(Twig_Compiler $compiler) ->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n") ->write("try {\n") ->indent() - ->write("\$this->env->getExtension('Twig_Extension_Sandbox')->checkSecurity(\n") + ->write("\$this->env->getExtension('\Twig\Extension\SandboxExtension')->checkSecurity(\n") ->indent() ->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n") ->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n") @@ -54,18 +54,18 @@ public function compile(Twig_Compiler $compiler) ->outdent() ->write(");\n") ->outdent() - ->write("} catch (Twig_Sandbox_SecurityError \$e) {\n") + ->write("} catch (\Twig\Sandbox\SecurityError \$e) {\n") ->indent() ->write("\$e->setSourceContext(\$this->getSourceContext());\n\n") - ->write("if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") + ->write("if (\$e instanceof \Twig\Sandbox\SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") ->indent() ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n") ->outdent() - ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") + ->write("} elseif (\$e instanceof \Twig\Sandbox\SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") ->indent() ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n") ->outdent() - ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") + ->write("} elseif (\$e instanceof \Twig\Sandbox\SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") ->indent() ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n") ->outdent() diff --git a/lib/Twig/Node/Deprecated.php b/lib/Twig/Node/Deprecated.php index fc4c392383..f793e74b58 100644 --- a/lib/Twig/Node/Deprecated.php +++ b/lib/Twig/Node/Deprecated.php @@ -14,20 +14,20 @@ * * @author Yonel Ceruto */ -class Twig_Node_Deprecated extends Twig_Node +class Twig_Node_Deprecated extends \Twig\Node\Node { - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) + public function __construct(\Twig\Node\Expression\AbstractExpression $expr, $lineno, $tag = null) { parent::__construct(['expr' => $expr], [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->addDebugInfo($this); $expr = $this->getNode('expr'); - if ($expr instanceof Twig_Node_Expression_Constant) { + if ($expr instanceof \Twig\Node\Expression\ConstantExpression) { $compiler->write('@trigger_error(') ->subcompile($expr); } else { diff --git a/lib/Twig/Node/Do.php b/lib/Twig/Node/Do.php index 13350454fa..28e7ab0eef 100644 --- a/lib/Twig/Node/Do.php +++ b/lib/Twig/Node/Do.php @@ -14,14 +14,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Do extends Twig_Node +class Twig_Node_Do extends \Twig\Node\Node { - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) + public function __construct(\Twig\Node\Expression\AbstractExpression $expr, $lineno, $tag = null) { parent::__construct(['expr' => $expr], [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/Embed.php b/lib/Twig/Node/Embed.php index 3785d3a9fe..f32c3bc25b 100644 --- a/lib/Twig/Node/Embed.php +++ b/lib/Twig/Node/Embed.php @@ -14,12 +14,12 @@ * * @author Fabien Potencier */ -class Twig_Node_Embed extends Twig_Node_Include +class Twig_Node_Embed extends \Twig\Node\IncludeNode { // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module) - public function __construct($name, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) + public function __construct($name, $index, \Twig\Node\Expression\AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) { - parent::__construct(new Twig_Node_Expression_Constant('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); + parent::__construct(new \Twig\Node\Expression\ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); $this->setAttribute('name', $name); // to be removed in 2.0, used name instead @@ -27,7 +27,7 @@ public function __construct($name, $index, Twig_Node_Expression $variables = nul $this->setAttribute('index', $index); } - protected function addGetTemplate(Twig_Compiler $compiler) + protected function addGetTemplate(\Twig\Compiler $compiler) { $compiler ->write('$this->loadTemplate(') diff --git a/lib/Twig/Node/Expression.php b/lib/Twig/Node/Expression.php index a99c4e63ad..4fd85c570b 100644 --- a/lib/Twig/Node/Expression.php +++ b/lib/Twig/Node/Expression.php @@ -15,7 +15,7 @@ * * @author Fabien Potencier */ -abstract class Twig_Node_Expression extends Twig_Node +abstract class Twig_Node_Expression extends \Twig\Node\Node { } diff --git a/lib/Twig/Node/Expression/Array.php b/lib/Twig/Node/Expression/Array.php index 61e0d96191..0ff671c9e4 100644 --- a/lib/Twig/Node/Expression/Array.php +++ b/lib/Twig/Node/Expression/Array.php @@ -8,7 +8,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Array extends Twig_Node_Expression +class Twig_Node_Expression_Array extends \Twig\Node\Expression\AbstractExpression { protected $index; @@ -18,7 +18,7 @@ public function __construct(array $elements, $lineno) $this->index = -1; foreach ($this->getKeyValuePairs() as $pair) { - if ($pair['key'] instanceof Twig_Node_Expression_Constant && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { + if ($pair['key'] instanceof \Twig\Node\Expression\ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { $this->index = $pair['key']->getAttribute('value'); } } @@ -38,7 +38,7 @@ public function getKeyValuePairs() return $pairs; } - public function hasElement(Twig_Node_Expression $key) + public function hasElement(\Twig\Node\Expression\AbstractExpression $key) { foreach ($this->getKeyValuePairs() as $pair) { // we compare the string representation of the keys @@ -51,16 +51,16 @@ public function hasElement(Twig_Node_Expression $key) return false; } - public function addElement(Twig_Node_Expression $value, Twig_Node_Expression $key = null) + public function addElement(\Twig\Node\Expression\AbstractExpression $value, \Twig\Node\Expression\AbstractExpression $key = null) { if (null === $key) { - $key = new Twig_Node_Expression_Constant(++$this->index, $value->getTemplateLine()); + $key = new \Twig\Node\Expression\ConstantExpression(++$this->index, $value->getTemplateLine()); } array_push($this->nodes, $key, $value); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->raw('['); $first = true; diff --git a/lib/Twig/Node/Expression/AssignName.php b/lib/Twig/Node/Expression/AssignName.php index 2e6b4c7ca3..e67b91ebfe 100644 --- a/lib/Twig/Node/Expression/AssignName.php +++ b/lib/Twig/Node/Expression/AssignName.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ -class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name +class Twig_Node_Expression_AssignName extends \Twig\Node\Expression\NameExpression { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('$context[') diff --git a/lib/Twig/Node/Expression/Binary.php b/lib/Twig/Node/Expression/Binary.php index e9155dd505..2b1fcfe76d 100644 --- a/lib/Twig/Node/Expression/Binary.php +++ b/lib/Twig/Node/Expression/Binary.php @@ -9,14 +9,14 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression +abstract class Twig_Node_Expression_Binary extends \Twig\Node\Expression\AbstractExpression { public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno) { parent::__construct(['left' => $left, 'right' => $right], [], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('(') @@ -31,7 +31,7 @@ public function compile(Twig_Compiler $compiler) ; } - abstract public function operator(Twig_Compiler $compiler); + abstract public function operator(\Twig\Compiler $compiler); } class_alias('Twig_Node_Expression_Binary', 'Twig\Node\Expression\Binary\AbstractBinary', false); diff --git a/lib/Twig/Node/Expression/Binary/Add.php b/lib/Twig/Node/Expression/Binary/Add.php index 5a09d8367f..6444f5d445 100644 --- a/lib/Twig/Node/Expression/Binary/Add.php +++ b/lib/Twig/Node/Expression/Binary/Add.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Add extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Add extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('+'); } diff --git a/lib/Twig/Node/Expression/Binary/And.php b/lib/Twig/Node/Expression/Binary/And.php index 9ffddce6b1..9dc35f6384 100644 --- a/lib/Twig/Node/Expression/Binary/And.php +++ b/lib/Twig/Node/Expression/Binary/And.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_And extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_And extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('&&'); } diff --git a/lib/Twig/Node/Expression/Binary/BitwiseAnd.php b/lib/Twig/Node/Expression/Binary/BitwiseAnd.php index e46e9ebfa4..a766102bb7 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseAnd.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseAnd.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_BitwiseAnd extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_BitwiseAnd extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('&'); } diff --git a/lib/Twig/Node/Expression/Binary/BitwiseOr.php b/lib/Twig/Node/Expression/Binary/BitwiseOr.php index 5d7f1b7c04..cf30c8e027 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseOr.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseOr.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_BitwiseOr extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_BitwiseOr extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('|'); } diff --git a/lib/Twig/Node/Expression/Binary/BitwiseXor.php b/lib/Twig/Node/Expression/Binary/BitwiseXor.php index 82edf516ce..6cd953dac0 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseXor.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseXor.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_BitwiseXor extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_BitwiseXor extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('^'); } diff --git a/lib/Twig/Node/Expression/Binary/Concat.php b/lib/Twig/Node/Expression/Binary/Concat.php index 91abca6023..071cb3fb18 100644 --- a/lib/Twig/Node/Expression/Binary/Concat.php +++ b/lib/Twig/Node/Expression/Binary/Concat.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Concat extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Concat extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('.'); } diff --git a/lib/Twig/Node/Expression/Binary/Div.php b/lib/Twig/Node/Expression/Binary/Div.php index 38ffa30c32..5304a6042e 100644 --- a/lib/Twig/Node/Expression/Binary/Div.php +++ b/lib/Twig/Node/Expression/Binary/Div.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Div extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Div extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('/'); } diff --git a/lib/Twig/Node/Expression/Binary/EndsWith.php b/lib/Twig/Node/Expression/Binary/EndsWith.php index 85c5293766..85cacfe010 100644 --- a/lib/Twig/Node/Expression/Binary/EndsWith.php +++ b/lib/Twig/Node/Expression/Binary/EndsWith.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_EndsWith extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_EndsWith extends \Twig\Node\Expression\Binary\AbstractBinary { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $left = $compiler->getVarName(); $right = $compiler->getVarName(); @@ -23,7 +23,7 @@ public function compile(Twig_Compiler $compiler) ; } - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw(''); } diff --git a/lib/Twig/Node/Expression/Binary/Equal.php b/lib/Twig/Node/Expression/Binary/Equal.php index a6a6946b6d..96ef717981 100644 --- a/lib/Twig/Node/Expression/Binary/Equal.php +++ b/lib/Twig/Node/Expression/Binary/Equal.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Equal extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Equal extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('=='); } diff --git a/lib/Twig/Node/Expression/Binary/FloorDiv.php b/lib/Twig/Node/Expression/Binary/FloorDiv.php index 7393bcb897..46eeb4cc1e 100644 --- a/lib/Twig/Node/Expression/Binary/FloorDiv.php +++ b/lib/Twig/Node/Expression/Binary/FloorDiv.php @@ -8,16 +8,16 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_FloorDiv extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_FloorDiv extends \Twig\Node\Expression\Binary\AbstractBinary { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->raw('(int) floor('); parent::compile($compiler); $compiler->raw(')'); } - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('/'); } diff --git a/lib/Twig/Node/Expression/Binary/Greater.php b/lib/Twig/Node/Expression/Binary/Greater.php index 832f97977c..7c2272c75c 100644 --- a/lib/Twig/Node/Expression/Binary/Greater.php +++ b/lib/Twig/Node/Expression/Binary/Greater.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Greater extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Greater extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('>'); } diff --git a/lib/Twig/Node/Expression/Binary/GreaterEqual.php b/lib/Twig/Node/Expression/Binary/GreaterEqual.php index c5f7624572..be48bec7ae 100644 --- a/lib/Twig/Node/Expression/Binary/GreaterEqual.php +++ b/lib/Twig/Node/Expression/Binary/GreaterEqual.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_GreaterEqual extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_GreaterEqual extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('>='); } diff --git a/lib/Twig/Node/Expression/Binary/In.php b/lib/Twig/Node/Expression/Binary/In.php index af112448f4..ebb986c199 100644 --- a/lib/Twig/Node/Expression/Binary/In.php +++ b/lib/Twig/Node/Expression/Binary/In.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_In extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_In extends \Twig\Node\Expression\Binary\AbstractBinary { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('twig_in_filter(') @@ -21,7 +21,7 @@ public function compile(Twig_Compiler $compiler) ; } - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('in'); } diff --git a/lib/Twig/Node/Expression/Binary/Less.php b/lib/Twig/Node/Expression/Binary/Less.php index ab8fc1f9a8..79de38cbda 100644 --- a/lib/Twig/Node/Expression/Binary/Less.php +++ b/lib/Twig/Node/Expression/Binary/Less.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Less extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Less extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('<'); } diff --git a/lib/Twig/Node/Expression/Binary/LessEqual.php b/lib/Twig/Node/Expression/Binary/LessEqual.php index 71a279e9ce..77d1b2cbfc 100644 --- a/lib/Twig/Node/Expression/Binary/LessEqual.php +++ b/lib/Twig/Node/Expression/Binary/LessEqual.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_LessEqual extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_LessEqual extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('<='); } diff --git a/lib/Twig/Node/Expression/Binary/Matches.php b/lib/Twig/Node/Expression/Binary/Matches.php index 5cb8558428..0e5cde297a 100644 --- a/lib/Twig/Node/Expression/Binary/Matches.php +++ b/lib/Twig/Node/Expression/Binary/Matches.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Matches extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Matches extends \Twig\Node\Expression\Binary\AbstractBinary { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('preg_match(') @@ -21,7 +21,7 @@ public function compile(Twig_Compiler $compiler) ; } - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw(''); } diff --git a/lib/Twig/Node/Expression/Binary/Mod.php b/lib/Twig/Node/Expression/Binary/Mod.php index 28109633da..e577277f76 100644 --- a/lib/Twig/Node/Expression/Binary/Mod.php +++ b/lib/Twig/Node/Expression/Binary/Mod.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Mod extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Mod extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('%'); } diff --git a/lib/Twig/Node/Expression/Binary/Mul.php b/lib/Twig/Node/Expression/Binary/Mul.php index 790c6a22d8..8d39682f26 100644 --- a/lib/Twig/Node/Expression/Binary/Mul.php +++ b/lib/Twig/Node/Expression/Binary/Mul.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Mul extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Mul extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('*'); } diff --git a/lib/Twig/Node/Expression/Binary/NotEqual.php b/lib/Twig/Node/Expression/Binary/NotEqual.php index bb45c9ed55..d79d60f261 100644 --- a/lib/Twig/Node/Expression/Binary/NotEqual.php +++ b/lib/Twig/Node/Expression/Binary/NotEqual.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_NotEqual extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_NotEqual extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('!='); } diff --git a/lib/Twig/Node/Expression/Binary/NotIn.php b/lib/Twig/Node/Expression/Binary/NotIn.php index 9dedf92f92..5139d9c68d 100644 --- a/lib/Twig/Node/Expression/Binary/NotIn.php +++ b/lib/Twig/Node/Expression/Binary/NotIn.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_NotIn extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_NotIn extends \Twig\Node\Expression\Binary\AbstractBinary { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('!twig_in_filter(') @@ -21,7 +21,7 @@ public function compile(Twig_Compiler $compiler) ; } - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('not in'); } diff --git a/lib/Twig/Node/Expression/Binary/Or.php b/lib/Twig/Node/Expression/Binary/Or.php index dc9eece14c..f02517f157 100644 --- a/lib/Twig/Node/Expression/Binary/Or.php +++ b/lib/Twig/Node/Expression/Binary/Or.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Or extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Or extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('||'); } diff --git a/lib/Twig/Node/Expression/Binary/Power.php b/lib/Twig/Node/Expression/Binary/Power.php index d24777bd55..67c45bddb4 100644 --- a/lib/Twig/Node/Expression/Binary/Power.php +++ b/lib/Twig/Node/Expression/Binary/Power.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Power extends \Twig\Node\Expression\Binary\AbstractBinary { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { if (PHP_VERSION_ID >= 50600) { return parent::compile($compiler); @@ -25,7 +25,7 @@ public function compile(Twig_Compiler $compiler) ; } - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('**'); } diff --git a/lib/Twig/Node/Expression/Binary/Range.php b/lib/Twig/Node/Expression/Binary/Range.php index 187f67653b..9ef312e060 100644 --- a/lib/Twig/Node/Expression/Binary/Range.php +++ b/lib/Twig/Node/Expression/Binary/Range.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Range extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Range extends \Twig\Node\Expression\Binary\AbstractBinary { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('range(') @@ -21,7 +21,7 @@ public function compile(Twig_Compiler $compiler) ; } - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('..'); } diff --git a/lib/Twig/Node/Expression/Binary/StartsWith.php b/lib/Twig/Node/Expression/Binary/StartsWith.php index 7e43b8de09..140cd772b9 100644 --- a/lib/Twig/Node/Expression/Binary/StartsWith.php +++ b/lib/Twig/Node/Expression/Binary/StartsWith.php @@ -8,9 +8,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_StartsWith extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_StartsWith extends \Twig\Node\Expression\Binary\AbstractBinary { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $left = $compiler->getVarName(); $right = $compiler->getVarName(); @@ -23,7 +23,7 @@ public function compile(Twig_Compiler $compiler) ; } - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw(''); } diff --git a/lib/Twig/Node/Expression/Binary/Sub.php b/lib/Twig/Node/Expression/Binary/Sub.php index cff8ed075b..098b6a0ae6 100644 --- a/lib/Twig/Node/Expression/Binary/Sub.php +++ b/lib/Twig/Node/Expression/Binary/Sub.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Sub extends Twig_Node_Expression_Binary +class Twig_Node_Expression_Binary_Sub extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { return $compiler->raw('-'); } diff --git a/lib/Twig/Node/Expression/BlockReference.php b/lib/Twig/Node/Expression/BlockReference.php index 1fcea68fa5..b753104f97 100644 --- a/lib/Twig/Node/Expression/BlockReference.php +++ b/lib/Twig/Node/Expression/BlockReference.php @@ -15,10 +15,10 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_BlockReference extends Twig_Node_Expression +class Twig_Node_Expression_BlockReference extends \Twig\Node\Expression\AbstractExpression { /** - * @param Twig_Node|null $template + * @param \Twig\Node\Node|null $template */ public function __construct(Twig_NodeInterface $name, $template = null, $lineno, $tag = null) { @@ -36,7 +36,7 @@ public function __construct(Twig_NodeInterface $name, $template = null, $lineno, parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { if ($this->getAttribute('is_defined_test')) { $this->compileTemplateCall($compiler, 'hasBlock'); @@ -53,7 +53,7 @@ public function compile(Twig_Compiler $compiler) } } - private function compileTemplateCall(Twig_Compiler $compiler, $method) + private function compileTemplateCall(\Twig\Compiler $compiler, $method) { if (!$this->hasNode('template')) { $compiler->write('$this'); @@ -75,7 +75,7 @@ private function compileTemplateCall(Twig_Compiler $compiler, $method) return $compiler; } - private function compileBlockArguments(Twig_Compiler $compiler) + private function compileBlockArguments(\Twig\Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index a5a9b5f23a..2626a28d87 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -8,11 +8,11 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -abstract class Twig_Node_Expression_Call extends Twig_Node_Expression +abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractExpression { private $reflector; - protected function compileCallable(Twig_Compiler $compiler) + protected function compileCallable(\Twig\Compiler $compiler) { $closingParenthesis = false; $isArray = false; @@ -27,7 +27,7 @@ protected function compileCallable(Twig_Compiler $compiler) } else { $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); } - } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof Twig_ExtensionInterface) { + } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof \Twig\Extension\ExtensionInterface) { $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($callable[0]), $callable[1])); } else { $type = ucfirst($this->getAttribute('type')); @@ -47,7 +47,7 @@ protected function compileCallable(Twig_Compiler $compiler) } } - protected function compileArguments(Twig_Compiler $compiler, $isArray = false) + protected function compileArguments(\Twig\Compiler $compiler, $isArray = false) { $compiler->raw($isArray ? '[' : '('); @@ -113,7 +113,7 @@ protected function getArguments($callable, $arguments) $named = true; $name = $this->normalizeName($name); } elseif ($named) { - throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine()); + throw new \Twig\Error\SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine()); } $parameters[$name] = $node; @@ -145,11 +145,11 @@ protected function getArguments($callable, $arguments) if (\array_key_exists($name, $parameters)) { if (\array_key_exists($pos, $parameters)) { - throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); + throw new \Twig\Error\SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); } if (\count($missingArguments)) { - throw new Twig_Error_Syntax(sprintf( + throw new \Twig\Error\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()); @@ -166,7 +166,7 @@ protected function getArguments($callable, $arguments) $optionalArguments = []; ++$pos; } elseif ($callableParameter->isDefaultValueAvailable()) { - $optionalArguments[] = new Twig_Node_Expression_Constant($callableParameter->getDefaultValue(), -1); + $optionalArguments[] = new \Twig\Node\Expression\ConstantExpression($callableParameter->getDefaultValue(), -1); } elseif ($callableParameter->isOptional()) { if (empty($parameters)) { break; @@ -174,17 +174,17 @@ protected function getArguments($callable, $arguments) $missingArguments[] = $name; } } else { - throw new Twig_Error_Syntax(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); + throw new \Twig\Error\SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); } } if ($isVariadic) { - $arbitraryArguments = new Twig_Node_Expression_Array([], -1); + $arbitraryArguments = new \Twig\Node\Expression\ArrayExpression([], -1); foreach ($parameters as $key => $value) { if (\is_int($key)) { $arbitraryArguments->addElement($value); } else { - $arbitraryArguments->addElement($value, new Twig_Node_Expression_Constant($key, -1)); + $arbitraryArguments->addElement($value, new \Twig\Node\Expression\ConstantExpression($key, -1)); } unset($parameters[$key]); } @@ -198,13 +198,13 @@ protected function getArguments($callable, $arguments) if (!empty($parameters)) { $unknownParameter = null; foreach ($parameters as $parameter) { - if ($parameter instanceof Twig_Node) { + if ($parameter instanceof \Twig\Node\Node) { $unknownParameter = $parameter; break; } } - throw new Twig_Error_Syntax(sprintf( + throw new \Twig\Error\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()); diff --git a/lib/Twig/Node/Expression/Conditional.php b/lib/Twig/Node/Expression/Conditional.php index 996772a05b..7f3a6c9a22 100644 --- a/lib/Twig/Node/Expression/Conditional.php +++ b/lib/Twig/Node/Expression/Conditional.php @@ -9,14 +9,14 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Conditional extends Twig_Node_Expression +class Twig_Node_Expression_Conditional extends \Twig\Node\Expression\AbstractExpression { - public function __construct(Twig_Node_Expression $expr1, Twig_Node_Expression $expr2, Twig_Node_Expression $expr3, $lineno) + public function __construct(\Twig\Node\Expression\AbstractExpression $expr1, \Twig\Node\Expression\AbstractExpression $expr2, \Twig\Node\Expression\AbstractExpression $expr3, $lineno) { parent::__construct(['expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('((') diff --git a/lib/Twig/Node/Expression/Constant.php b/lib/Twig/Node/Expression/Constant.php index 7304e8c3ba..cd01805766 100644 --- a/lib/Twig/Node/Expression/Constant.php +++ b/lib/Twig/Node/Expression/Constant.php @@ -9,14 +9,14 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Constant extends Twig_Node_Expression +class Twig_Node_Expression_Constant extends \Twig\Node\Expression\AbstractExpression { public function __construct($value, $lineno) { parent::__construct([], ['value' => $value], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->repr($this->getAttribute('value')); } diff --git a/lib/Twig/Node/Expression/ExtensionReference.php b/lib/Twig/Node/Expression/ExtensionReference.php index 7bcc078cad..dfec4214a2 100644 --- a/lib/Twig/Node/Expression/ExtensionReference.php +++ b/lib/Twig/Node/Expression/ExtensionReference.php @@ -18,14 +18,14 @@ * * @deprecated since 1.23 and will be removed in 2.0. */ -class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression +class Twig_Node_Expression_ExtensionReference extends \Twig\Node\Expression\AbstractExpression { public function __construct($name, $lineno, $tag = null) { parent::__construct([], ['name' => $name], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name'))); } diff --git a/lib/Twig/Node/Expression/Filter.php b/lib/Twig/Node/Expression/Filter.php index 7b5952fb1f..2efaf3ca0e 100644 --- a/lib/Twig/Node/Expression/Filter.php +++ b/lib/Twig/Node/Expression/Filter.php @@ -9,14 +9,14 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Filter extends Twig_Node_Expression_Call +class Twig_Node_Expression_Filter extends \Twig\Node\Expression\CallExpression { - public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) + public function __construct(Twig_NodeInterface $node, \Twig\Node\Expression\ConstantExpression $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) { parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $name = $this->getNode('filter')->getAttribute('value'); $filter = $compiler->getEnvironment()->getFilter($name); @@ -27,10 +27,10 @@ public function compile(Twig_Compiler $compiler) $this->setAttribute('needs_environment', $filter->needsEnvironment()); $this->setAttribute('needs_context', $filter->needsContext()); $this->setAttribute('arguments', $filter->getArguments()); - if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof Twig_SimpleFilter) { + if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof \Twig\TwigFilter) { $this->setAttribute('callable', $filter->getCallable()); } - if ($filter instanceof Twig_SimpleFilter) { + if ($filter instanceof \Twig\TwigFilter) { $this->setAttribute('is_variadic', $filter->isVariadic()); } diff --git a/lib/Twig/Node/Expression/Filter/Default.php b/lib/Twig/Node/Expression/Filter/Default.php index 3fbbe52ebd..ebc7d6bb0e 100644 --- a/lib/Twig/Node/Expression/Filter/Default.php +++ b/lib/Twig/Node/Expression/Filter/Default.php @@ -16,17 +16,17 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter +class Twig_Node_Expression_Filter_Default extends \Twig\Node\Expression\FilterExpression { - public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) + public function __construct(Twig_NodeInterface $node, \Twig\Node\Expression\ConstantExpression $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) { - $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); + $default = new \Twig\Node\Expression\FilterExpression($node, new \Twig\Node\Expression\ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); - if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) { - $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getTemplateLine()); - $false = \count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getTemplateLine()); + if ('default' === $filterName->getAttribute('value') && ($node instanceof \Twig\Node\Expression\NameExpression || $node instanceof \Twig\Node\Expression\GetAttrExpression)) { + $test = new \Twig\Node\Expression\Test\DefinedTest(clone $node, 'defined', new \Twig\Node\Node(), $node->getTemplateLine()); + $false = \count($arguments) ? $arguments->getNode(0) : new \Twig\Node\Expression\ConstantExpression('', $node->getTemplateLine()); - $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getTemplateLine()); + $node = new \Twig\Node\Expression\ConditionalExpression($test, $default, $false, $node->getTemplateLine()); } else { $node = $default; } @@ -34,7 +34,7 @@ public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Const parent::__construct($node, $filterName, $arguments, $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->subcompile($this->getNode('node')); } diff --git a/lib/Twig/Node/Expression/Function.php b/lib/Twig/Node/Expression/Function.php index c19633f187..e73c51ae1d 100644 --- a/lib/Twig/Node/Expression/Function.php +++ b/lib/Twig/Node/Expression/Function.php @@ -8,14 +8,14 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Function extends Twig_Node_Expression_Call +class Twig_Node_Expression_Function extends \Twig\Node\Expression\CallExpression { public function __construct($name, Twig_NodeInterface $arguments, $lineno) { parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $name = $this->getAttribute('name'); $function = $compiler->getEnvironment()->getFunction($name); @@ -26,7 +26,7 @@ public function compile(Twig_Compiler $compiler) $this->setAttribute('needs_environment', $function->needsEnvironment()); $this->setAttribute('needs_context', $function->needsContext()); $this->setAttribute('arguments', $function->getArguments()); - if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) { + if ($function instanceof Twig_FunctionCallableInterface || $function instanceof \Twig\TwigFunction) { $callable = $function->getCallable(); if ('constant' === $name && $this->getAttribute('is_defined_test')) { $callable = 'twig_constant_is_defined'; @@ -34,7 +34,7 @@ public function compile(Twig_Compiler $compiler) $this->setAttribute('callable', $callable); } - if ($function instanceof Twig_SimpleFunction) { + if ($function instanceof \Twig\TwigFunction) { $this->setAttribute('is_variadic', $function->isVariadic()); } diff --git a/lib/Twig/Node/Expression/GetAttr.php b/lib/Twig/Node/Expression/GetAttr.php index b3a01b27f0..7da9f032da 100644 --- a/lib/Twig/Node/Expression/GetAttr.php +++ b/lib/Twig/Node/Expression/GetAttr.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_GetAttr extends Twig_Node_Expression +class Twig_Node_Expression_GetAttr extends \Twig\Node\Expression\AbstractExpression { - public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression $arguments = null, $type, $lineno) + public function __construct(\Twig\Node\Expression\AbstractExpression $node, \Twig\Node\Expression\AbstractExpression $attribute, \Twig\Node\Expression\AbstractExpression $arguments = null, $type, $lineno) { $nodes = ['node' => $node, 'attribute' => $attribute]; if (null !== $arguments) { @@ -21,7 +21,7 @@ public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $at parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { if ($this->getAttribute('disable_c_ext')) { @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED); @@ -44,7 +44,7 @@ public function compile(Twig_Compiler $compiler) // only generate optional arguments when needed (to make generated code more readable) $needFourth = $this->getAttribute('ignore_strict_check'); $needThird = $needFourth || $this->getAttribute('is_defined_test'); - $needSecond = $needThird || Twig_Template::ANY_CALL !== $this->getAttribute('type'); + $needSecond = $needThird || \Twig\Template::ANY_CALL !== $this->getAttribute('type'); $needFirst = $needSecond || $this->hasNode('arguments'); if ($needFirst) { diff --git a/lib/Twig/Node/Expression/MethodCall.php b/lib/Twig/Node/Expression/MethodCall.php index b8a83450af..9048fff299 100644 --- a/lib/Twig/Node/Expression/MethodCall.php +++ b/lib/Twig/Node/Expression/MethodCall.php @@ -8,18 +8,18 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_MethodCall extends Twig_Node_Expression +class Twig_Node_Expression_MethodCall extends \Twig\Node\Expression\AbstractExpression { - public function __construct(Twig_Node_Expression $node, $method, Twig_Node_Expression_Array $arguments, $lineno) + public function __construct(\Twig\Node\Expression\AbstractExpression $node, $method, \Twig\Node\Expression\ArrayExpression $arguments, $lineno) { parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false], $lineno); - if ($node instanceof Twig_Node_Expression_Name) { + if ($node instanceof \Twig\Node\Expression\NameExpression) { $node->setAttribute('always_defined', true); } } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->subcompile($this->getNode('node')) diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index 2d1d3d1c25..c6ef9936e6 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -9,7 +9,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Name extends Twig_Node_Expression +class Twig_Node_Expression_Name extends \Twig\Node\Expression\AbstractExpression { protected $specialVars = [ '_self' => '$this', @@ -22,7 +22,7 @@ public function __construct($name, $lineno) parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $name = $this->getAttribute('name'); diff --git a/lib/Twig/Node/Expression/NullCoalesce.php b/lib/Twig/Node/Expression/NullCoalesce.php index eaafa4c91e..5d022154cf 100644 --- a/lib/Twig/Node/Expression/NullCoalesce.php +++ b/lib/Twig/Node/Expression/NullCoalesce.php @@ -8,20 +8,20 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_NullCoalesce extends Twig_Node_Expression_Conditional +class Twig_Node_Expression_NullCoalesce extends \Twig\Node\Expression\ConditionalExpression { public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno) { - $test = new Twig_Node_Expression_Binary_And( - new Twig_Node_Expression_Test_Defined(clone $left, 'defined', new Twig_Node(), $left->getTemplateLine()), - new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getTemplateLine()), $left->getTemplateLine()), + $test = new \Twig\Node\Expression\Binary\AndBinary( + new \Twig\Node\Expression\Test\DefinedTest(clone $left, 'defined', new \Twig\Node\Node(), $left->getTemplateLine()), + new \Twig\Node\Expression\Unary\NotUnary(new \Twig\Node\Expression\Test\NullTest($left, 'null', new \Twig\Node\Node(), $left->getTemplateLine()), $left->getTemplateLine()), $left->getTemplateLine() ); parent::__construct($test, $left, $right, $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { /* * This optimizes only one case. PHP 7 also supports more complex expressions @@ -30,7 +30,7 @@ public function compile(Twig_Compiler $compiler) * cases might be implemented as an optimizer node visitor, but has not been done * as benefits are probably not worth the added complexity. */ - if (PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof Twig_Node_Expression_Name) { + if (PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof \Twig\Node\Expression\NameExpression) { $this->getNode('expr2')->setAttribute('always_defined', true); $compiler ->raw('((') diff --git a/lib/Twig/Node/Expression/Parent.php b/lib/Twig/Node/Expression/Parent.php index 8623685280..59d857792d 100644 --- a/lib/Twig/Node/Expression/Parent.php +++ b/lib/Twig/Node/Expression/Parent.php @@ -15,14 +15,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Parent extends Twig_Node_Expression +class Twig_Node_Expression_Parent extends \Twig\Node\Expression\AbstractExpression { public function __construct($name, $lineno, $tag = null) { parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { if ($this->getAttribute('output')) { $compiler diff --git a/lib/Twig/Node/Expression/TempName.php b/lib/Twig/Node/Expression/TempName.php index 4be1cc2c27..1184eaae1e 100644 --- a/lib/Twig/Node/Expression/TempName.php +++ b/lib/Twig/Node/Expression/TempName.php @@ -8,14 +8,14 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_TempName extends Twig_Node_Expression +class Twig_Node_Expression_TempName extends \Twig\Node\Expression\AbstractExpression { public function __construct($name, $lineno) { parent::__construct([], ['name' => $name], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('$_') diff --git a/lib/Twig/Node/Expression/Test.php b/lib/Twig/Node/Expression/Test.php index a543ec55dc..04bc83125c 100644 --- a/lib/Twig/Node/Expression/Test.php +++ b/lib/Twig/Node/Expression/Test.php @@ -8,7 +8,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Test extends Twig_Node_Expression_Call +class Twig_Node_Expression_Test extends \Twig\Node\Expression\CallExpression { public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) { @@ -20,7 +20,7 @@ public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface parent::__construct($nodes, ['name' => $name], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $name = $this->getAttribute('name'); $test = $compiler->getEnvironment()->getTest($name); @@ -28,13 +28,13 @@ public function compile(Twig_Compiler $compiler) $this->setAttribute('name', $name); $this->setAttribute('type', 'test'); $this->setAttribute('thing', $test); - if ($test instanceof Twig_SimpleTest) { + if ($test instanceof \Twig\TwigTest) { $this->setAttribute('arguments', $test->getArguments()); } - if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) { + if ($test instanceof Twig_TestCallableInterface || $test instanceof \Twig\TwigTest) { $this->setAttribute('callable', $test->getCallable()); } - if ($test instanceof Twig_SimpleTest) { + if ($test instanceof \Twig\TwigTest) { $this->setAttribute('is_variadic', $test->isVariadic()); } diff --git a/lib/Twig/Node/Expression/Test/Constant.php b/lib/Twig/Node/Expression/Test/Constant.php index 6afb061f4c..12b9b27473 100644 --- a/lib/Twig/Node/Expression/Test/Constant.php +++ b/lib/Twig/Node/Expression/Test/Constant.php @@ -18,9 +18,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test +class Twig_Node_Expression_Test_Constant extends \Twig\Node\Expression\TestExpression { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Test/Defined.php b/lib/Twig/Node/Expression/Test/Defined.php index 235f99333a..f9056ec387 100644 --- a/lib/Twig/Node/Expression/Test/Defined.php +++ b/lib/Twig/Node/Expression/Test/Defined.php @@ -19,38 +19,38 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test +class Twig_Node_Expression_Test_Defined extends \Twig\Node\Expression\TestExpression { public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) { - if ($node instanceof Twig_Node_Expression_Name) { + if ($node instanceof \Twig\Node\Expression\NameExpression) { $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_GetAttr) { + } elseif ($node instanceof \Twig\Node\Expression\GetAttrExpression) { $node->setAttribute('is_defined_test', true); $this->changeIgnoreStrictCheck($node); - } elseif ($node instanceof Twig_Node_Expression_BlockReference) { + } elseif ($node instanceof \Twig\Node\Expression\BlockReferenceExpression) { $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_Function && 'constant' === $node->getAttribute('name')) { + } elseif ($node instanceof \Twig\Node\Expression\FunctionExpression && 'constant' === $node->getAttribute('name')) { $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) { - $node = new Twig_Node_Expression_Constant(true, $node->getTemplateLine()); + } elseif ($node instanceof \Twig\Node\Expression\ConstantExpression || $node instanceof \Twig\Node\Expression\ArrayExpression) { + $node = new \Twig\Node\Expression\ConstantExpression(true, $node->getTemplateLine()); } else { - throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getTemplateLine()); + throw new \Twig\Error\SyntaxError('The "defined" test only works with simple variables.', $this->getTemplateLine()); } parent::__construct($node, $name, $arguments, $lineno); } - protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node) + protected function changeIgnoreStrictCheck(\Twig\Node\Expression\GetAttrExpression $node) { $node->setAttribute('ignore_strict_check', true); - if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) { + if ($node->getNode('node') instanceof \Twig\Node\Expression\GetAttrExpression) { $this->changeIgnoreStrictCheck($node->getNode('node')); } } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->subcompile($this->getNode('node')); } diff --git a/lib/Twig/Node/Expression/Test/Divisibleby.php b/lib/Twig/Node/Expression/Test/Divisibleby.php index 60e7ec7046..02b4999e17 100644 --- a/lib/Twig/Node/Expression/Test/Divisibleby.php +++ b/lib/Twig/Node/Expression/Test/Divisibleby.php @@ -16,9 +16,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test +class Twig_Node_Expression_Test_Divisibleby extends \Twig\Node\Expression\TestExpression { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('(0 == ') diff --git a/lib/Twig/Node/Expression/Test/Even.php b/lib/Twig/Node/Expression/Test/Even.php index 577728bfd8..b059b18de0 100644 --- a/lib/Twig/Node/Expression/Test/Even.php +++ b/lib/Twig/Node/Expression/Test/Even.php @@ -16,9 +16,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Even extends Twig_Node_Expression_Test +class Twig_Node_Expression_Test_Even extends \Twig\Node\Expression\TestExpression { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Test/Null.php b/lib/Twig/Node/Expression/Test/Null.php index 185c5b1bcf..a5bf547634 100644 --- a/lib/Twig/Node/Expression/Test/Null.php +++ b/lib/Twig/Node/Expression/Test/Null.php @@ -16,9 +16,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Null extends Twig_Node_Expression_Test +class Twig_Node_Expression_Test_Null extends \Twig\Node\Expression\TestExpression { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('(null === ') diff --git a/lib/Twig/Node/Expression/Test/Odd.php b/lib/Twig/Node/Expression/Test/Odd.php index 45ce53ebeb..2752a41253 100644 --- a/lib/Twig/Node/Expression/Test/Odd.php +++ b/lib/Twig/Node/Expression/Test/Odd.php @@ -16,9 +16,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test +class Twig_Node_Expression_Test_Odd extends \Twig\Node\Expression\TestExpression { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Test/Sameas.php b/lib/Twig/Node/Expression/Test/Sameas.php index e95ff1f20c..b8cbaad110 100644 --- a/lib/Twig/Node/Expression/Test/Sameas.php +++ b/lib/Twig/Node/Expression/Test/Sameas.php @@ -14,9 +14,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Sameas extends Twig_Node_Expression_Test +class Twig_Node_Expression_Test_Sameas extends \Twig\Node\Expression\TestExpression { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Unary.php b/lib/Twig/Node/Expression/Unary.php index abf191a387..88575e23c4 100644 --- a/lib/Twig/Node/Expression/Unary.php +++ b/lib/Twig/Node/Expression/Unary.php @@ -9,21 +9,21 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -abstract class Twig_Node_Expression_Unary extends Twig_Node_Expression +abstract class Twig_Node_Expression_Unary extends \Twig\Node\Expression\AbstractExpression { public function __construct(Twig_NodeInterface $node, $lineno) { parent::__construct(['node' => $node], [], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->raw(' '); $this->operator($compiler); $compiler->subcompile($this->getNode('node')); } - abstract public function operator(Twig_Compiler $compiler); + abstract public function operator(\Twig\Compiler $compiler); } class_alias('Twig_Node_Expression_Unary', 'Twig\Node\Expression\Unary\AbstractUnary', false); diff --git a/lib/Twig/Node/Expression/Unary/Neg.php b/lib/Twig/Node/Expression/Unary/Neg.php index 039d933d93..92a36c06af 100644 --- a/lib/Twig/Node/Expression/Unary/Neg.php +++ b/lib/Twig/Node/Expression/Unary/Neg.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Unary_Neg extends Twig_Node_Expression_Unary +class Twig_Node_Expression_Unary_Neg extends \Twig\Node\Expression\Unary\AbstractUnary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { $compiler->raw('-'); } diff --git a/lib/Twig/Node/Expression/Unary/Not.php b/lib/Twig/Node/Expression/Unary/Not.php index a0860b1838..ec6269615f 100644 --- a/lib/Twig/Node/Expression/Unary/Not.php +++ b/lib/Twig/Node/Expression/Unary/Not.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Unary_Not extends Twig_Node_Expression_Unary +class Twig_Node_Expression_Unary_Not extends \Twig\Node\Expression\Unary\AbstractUnary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { $compiler->raw('!'); } diff --git a/lib/Twig/Node/Expression/Unary/Pos.php b/lib/Twig/Node/Expression/Unary/Pos.php index eeff5452ff..2d5267d3d3 100644 --- a/lib/Twig/Node/Expression/Unary/Pos.php +++ b/lib/Twig/Node/Expression/Unary/Pos.php @@ -9,9 +9,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Unary_Pos extends Twig_Node_Expression_Unary +class Twig_Node_Expression_Unary_Pos extends \Twig\Node\Expression\Unary\AbstractUnary { - public function operator(Twig_Compiler $compiler) + public function operator(\Twig\Compiler $compiler) { $compiler->raw('+'); } diff --git a/lib/Twig/Node/Flush.php b/lib/Twig/Node/Flush.php index 5d3ffd52d3..a05f805c67 100644 --- a/lib/Twig/Node/Flush.php +++ b/lib/Twig/Node/Flush.php @@ -14,14 +14,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Flush extends Twig_Node +class Twig_Node_Flush extends \Twig\Node\Node { public function __construct($lineno, $tag) { parent::__construct([], [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index 1b592e25a6..5978e0140f 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -15,16 +15,16 @@ * * @author Fabien Potencier */ -class Twig_Node_For extends Twig_Node +class Twig_Node_For extends \Twig\Node\Node { protected $loop; - public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null) + public function __construct(\Twig\Node\Expression\AssignNameExpression $keyTarget, \Twig\Node\Expression\AssignNameExpression $valueTarget, \Twig\Node\Expression\AbstractExpression $seq, \Twig\Node\Expression\AbstractExpression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null) { - $body = new Twig_Node([$body, $this->loop = new Twig_Node_ForLoop($lineno, $tag)]); + $body = new \Twig\Node\Node([$body, $this->loop = new \Twig\Node\ForLoopNode($lineno, $tag)]); if (null !== $ifexpr) { - $body = new Twig_Node_If(new Twig_Node([$ifexpr, $body]), null, $lineno, $tag); + $body = new \Twig\Node\IfNode(new \Twig\Node\Node([$ifexpr, $body]), null, $lineno, $tag); } $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body]; @@ -35,7 +35,7 @@ public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Nod parent::__construct($nodes, ['with_loop' => true, 'ifexpr' => null !== $ifexpr], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/ForLoop.php b/lib/Twig/Node/ForLoop.php index 31f282d79a..d5bb816b9e 100644 --- a/lib/Twig/Node/ForLoop.php +++ b/lib/Twig/Node/ForLoop.php @@ -14,14 +14,14 @@ * * @author Fabien Potencier */ -class Twig_Node_ForLoop extends Twig_Node +class Twig_Node_ForLoop extends \Twig\Node\Node { public function __construct($lineno, $tag = null) { parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { if ($this->getAttribute('else')) { $compiler->write("\$context['_iterated'] = true;\n"); diff --git a/lib/Twig/Node/If.php b/lib/Twig/Node/If.php index 3a5af2cdfc..6bdc9e8f34 100644 --- a/lib/Twig/Node/If.php +++ b/lib/Twig/Node/If.php @@ -15,7 +15,7 @@ * * @author Fabien Potencier */ -class Twig_Node_If extends Twig_Node +class Twig_Node_If extends \Twig\Node\Node { public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else = null, $lineno, $tag = null) { @@ -27,7 +27,7 @@ public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else parent::__construct($nodes, [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->addDebugInfo($this); for ($i = 0, $count = \count($this->getNode('tests')); $i < $count; $i += 2) { diff --git a/lib/Twig/Node/Import.php b/lib/Twig/Node/Import.php index 44b2131e2b..1317e30742 100644 --- a/lib/Twig/Node/Import.php +++ b/lib/Twig/Node/Import.php @@ -14,14 +14,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Import extends Twig_Node +class Twig_Node_Import extends \Twig\Node\Node { - public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $var, $lineno, $tag = null) + public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \Twig\Node\Expression\AbstractExpression $var, $lineno, $tag = null) { parent::__construct(['expr' => $expr, 'var' => $var], [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) @@ -30,7 +30,7 @@ public function compile(Twig_Compiler $compiler) ->raw(' = ') ; - if ($this->getNode('expr') instanceof Twig_Node_Expression_Name && '_self' === $this->getNode('expr')->getAttribute('name')) { + if ($this->getNode('expr') instanceof \Twig\Node\Expression\NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) { $compiler->raw('$this'); } else { $compiler diff --git a/lib/Twig/Node/Include.php b/lib/Twig/Node/Include.php index 4b263819ff..f3bef8a0d1 100644 --- a/lib/Twig/Node/Include.php +++ b/lib/Twig/Node/Include.php @@ -15,9 +15,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface +class Twig_Node_Include extends \Twig\Node\Node implements \Twig\Node\NodeOutputInterface { - public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) + public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \Twig\Node\Expression\AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) { $nodes = ['expr' => $expr]; if (null !== $variables) { @@ -27,7 +27,7 @@ public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $va parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->addDebugInfo($this); @@ -49,7 +49,7 @@ public function compile(Twig_Compiler $compiler) if ($this->getAttribute('ignore_missing')) { $compiler ->outdent() - ->write("} catch (Twig_Error_Loader \$e) {\n") + ->write("} catch (\Twig\Error\LoaderError \$e) {\n") ->indent() ->write("// ignore missing template\n") ->outdent() @@ -58,7 +58,7 @@ public function compile(Twig_Compiler $compiler) } } - protected function addGetTemplate(Twig_Compiler $compiler) + protected function addGetTemplate(\Twig\Compiler $compiler) { $compiler ->write('$this->loadTemplate(') @@ -71,7 +71,7 @@ protected function addGetTemplate(Twig_Compiler $compiler) ; } - protected function addTemplateArguments(Twig_Compiler $compiler) + protected function addTemplateArguments(\Twig\Compiler $compiler) { if (!$this->hasNode('variables')) { $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]'); diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 592c11e1ac..68ba03d359 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -14,7 +14,7 @@ * * @author Fabien Potencier */ -class Twig_Node_Macro extends Twig_Node +class Twig_Node_Macro extends \Twig\Node\Node { const VARARGS_NAME = 'varargs'; @@ -22,14 +22,14 @@ public function __construct($name, Twig_NodeInterface $body, Twig_NodeInterface { foreach ($arguments as $argumentName => $argument) { if (self::VARARGS_NAME === $argumentName) { - throw new Twig_Error_Syntax(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 \Twig\Error\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()); } } parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) @@ -115,7 +115,7 @@ public function compile(Twig_Compiler $compiler) ->write("throw \$e;\n") ->outdent() ->write("}\n\n") - ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") + ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset());\n") ->outdent() ->write("}\n\n") ; diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index b24a29e4e6..d4b9164f6c 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -19,15 +19,15 @@ * * @author Fabien Potencier */ -class Twig_Node_Module extends Twig_Node +class Twig_Node_Module extends \Twig\Node\Node { private $source; - public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '') + public function __construct(Twig_NodeInterface $body, \Twig\Node\Expression\AbstractExpression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '') { - if (!$name instanceof Twig_Source) { + if (!$name instanceof \Twig\Source) { @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $this->source = new Twig_Source($source, $name); + $this->source = new \Twig\Source($source, $name); } else { $this->source = $name; } @@ -37,11 +37,11 @@ public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $pare 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits, - 'display_start' => new Twig_Node(), - 'display_end' => new Twig_Node(), - 'constructor_start' => new Twig_Node(), - 'constructor_end' => new Twig_Node(), - 'class_end' => new Twig_Node(), + 'display_start' => new \Twig\Node\Node(), + 'display_end' => new \Twig\Node\Node(), + 'constructor_start' => new \Twig\Node\Node(), + 'constructor_end' => new \Twig\Node\Node(), + 'class_end' => new \Twig\Node\Node(), ]; if (null !== $parent) { $nodes['parent'] = $parent; @@ -66,7 +66,7 @@ public function setIndex($index) $this->setAttribute('index', $index); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $this->compileTemplate($compiler); @@ -75,7 +75,7 @@ public function compile(Twig_Compiler $compiler) } } - protected function compileTemplate(Twig_Compiler $compiler) + protected function compileTemplate(\Twig\Compiler $compiler) { if (!$this->getAttribute('index')) { $compiler->write('getNode('blocks')) || \count($this->getNode('traits')) || !$this->hasNode('parent') - || $this->getNode('parent') instanceof Twig_Node_Expression_Constant + || $this->getNode('parent') instanceof \Twig\Node\Expression\ConstantExpression || \count($this->getNode('constructor_start')) || \count($this->getNode('constructor_end')) ) { @@ -115,7 +115,7 @@ protected function compileTemplate(Twig_Compiler $compiler) $this->compileClassFooter($compiler); } - protected function compileGetParent(Twig_Compiler $compiler) + protected function compileGetParent(\Twig\Compiler $compiler) { if (!$this->hasNode('parent')) { return; @@ -129,7 +129,7 @@ protected function compileGetParent(Twig_Compiler $compiler) ->write('return ') ; - if ($parent instanceof Twig_Node_Expression_Constant) { + if ($parent instanceof \Twig\Node\Expression\ConstantExpression) { $compiler->subcompile($parent); } else { $compiler @@ -150,7 +150,7 @@ protected function compileGetParent(Twig_Compiler $compiler) ; } - protected function compileClassHeader(Twig_Compiler $compiler) + protected function compileClassHeader(\Twig\Compiler $compiler) { $compiler ->write("\n\n") @@ -163,10 +163,10 @@ protected function compileClassHeader(Twig_Compiler $compiler) ; } - protected function compileConstructor(Twig_Compiler $compiler) + protected function compileConstructor(\Twig\Compiler $compiler) { $compiler - ->write("public function __construct(Twig_Environment \$env)\n", "{\n") + ->write("public function __construct(\Twig\Environment \$env)\n", "{\n") ->indent() ->subcompile($this->getNode('constructor_start')) ->write("parent::__construct(\$env);\n\n") @@ -175,7 +175,7 @@ protected function compileConstructor(Twig_Compiler $compiler) // parent if (!$this->hasNode('parent')) { $compiler->write("\$this->parent = false;\n\n"); - } elseif (($parent = $this->getNode('parent')) && $parent instanceof Twig_Node_Expression_Constant) { + } elseif (($parent = $this->getNode('parent')) && $parent instanceof \Twig\Node\Expression\ConstantExpression) { $compiler ->addDebugInfo($parent) ->write('$this->parent = $this->loadTemplate(') @@ -198,7 +198,7 @@ protected function compileConstructor(Twig_Compiler $compiler) ->addDebugInfo($trait->getNode('template')) ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i)) ->indent() - ->write("throw new Twig_Error_Runtime('Template \"'.") + ->write("throw new \Twig\Error\RuntimeError('Template \"'.") ->subcompile($trait->getNode('template')) ->raw(".'\" cannot be used as a trait.');\n") ->outdent() @@ -212,7 +212,7 @@ protected function compileConstructor(Twig_Compiler $compiler) ->string($key) ->raw("])) {\n") ->indent() - ->write("throw new Twig_Error_Runtime(sprintf('Block ") + ->write("throw new \Twig\Error\RuntimeError(sprintf('Block ") ->string($key) ->raw(' is not defined in trait ') ->subcompile($trait->getNode('template')) @@ -297,7 +297,7 @@ protected function compileConstructor(Twig_Compiler $compiler) ; } - protected function compileDisplay(Twig_Compiler $compiler) + protected function compileDisplay(\Twig\Compiler $compiler) { $compiler ->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n") @@ -309,7 +309,7 @@ protected function compileDisplay(Twig_Compiler $compiler) if ($this->hasNode('parent')) { $parent = $this->getNode('parent'); $compiler->addDebugInfo($parent); - if ($parent instanceof Twig_Node_Expression_Constant) { + if ($parent instanceof \Twig\Node\Expression\ConstantExpression) { $compiler->write('$this->parent'); } else { $compiler->write('$this->getParent($context)'); @@ -324,7 +324,7 @@ protected function compileDisplay(Twig_Compiler $compiler) ; } - protected function compileClassFooter(Twig_Compiler $compiler) + protected function compileClassFooter(\Twig\Compiler $compiler) { $compiler ->subcompile($this->getNode('class_end')) @@ -333,12 +333,12 @@ protected function compileClassFooter(Twig_Compiler $compiler) ; } - protected function compileMacros(Twig_Compiler $compiler) + protected function compileMacros(\Twig\Compiler $compiler) { $compiler->subcompile($this->getNode('macros')); } - protected function compileGetTemplateName(Twig_Compiler $compiler) + protected function compileGetTemplateName(\Twig\Compiler $compiler) { $compiler ->write("public function getTemplateName()\n", "{\n") @@ -351,7 +351,7 @@ protected function compileGetTemplateName(Twig_Compiler $compiler) ; } - protected function compileIsTraitable(Twig_Compiler $compiler) + protected function compileIsTraitable(\Twig\Compiler $compiler) { // A template can be used as a trait if: // * it has no parent @@ -362,14 +362,14 @@ protected function compileIsTraitable(Twig_Compiler $compiler) // only contains blocks and use statements. $traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros')); if ($traitable) { - if ($this->getNode('body') instanceof Twig_Node_Body) { + if ($this->getNode('body') instanceof \Twig\Node\BodyNode) { $nodes = $this->getNode('body')->getNode(0); } else { $nodes = $this->getNode('body'); } if (!\count($nodes)) { - $nodes = new Twig_Node([$nodes]); + $nodes = new \Twig\Node\Node([$nodes]); } foreach ($nodes as $node) { @@ -377,11 +377,11 @@ protected function compileIsTraitable(Twig_Compiler $compiler) continue; } - if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) { + if ($node instanceof \Twig\Node\TextNode && ctype_space($node->getAttribute('data'))) { continue; } - if ($node instanceof Twig_Node_BlockReference) { + if ($node instanceof \Twig\Node\BlockReferenceNode) { continue; } @@ -403,7 +403,7 @@ protected function compileIsTraitable(Twig_Compiler $compiler) ; } - protected function compileDebugInfo(Twig_Compiler $compiler) + protected function compileDebugInfo(\Twig\Compiler $compiler) { $compiler ->write("public function getDebugInfo()\n", "{\n") @@ -414,7 +414,7 @@ protected function compileDebugInfo(Twig_Compiler $compiler) ; } - protected function compileGetSource(Twig_Compiler $compiler) + protected function compileGetSource(\Twig\Compiler $compiler) { $compiler ->write("/** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */\n") @@ -428,12 +428,12 @@ protected function compileGetSource(Twig_Compiler $compiler) ; } - protected function compileGetSourceContext(Twig_Compiler $compiler) + protected function compileGetSourceContext(\Twig\Compiler $compiler) { $compiler ->write("public function getSourceContext()\n", "{\n") ->indent() - ->write('return new Twig_Source(') + ->write('return new \Twig\Source(') ->string($compiler->getEnvironment()->isDebug() ? $this->source->getCode() : '') ->raw(', ') ->string($this->source->getName()) @@ -445,9 +445,9 @@ protected function compileGetSourceContext(Twig_Compiler $compiler) ; } - protected function compileLoadTemplate(Twig_Compiler $compiler, $node, $var) + protected function compileLoadTemplate(\Twig\Compiler $compiler, $node, $var) { - if ($node instanceof Twig_Node_Expression_Constant) { + if ($node instanceof \Twig\Node\Expression\ConstantExpression) { $compiler ->write(sprintf('%s = $this->loadTemplate(', $var)) ->subcompile($node) diff --git a/lib/Twig/Node/Print.php b/lib/Twig/Node/Print.php index 215d712ad0..4ad9bb33ba 100644 --- a/lib/Twig/Node/Print.php +++ b/lib/Twig/Node/Print.php @@ -15,14 +15,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface +class Twig_Node_Print extends \Twig\Node\Node implements \Twig\Node\NodeOutputInterface { - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) + public function __construct(\Twig\Node\Expression\AbstractExpression $expr, $lineno, $tag = null) { parent::__construct(['expr' => $expr], [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/Sandbox.php b/lib/Twig/Node/Sandbox.php index e06f332be5..a5253889eb 100644 --- a/lib/Twig/Node/Sandbox.php +++ b/lib/Twig/Node/Sandbox.php @@ -14,18 +14,18 @@ * * @author Fabien Potencier */ -class Twig_Node_Sandbox extends Twig_Node +class Twig_Node_Sandbox extends \Twig\Node\Node { public function __construct(Twig_NodeInterface $body, $lineno, $tag = null) { parent::__construct(['body' => $body], [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) - ->write("\$sandbox = \$this->env->getExtension('Twig_Extension_Sandbox');\n") + ->write("\$sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');\n") ->write("if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {\n") ->indent() ->write("\$sandbox->enableSandbox();\n") diff --git a/lib/Twig/Node/SandboxedPrint.php b/lib/Twig/Node/SandboxedPrint.php index a08f21f567..05abce6ccc 100644 --- a/lib/Twig/Node/SandboxedPrint.php +++ b/lib/Twig/Node/SandboxedPrint.php @@ -19,13 +19,13 @@ * * @author Fabien Potencier */ -class Twig_Node_SandboxedPrint extends Twig_Node_Print +class Twig_Node_SandboxedPrint extends \Twig\Node\PrintNode { - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) - ->write('echo $this->env->getExtension(\'Twig_Extension_Sandbox\')->ensureToStringAllowed(') + ->write('echo $this->env->getExtension(\'\Twig\Extension\SandboxExtension\')->ensureToStringAllowed(') ->subcompile($this->getNode('expr')) ->raw(");\n") ; @@ -36,11 +36,11 @@ public function compile(Twig_Compiler $compiler) * * This is mostly needed when another visitor adds filters (like the escaper one). * - * @return Twig_Node + * @return \Twig\Node\Node */ - protected function removeNodeFilter(Twig_Node $node) + protected function removeNodeFilter(\Twig\Node\Node $node) { - if ($node instanceof Twig_Node_Expression_Filter) { + if ($node instanceof \Twig\Node\Expression\FilterExpression) { return $this->removeNodeFilter($node->getNode('node')); } diff --git a/lib/Twig/Node/Set.php b/lib/Twig/Node/Set.php index c1b5e95bea..700e5bd672 100644 --- a/lib/Twig/Node/Set.php +++ b/lib/Twig/Node/Set.php @@ -14,7 +14,7 @@ * * @author Fabien Potencier */ -class Twig_Node_Set extends Twig_Node implements Twig_NodeCaptureInterface +class Twig_Node_Set extends \Twig\Node\Node implements \Twig\Node\NodeCaptureInterface { public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null) { @@ -23,20 +23,20 @@ public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterf /* * Optimizes the node when capture is used for a large block of text. * - * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo"); + * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new \Twig\Markup("foo"); */ if ($this->getAttribute('capture')) { $this->setAttribute('safe', true); $values = $this->getNode('values'); - if ($values instanceof Twig_Node_Text) { - $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getTemplateLine())); + if ($values instanceof \Twig\Node\TextNode) { + $this->setNode('values', new \Twig\Node\Expression\ConstantExpression($values->getAttribute('data'), $values->getTemplateLine())); $this->setAttribute('capture', false); } } } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->addDebugInfo($this); @@ -61,7 +61,7 @@ public function compile(Twig_Compiler $compiler) $compiler->subcompile($this->getNode('names'), false); if ($this->getAttribute('capture')) { - $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())"); + $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset())"); } } @@ -83,7 +83,7 @@ public function compile(Twig_Compiler $compiler) $compiler ->raw("('' === \$tmp = ") ->subcompile($this->getNode('values')) - ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())") + ->raw(") ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset())") ; } else { $compiler->subcompile($this->getNode('values')); diff --git a/lib/Twig/Node/SetTemp.php b/lib/Twig/Node/SetTemp.php index c04ff45482..abea358eca 100644 --- a/lib/Twig/Node/SetTemp.php +++ b/lib/Twig/Node/SetTemp.php @@ -12,14 +12,14 @@ /** * @internal */ -class Twig_Node_SetTemp extends Twig_Node +class Twig_Node_SetTemp extends \Twig\Node\Node { public function __construct($name, $lineno) { parent::__construct([], ['name' => $name], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $name = $this->getAttribute('name'); $compiler diff --git a/lib/Twig/Node/Spaceless.php b/lib/Twig/Node/Spaceless.php index 43e907af22..82bbae9ff8 100644 --- a/lib/Twig/Node/Spaceless.php +++ b/lib/Twig/Node/Spaceless.php @@ -16,14 +16,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Spaceless extends Twig_Node +class Twig_Node_Spaceless extends \Twig\Node\Node { public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'spaceless') { parent::__construct(['body' => $body], [], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/Text.php b/lib/Twig/Node/Text.php index ab24d71962..c503bfa775 100644 --- a/lib/Twig/Node/Text.php +++ b/lib/Twig/Node/Text.php @@ -15,14 +15,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface +class Twig_Node_Text extends \Twig\Node\Node implements \Twig\Node\NodeOutputInterface { public function __construct($data, $lineno) { parent::__construct([], ['data' => $data], $lineno); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/With.php b/lib/Twig/Node/With.php index 422cc81221..9a4f9403af 100644 --- a/lib/Twig/Node/With.php +++ b/lib/Twig/Node/With.php @@ -14,9 +14,9 @@ * * @author Fabien Potencier */ -class Twig_Node_With extends Twig_Node +class Twig_Node_With extends \Twig\Node\Node { - public function __construct(Twig_Node $body, Twig_Node $variables = null, $only = false, $lineno, $tag = null) + public function __construct(\Twig\Node\Node $body, \Twig\Node\Node $variables = null, $only = false, $lineno, $tag = null) { $nodes = ['body' => $body]; if (null !== $variables) { @@ -26,7 +26,7 @@ public function __construct(Twig_Node $body, Twig_Node $variables = null, $only parent::__construct($nodes, ['only' => (bool) $only], $lineno, $tag); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler->addDebugInfo($this); @@ -38,7 +38,7 @@ public function compile(Twig_Compiler $compiler) ->raw(";\n") ->write(sprintf("if (!is_array(\$%s)) {\n", $varsName)) ->indent() - ->write("throw new Twig_Error_Runtime('Variables passed to the \"with\" tag must be a hash.');\n") + ->write("throw new \Twig\Error\RuntimeError('Variables passed to the \"with\" tag must be a hash.');\n") ->outdent() ->write("}\n") ; diff --git a/lib/Twig/NodeInterface.php b/lib/Twig/NodeInterface.php index 5cdf5ffec3..b2af005494 100644 --- a/lib/Twig/NodeInterface.php +++ b/lib/Twig/NodeInterface.php @@ -21,7 +21,7 @@ interface Twig_NodeInterface extends \Countable, \IteratorAggregate /** * Compiles the node to PHP. */ - public function compile(Twig_Compiler $compiler); + public function compile(\Twig\Compiler $compiler); /** * @deprecated since 1.27 (to be removed in 2.0) diff --git a/lib/Twig/NodeTraverser.php b/lib/Twig/NodeTraverser.php index 4b37b5c223..ee6cd9bc3f 100644 --- a/lib/Twig/NodeTraverser.php +++ b/lib/Twig/NodeTraverser.php @@ -24,9 +24,9 @@ class Twig_NodeTraverser protected $visitors = []; /** - * @param Twig_NodeVisitorInterface[] $visitors + * @param \Twig\NodeVisitor\NodeVisitorInterface[] $visitors */ - public function __construct(Twig_Environment $env, array $visitors = []) + public function __construct(\Twig\Environment $env, array $visitors = []) { $this->env = $env; foreach ($visitors as $visitor) { @@ -34,7 +34,7 @@ public function __construct(Twig_Environment $env, array $visitors = []) } } - public function addVisitor(Twig_NodeVisitorInterface $visitor) + public function addVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor) { if (!isset($this->visitors[$visitor->getPriority()])) { $this->visitors[$visitor->getPriority()] = []; @@ -60,7 +60,7 @@ public function traverse(Twig_NodeInterface $node) return $node; } - protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node = null) + protected function traverseForVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor, Twig_NodeInterface $node = null) { if (null === $node) { return; diff --git a/lib/Twig/NodeVisitor/Escaper.php b/lib/Twig/NodeVisitor/Escaper.php index 8c03657628..a57e73342a 100644 --- a/lib/Twig/NodeVisitor/Escaper.php +++ b/lib/Twig/NodeVisitor/Escaper.php @@ -16,7 +16,7 @@ * * @author Fabien Potencier */ -class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor +class Twig_NodeVisitor_Escaper extends \Twig\NodeVisitor\AbstractNodeVisitor { protected $statusStack = []; protected $blocks = []; @@ -27,50 +27,50 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor public function __construct() { - $this->safeAnalysis = new Twig_NodeVisitor_SafeAnalysis(); + $this->safeAnalysis = new \Twig\NodeVisitor\SafeAnalysisNodeVisitor(); } - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) + protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Module) { - if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getTemplateName())) { + if ($node instanceof \Twig\Node\ModuleNode) { + if ($env->hasExtension('\Twig\Extension\EscaperExtension') && $defaultStrategy = $env->getExtension('\Twig\Extension\EscaperExtension')->getDefaultStrategy($node->getTemplateName())) { $this->defaultStrategy = $defaultStrategy; } $this->safeVars = []; $this->blocks = []; - } elseif ($node instanceof Twig_Node_AutoEscape) { + } elseif ($node instanceof \Twig\Node\AutoEscapeNode) { $this->statusStack[] = $node->getAttribute('value'); - } elseif ($node instanceof Twig_Node_Block) { + } elseif ($node instanceof \Twig\Node\BlockNode) { $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); - } elseif ($node instanceof Twig_Node_Import) { + } elseif ($node instanceof \Twig\Node\ImportNode) { $this->safeVars[] = $node->getNode('var')->getAttribute('name'); } return $node; } - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) + protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Module) { + if ($node instanceof \Twig\Node\ModuleNode) { $this->defaultStrategy = false; $this->safeVars = []; $this->blocks = []; - } elseif ($node instanceof Twig_Node_Expression_Filter) { + } elseif ($node instanceof \Twig\Node\Expression\FilterExpression) { return $this->preEscapeFilterNode($node, $env); - } elseif ($node instanceof Twig_Node_Print) { + } elseif ($node instanceof \Twig\Node\PrintNode) { return $this->escapePrintNode($node, $env, $this->needEscaping($env)); } - if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) { + if ($node instanceof \Twig\Node\AutoEscapeNode || $node instanceof \Twig\Node\BlockNode) { array_pop($this->statusStack); - } elseif ($node instanceof Twig_Node_BlockReference) { + } elseif ($node instanceof \Twig\Node\BlockReferenceNode) { $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env); } return $node; } - protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type) + protected function escapePrintNode(\Twig\Node\PrintNode $node, \Twig\Environment $env, $type) { if (false === $type) { return $node; @@ -90,7 +90,7 @@ protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, ); } - protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env) + protected function preEscapeFilterNode(\Twig\Node\Expression\FilterExpression $filter, \Twig\Environment $env) { $name = $filter->getNode('filter')->getAttribute('value'); @@ -115,7 +115,7 @@ protected function isSafeFor($type, Twig_NodeInterface $expression, $env) if (null === $safe) { if (null === $this->traverser) { - $this->traverser = new Twig_NodeTraverser($env, [$this->safeAnalysis]); + $this->traverser = new \Twig\NodeTraverser($env, [$this->safeAnalysis]); } $this->safeAnalysis->setSafeVars($this->safeVars); @@ -127,7 +127,7 @@ protected function isSafeFor($type, Twig_NodeInterface $expression, $env) return \in_array($type, $safe) || \in_array('all', $safe); } - protected function needEscaping(Twig_Environment $env) + protected function needEscaping(\Twig\Environment $env) { if (\count($this->statusStack)) { return $this->statusStack[\count($this->statusStack) - 1]; @@ -139,10 +139,10 @@ protected function needEscaping(Twig_Environment $env) protected function getEscaperFilter($type, Twig_NodeInterface $node) { $line = $node->getTemplateLine(); - $name = new Twig_Node_Expression_Constant('escape', $line); - $args = new Twig_Node([new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)]); + $name = new \Twig\Node\Expression\ConstantExpression('escape', $line); + $args = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression((string) $type, $line), new \Twig\Node\Expression\ConstantExpression(null, $line), new \Twig\Node\Expression\ConstantExpression(true, $line)]); - return new Twig_Node_Expression_Filter($node, $name, $args, $line); + return new \Twig\Node\Expression\FilterExpression($node, $name, $args, $line); } public function getPriority() diff --git a/lib/Twig/NodeVisitor/Optimizer.php b/lib/Twig/NodeVisitor/Optimizer.php index 1950a5a6fa..a25ef90257 100644 --- a/lib/Twig/NodeVisitor/Optimizer.php +++ b/lib/Twig/NodeVisitor/Optimizer.php @@ -21,7 +21,7 @@ * * @author Fabien Potencier */ -class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor +class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor { const OPTIMIZE_ALL = -1; const OPTIMIZE_NONE = 0; @@ -47,22 +47,22 @@ public function __construct($optimizers = -1) $this->optimizers = $optimizers; } - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) + protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) { if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { $this->enterOptimizeFor($node, $env); } - if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('Twig_Extension_Sandbox')) { + if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('\Twig\Extension\SandboxExtension')) { if ($this->inABody) { - if (!$node instanceof Twig_Node_Expression) { + if (!$node instanceof \Twig\Node\Expression\AbstractExpression) { if ('Twig_Node' !== \get_class($node)) { array_unshift($this->prependedNodes, []); } } else { $node = $this->optimizeVariables($node, $env); } - } elseif ($node instanceof Twig_Node_Body) { + } elseif ($node instanceof \Twig\Node\BodyNode) { $this->inABody = true; } } @@ -70,9 +70,9 @@ protected function doEnterNode(Twig_Node $node, Twig_Environment $env) return $node; } - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) + protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) { - $expression = $node instanceof Twig_Node_Expression; + $expression = $node instanceof \Twig\Node\Expression\AbstractExpression; if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { $this->leaveOptimizeFor($node, $env); @@ -84,18 +84,18 @@ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) $node = $this->optimizePrintNode($node, $env); - if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('Twig_Extension_Sandbox')) { - if ($node instanceof Twig_Node_Body) { + if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('\Twig\Extension\SandboxExtension')) { + if ($node instanceof \Twig\Node\BodyNode) { $this->inABody = false; } elseif ($this->inABody) { if (!$expression && 'Twig_Node' !== \get_class($node) && $prependedNodes = array_shift($this->prependedNodes)) { $nodes = []; foreach (array_unique($prependedNodes) as $name) { - $nodes[] = new Twig_Node_SetTemp($name, $node->getTemplateLine()); + $nodes[] = new \Twig\Node\SetTempNode($name, $node->getTemplateLine()); } $nodes[] = $node; - $node = new Twig_Node($nodes); + $node = new \Twig\Node\Node($nodes); } } } @@ -103,12 +103,12 @@ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) return $node; } - protected function optimizeVariables(Twig_NodeInterface $node, Twig_Environment $env) + protected function optimizeVariables(Twig_NodeInterface $node, \Twig\Environment $env) { if ('Twig_Node_Expression_Name' === \get_class($node) && $node->isSimple()) { $this->prependedNodes[0][] = $node->getAttribute('name'); - return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getTemplateLine()); + return new \Twig\Node\Expression\TempNameExpression($node->getAttribute('name'), $node->getTemplateLine()); } return $node; @@ -123,16 +123,16 @@ protected function optimizeVariables(Twig_NodeInterface $node, Twig_Environment * * @return Twig_NodeInterface */ - protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env) + protected function optimizePrintNode(Twig_NodeInterface $node, \Twig\Environment $env) { - if (!$node instanceof Twig_Node_Print) { + if (!$node instanceof \Twig\Node\PrintNode) { return $node; } $exprNode = $node->getNode('expr'); if ( - $exprNode instanceof Twig_Node_Expression_BlockReference || - $exprNode instanceof Twig_Node_Expression_Parent + $exprNode instanceof \Twig\Node\Expression\BlockReferenceExpression || + $exprNode instanceof \Twig\Node\Expression\ParentExpression ) { $exprNode->setAttribute('output', true); @@ -147,9 +147,9 @@ protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment * * @return Twig_NodeInterface */ - protected function optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment $env) + protected function optimizeRawFilter(Twig_NodeInterface $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Expression_Filter && 'raw' == $node->getNode('filter')->getAttribute('value')) { + if ($node instanceof \Twig\Node\Expression\FilterExpression && 'raw' == $node->getNode('filter')->getAttribute('value')) { return $node->getNode('node'); } @@ -159,9 +159,9 @@ protected function optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment /** * Optimizes "for" tag by removing the "loop" variable creation whenever possible. */ - protected function enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env) + protected function enterOptimizeFor(Twig_NodeInterface $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_For) { + if ($node instanceof \Twig\Node\ForNode) { // disable the loop variable by default $node->setAttribute('with_loop', false); array_unshift($this->loops, $node); @@ -175,28 +175,28 @@ protected function enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $ // when do we need to add the loop variable back? // the loop variable is referenced for the current loop - elseif ($node instanceof Twig_Node_Expression_Name && 'loop' === $node->getAttribute('name')) { + elseif ($node instanceof \Twig\Node\Expression\NameExpression && 'loop' === $node->getAttribute('name')) { $node->setAttribute('always_defined', true); $this->addLoopToCurrent(); } // optimize access to loop targets - elseif ($node instanceof Twig_Node_Expression_Name && \in_array($node->getAttribute('name'), $this->loopsTargets)) { + elseif ($node instanceof \Twig\Node\Expression\NameExpression && \in_array($node->getAttribute('name'), $this->loopsTargets)) { $node->setAttribute('always_defined', true); } // block reference - elseif ($node instanceof Twig_Node_BlockReference || $node instanceof Twig_Node_Expression_BlockReference) { + elseif ($node instanceof \Twig\Node\BlockReferenceNode || $node instanceof \Twig\Node\Expression\BlockReferenceExpression) { $this->addLoopToCurrent(); } // include without the only attribute - elseif ($node instanceof Twig_Node_Include && !$node->getAttribute('only')) { + elseif ($node instanceof \Twig\Node\IncludeNode && !$node->getAttribute('only')) { $this->addLoopToAll(); } // include function without the with_context=false parameter - elseif ($node instanceof Twig_Node_Expression_Function + elseif ($node instanceof \Twig\Node\Expression\FunctionExpression && 'include' === $node->getAttribute('name') && (!$node->getNode('arguments')->hasNode('with_context') || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value') @@ -206,12 +206,12 @@ protected function enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $ } // the loop variable is referenced via an attribute - elseif ($node instanceof Twig_Node_Expression_GetAttr - && (!$node->getNode('attribute') instanceof Twig_Node_Expression_Constant + elseif ($node instanceof \Twig\Node\Expression\GetAttrExpression + && (!$node->getNode('attribute') instanceof \Twig\Node\Expression\ConstantExpression || 'parent' === $node->getNode('attribute')->getAttribute('value') ) && (true === $this->loops[0]->getAttribute('with_loop') - || ($node->getNode('node') instanceof Twig_Node_Expression_Name + || ($node->getNode('node') instanceof \Twig\Node\Expression\NameExpression && 'loop' === $node->getNode('node')->getAttribute('name') ) ) @@ -223,9 +223,9 @@ protected function enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $ /** * Optimizes "for" tag by removing the "loop" variable creation whenever possible. */ - protected function leaveOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env) + protected function leaveOptimizeFor(Twig_NodeInterface $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_For) { + if ($node instanceof \Twig\Node\ForNode) { array_shift($this->loops); array_shift($this->loopsTargets); array_shift($this->loopsTargets); diff --git a/lib/Twig/NodeVisitor/SafeAnalysis.php b/lib/Twig/NodeVisitor/SafeAnalysis.php index da77c2140c..442c16f87e 100644 --- a/lib/Twig/NodeVisitor/SafeAnalysis.php +++ b/lib/Twig/NodeVisitor/SafeAnalysis.php @@ -12,7 +12,7 @@ /** * @final */ -class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor +class Twig_NodeVisitor_SafeAnalysis extends \Twig\NodeVisitor\AbstractNodeVisitor { protected $data = []; protected $safeVars = []; @@ -60,27 +60,27 @@ protected function setSafe(Twig_NodeInterface $node, array $safe) ]; } - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) + protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) { return $node; } - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) + protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Expression_Constant) { + if ($node instanceof \Twig\Node\Expression\ConstantExpression) { // constants are marked safe for all $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_BlockReference) { + } elseif ($node instanceof \Twig\Node\Expression\BlockReferenceExpression) { // blocks are safe by definition $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_Parent) { + } elseif ($node instanceof \Twig\Node\Expression\ParentExpression) { // parent block is safe by definition $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_Conditional) { + } elseif ($node instanceof \Twig\Node\Expression\ConditionalExpression) { // intersect safeness of both operands $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3'))); $this->setSafe($node, $safe); - } elseif ($node instanceof Twig_Node_Expression_Filter) { + } elseif ($node instanceof \Twig\Node\Expression\FilterExpression) { // filter expression is safe when the filter is safe $name = $node->getNode('filter')->getAttribute('value'); $args = $node->getNode('arguments'); @@ -93,7 +93,7 @@ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) } else { $this->setSafe($node, []); } - } elseif ($node instanceof Twig_Node_Expression_Function) { + } elseif ($node instanceof \Twig\Node\Expression\FunctionExpression) { // function expression is safe when the function is safe $name = $node->getAttribute('name'); $args = $node->getNode('arguments'); @@ -103,13 +103,13 @@ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) } else { $this->setSafe($node, []); } - } elseif ($node instanceof Twig_Node_Expression_MethodCall) { + } elseif ($node instanceof \Twig\Node\Expression\MethodCallExpression) { if ($node->getAttribute('safe')) { $this->setSafe($node, ['all']); } else { $this->setSafe($node, []); } - } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) { + } elseif ($node instanceof \Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \Twig\Node\Expression\NameExpression) { $name = $node->getNode('node')->getAttribute('name'); // attributes on template instances are safe if ('_self' == $name || \in_array($name, $this->safeVars)) { diff --git a/lib/Twig/NodeVisitor/Sandbox.php b/lib/Twig/NodeVisitor/Sandbox.php index 894cc1a074..193f735649 100644 --- a/lib/Twig/NodeVisitor/Sandbox.php +++ b/lib/Twig/NodeVisitor/Sandbox.php @@ -16,16 +16,16 @@ * * @author Fabien Potencier */ -class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor +class Twig_NodeVisitor_Sandbox extends \Twig\NodeVisitor\AbstractNodeVisitor { protected $inAModule = false; protected $tags; protected $filters; protected $functions; - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) + protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Module) { + if ($node instanceof \Twig\Node\ModuleNode) { $this->inAModule = true; $this->tags = []; $this->filters = []; @@ -39,35 +39,35 @@ protected function doEnterNode(Twig_Node $node, Twig_Environment $env) } // look for filters - if ($node instanceof Twig_Node_Expression_Filter && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { + if ($node instanceof \Twig\Node\Expression\FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; } // look for functions - if ($node instanceof Twig_Node_Expression_Function && !isset($this->functions[$node->getAttribute('name')])) { + if ($node instanceof \Twig\Node\Expression\FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) { $this->functions[$node->getAttribute('name')] = $node; } // the .. operator is equivalent to the range() function - if ($node instanceof Twig_Node_Expression_Binary_Range && !isset($this->functions['range'])) { + if ($node instanceof \Twig\Node\Expression\Binary\RangeBinary && !isset($this->functions['range'])) { $this->functions['range'] = $node; } // wrap print to check __toString() calls - if ($node instanceof Twig_Node_Print) { - return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag()); + if ($node instanceof \Twig\Node\PrintNode) { + return new \Twig\Node\SandboxedPrintNode($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag()); } } return $node; } - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) + protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Module) { + if ($node instanceof \Twig\Node\ModuleNode) { $this->inAModule = false; - $node->setNode('display_start', new Twig_Node([new Twig_Node_CheckSecurity($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); + $node->setNode('display_start', new \Twig\Node\Node([new \Twig\Node\CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); } return $node; diff --git a/lib/Twig/NodeVisitorInterface.php b/lib/Twig/NodeVisitorInterface.php index 1270a37243..00f8afaf65 100644 --- a/lib/Twig/NodeVisitorInterface.php +++ b/lib/Twig/NodeVisitorInterface.php @@ -21,14 +21,14 @@ interface Twig_NodeVisitorInterface * * @return Twig_NodeInterface The modified node */ - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env); + public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env); /** * Called after child nodes are visited. * * @return Twig_NodeInterface|false The modified node or false if the node must be removed */ - public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env); + public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env); /** * Returns the priority for this visitor. diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 4aabcab04e..1eaf49fcea 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -33,7 +33,7 @@ class Twig_Parser implements Twig_ParserInterface protected $embeddedTemplates = []; private $varNameSalt = 0; - public function __construct(Twig_Environment $env) + public function __construct(\Twig\Environment $env) { $this->env = $env; } @@ -63,7 +63,7 @@ public function getFilename() return $this->stream->getSourceContext()->getName(); } - public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false) + public function parse(\Twig\TokenStream $stream, $test = null, $dropNeedle = false) { // push all variables into the stack to keep the current state of the parser // using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336 @@ -88,7 +88,7 @@ public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = fals } if (null === $this->expressionParser) { - $this->expressionParser = new Twig_ExpressionParser($this, $this->env); + $this->expressionParser = new \Twig\ExpressionParser($this, $this->env); } $this->stream = $stream; @@ -105,9 +105,9 @@ public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = fals $body = $this->subparse($test, $dropNeedle); if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) { - $body = new Twig_Node(); + $body = new \Twig\Node\Node(); } - } catch (Twig_Error_Syntax $e) { + } catch (\Twig\Error\SyntaxError $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->stream->getSourceContext()); } @@ -119,9 +119,9 @@ public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = fals throw $e; } - $node = new Twig_Node_Module(new Twig_Node_Body([$body]), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); + $node = new \Twig\Node\ModuleNode(new \Twig\Node\BodyNode([$body]), $this->parent, new \Twig\Node\Node($this->blocks), new \Twig\Node\Node($this->macros), new \Twig\Node\Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); - $traverser = new Twig_NodeTraverser($this->env, $this->visitors); + $traverser = new \Twig\NodeTraverser($this->env, $this->visitors); $node = $traverser->traverse($node); @@ -139,24 +139,24 @@ public function subparse($test, $dropNeedle = false) $rv = []; while (!$this->stream->isEOF()) { switch ($this->getCurrentToken()->getType()) { - case Twig_Token::TEXT_TYPE: + case \Twig\Token::TEXT_TYPE: $token = $this->stream->next(); - $rv[] = new Twig_Node_Text($token->getValue(), $token->getLine()); + $rv[] = new \Twig\Node\TextNode($token->getValue(), $token->getLine()); break; - case Twig_Token::VAR_START_TYPE: + case \Twig\Token::VAR_START_TYPE: $token = $this->stream->next(); $expr = $this->expressionParser->parseExpression(); - $this->stream->expect(Twig_Token::VAR_END_TYPE); - $rv[] = new Twig_Node_Print($expr, $token->getLine()); + $this->stream->expect(\Twig\Token::VAR_END_TYPE); + $rv[] = new \Twig\Node\PrintNode($expr, $token->getLine()); break; - case Twig_Token::BLOCK_START_TYPE: + case \Twig\Token::BLOCK_START_TYPE: $this->stream->next(); $token = $this->getCurrentToken(); - if (Twig_Token::NAME_TYPE !== $token->getType()) { - throw new Twig_Error_Syntax('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); + if (\Twig\Token::NAME_TYPE !== $token->getType()) { + throw new \Twig\Error\SyntaxError('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); } if (null !== $test && \call_user_func($test, $token)) { @@ -168,19 +168,19 @@ public function subparse($test, $dropNeedle = false) return $rv[0]; } - return new Twig_Node($rv, [], $lineno); + return new \Twig\Node\Node($rv, [], $lineno); } $subparser = $this->handlers->getTokenParser($token->getValue()); if (null === $subparser) { if (null !== $test) { - $e = new Twig_Error_Syntax(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + $e = new \Twig\Error\SyntaxError(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); - if (\is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { + if (\is_array($test) && isset($test[0]) && $test[0] instanceof \Twig\TokenParser\TokenParserInterface) { $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno)); } } else { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); $e->addSuggestions($token->getValue(), array_keys($this->env->getTags())); } @@ -196,7 +196,7 @@ public function subparse($test, $dropNeedle = false) break; default: - throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); + throw new \Twig\Error\SyntaxError('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); } } @@ -204,7 +204,7 @@ public function subparse($test, $dropNeedle = false) return $rv[0]; } - return new Twig_Node($rv, [], $lineno); + return new \Twig\Node\Node($rv, [], $lineno); } /** @@ -220,7 +220,7 @@ public function addHandler($name, $class) /** * @deprecated since 1.27 (to be removed in 2.0) */ - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) + public function addNodeVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor) { @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); @@ -257,9 +257,9 @@ public function getBlock($name) return $this->blocks[$name]; } - public function setBlock($name, Twig_Node_Block $value) + public function setBlock($name, \Twig\Node\BlockNode $value) { - $this->blocks[$name] = new Twig_Node_Body([$value], [], $value->getTemplateLine()); + $this->blocks[$name] = new \Twig\Node\BodyNode([$value], [], $value->getTemplateLine()); } public function hasMacro($name) @@ -267,10 +267,10 @@ public function hasMacro($name) return isset($this->macros[$name]); } - public function setMacro($name, Twig_Node_Macro $node) + public function setMacro($name, \Twig\Node\MacroNode $node) { if ($this->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext()); } $this->macros[$name] = $node; @@ -303,14 +303,14 @@ public function hasTraits() return \count($this->traits) > 0; } - public function embedTemplate(Twig_Node_Module $template) + public function embedTemplate(\Twig\Node\ModuleNode $template) { $template->setIndex(mt_rand()); $this->embeddedTemplates[] = $template; } - public function addImportedSymbol($type, $alias, $name = null, Twig_Node_Expression $node = null) + public function addImportedSymbol($type, $alias, $name = null, \Twig\Node\Expression\AbstractExpression $node = null) { $this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node]; } @@ -340,7 +340,7 @@ public function popLocalScope() } /** - * @return Twig_ExpressionParser + * @return \Twig\ExpressionParser */ public function getExpressionParser() { @@ -358,7 +358,7 @@ public function setParent($parent) } /** - * @return Twig_TokenStream + * @return \Twig\TokenStream */ public function getStream() { @@ -366,7 +366,7 @@ public function getStream() } /** - * @return Twig_Token + * @return \Twig\Token */ public function getCurrentToken() { @@ -377,9 +377,9 @@ protected function filterBodyNodes(Twig_NodeInterface $node) { // check that the body does not contain non-empty output nodes if ( - ($node instanceof Twig_Node_Text && !ctype_space($node->getAttribute('data'))) + ($node instanceof \Twig\Node\TextNode && !ctype_space($node->getAttribute('data'))) || - (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface) + (!$node instanceof \Twig\Node\TextNode && !$node instanceof \Twig\Node\BlockReferenceNode && $node instanceof \Twig\Node\NodeOutputInterface) ) { if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) { $t = substr($node->getAttribute('data'), 3); @@ -389,15 +389,15 @@ protected function filterBodyNodes(Twig_NodeInterface $node) } } - throw new Twig_Error_Syntax('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); + throw new \Twig\Error\SyntaxError('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); } // bypass nodes that will "capture" the output - if ($node instanceof Twig_NodeCaptureInterface) { + if ($node instanceof \Twig\Node\NodeCaptureInterface) { return $node; } - if ($node instanceof Twig_NodeOutputInterface) { + if ($node instanceof \Twig\Node\NodeOutputInterface) { return; } diff --git a/lib/Twig/ParserInterface.php b/lib/Twig/ParserInterface.php index 85c6e67b20..d628d65215 100644 --- a/lib/Twig/ParserInterface.php +++ b/lib/Twig/ParserInterface.php @@ -21,9 +21,9 @@ interface Twig_ParserInterface /** * Converts a token stream to a node tree. * - * @return Twig_Node_Module + * @return \Twig\Node\ModuleNode * - * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong + * @throws \Twig\Error\SyntaxError When the token stream is syntactically or semantically wrong */ - public function parse(Twig_TokenStream $stream); + public function parse(\Twig\TokenStream $stream); } diff --git a/lib/Twig/Profiler/Dumper/Base.php b/lib/Twig/Profiler/Dumper/Base.php index 8aeeeb7730..9ce1243230 100644 --- a/lib/Twig/Profiler/Dumper/Base.php +++ b/lib/Twig/Profiler/Dumper/Base.php @@ -16,18 +16,18 @@ abstract class Twig_Profiler_Dumper_Base { private $root; - public function dump(Twig_Profiler_Profile $profile) + public function dump(\Twig\Profiler\Profile $profile) { return $this->dumpProfile($profile); } - abstract protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix); + abstract protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix); - abstract protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix); + abstract protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix); - abstract protected function formatTime(Twig_Profiler_Profile $profile, $percent); + abstract protected function formatTime(\Twig\Profiler\Profile $profile, $percent); - private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false) + private function dumpProfile(\Twig\Profiler\Profile $profile, $prefix = '', $sibling = false) { if ($profile->isRoot()) { $this->root = $profile->getDuration(); diff --git a/lib/Twig/Profiler/Dumper/Blackfire.php b/lib/Twig/Profiler/Dumper/Blackfire.php index 4ebb0d0ff2..827a20b6dc 100644 --- a/lib/Twig/Profiler/Dumper/Blackfire.php +++ b/lib/Twig/Profiler/Dumper/Blackfire.php @@ -16,7 +16,7 @@ */ class Twig_Profiler_Dumper_Blackfire { - public function dump(Twig_Profiler_Profile $profile) + public function dump(\Twig\Profiler\Profile $profile) { $data = []; $this->dumpProfile('main()', $profile, $data); @@ -38,7 +38,7 @@ public function dump(Twig_Profiler_Profile $profile) return $str; } - private function dumpChildren($parent, Twig_Profiler_Profile $profile, &$data) + private function dumpChildren($parent, \Twig\Profiler\Profile $profile, &$data) { foreach ($profile as $p) { if ($p->isTemplate()) { @@ -51,7 +51,7 @@ private function dumpChildren($parent, Twig_Profiler_Profile $profile, &$data) } } - private function dumpProfile($edge, Twig_Profiler_Profile $profile, &$data) + private function dumpProfile($edge, \Twig\Profiler\Profile $profile, &$data) { if (isset($data[$edge])) { ++$data[$edge]['ct']; diff --git a/lib/Twig/Profiler/Dumper/Html.php b/lib/Twig/Profiler/Dumper/Html.php index 974b521687..b9ddd586b7 100644 --- a/lib/Twig/Profiler/Dumper/Html.php +++ b/lib/Twig/Profiler/Dumper/Html.php @@ -14,7 +14,7 @@ * * @final */ -class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Base +class Twig_Profiler_Dumper_Html extends \Twig\Profiler\Dumper\BaseDumper { private static $colors = [ 'block' => '#dfd', @@ -23,22 +23,22 @@ class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Base 'big' => '#d44', ]; - public function dump(Twig_Profiler_Profile $profile) + public function dump(\Twig\Profiler\Profile $profile) { return '
'.parent::dump($profile).'
'; } - protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix) + protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix) { return sprintf('%s└ %s', $prefix, self::$colors['template'], $profile->getTemplate()); } - protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix) + protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix) { return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName()); } - protected function formatTime(Twig_Profiler_Profile $profile, $percent) + protected function formatTime(\Twig\Profiler\Profile $profile, $percent) { return sprintf('%.2fms/%.0f%%', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent); } diff --git a/lib/Twig/Profiler/Dumper/Text.php b/lib/Twig/Profiler/Dumper/Text.php index 69d2c4bf34..abc961b784 100644 --- a/lib/Twig/Profiler/Dumper/Text.php +++ b/lib/Twig/Profiler/Dumper/Text.php @@ -14,19 +14,19 @@ * * @final */ -class Twig_Profiler_Dumper_Text extends Twig_Profiler_Dumper_Base +class Twig_Profiler_Dumper_Text extends \Twig\Profiler\Dumper\BaseDumper { - protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix) + protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix) { return sprintf('%s└ %s', $prefix, $profile->getTemplate()); } - protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix) + protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix) { return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName()); } - protected function formatTime(Twig_Profiler_Profile $profile, $percent) + protected function formatTime(\Twig\Profiler\Profile $profile, $percent) { return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent); } diff --git a/lib/Twig/Profiler/Node/EnterProfile.php b/lib/Twig/Profiler/Node/EnterProfile.php index b29ec9b7fa..3144c03c7f 100644 --- a/lib/Twig/Profiler/Node/EnterProfile.php +++ b/lib/Twig/Profiler/Node/EnterProfile.php @@ -14,20 +14,20 @@ * * @author Fabien Potencier */ -class Twig_Profiler_Node_EnterProfile extends Twig_Node +class Twig_Profiler_Node_EnterProfile extends \Twig\Node\Node { public function __construct($extensionName, $type, $name, $varName) { parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name'))) ->repr($this->getAttribute('extension_name')) ->raw(");\n") - ->write(sprintf('$%s->enter($%s = new Twig_Profiler_Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) + ->write(sprintf('$%s->enter($%s = new \Twig\Profiler\Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) ->repr($this->getAttribute('type')) ->raw(', ') ->repr($this->getAttribute('name')) diff --git a/lib/Twig/Profiler/Node/LeaveProfile.php b/lib/Twig/Profiler/Node/LeaveProfile.php index bcb912dd8b..cfc0d25975 100644 --- a/lib/Twig/Profiler/Node/LeaveProfile.php +++ b/lib/Twig/Profiler/Node/LeaveProfile.php @@ -14,14 +14,14 @@ * * @author Fabien Potencier */ -class Twig_Profiler_Node_LeaveProfile extends Twig_Node +class Twig_Profiler_Node_LeaveProfile extends \Twig\Node\Node { public function __construct($varName) { parent::__construct([], ['var_name' => $varName]); } - public function compile(Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $compiler ->write("\n") diff --git a/lib/Twig/Profiler/NodeVisitor/Profiler.php b/lib/Twig/Profiler/NodeVisitor/Profiler.php index 6cf5bb0e5a..40d46532d4 100644 --- a/lib/Twig/Profiler/NodeVisitor/Profiler.php +++ b/lib/Twig/Profiler/NodeVisitor/Profiler.php @@ -14,7 +14,7 @@ * * @final */ -class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor +class Twig_Profiler_NodeVisitor_Profiler extends \Twig\NodeVisitor\AbstractNodeVisitor { private $extensionName; @@ -23,30 +23,30 @@ public function __construct($extensionName) $this->extensionName = $extensionName; } - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) + protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) { return $node; } - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) + protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Module) { + if ($node instanceof \Twig\Node\ModuleNode) { $varName = $this->getVarName(); - $node->setNode('display_start', new Twig_Node([new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); - $node->setNode('display_end', new Twig_Node([new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end')])); - } elseif ($node instanceof Twig_Node_Block) { + $node->setNode('display_start', new \Twig\Node\Node([new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); + $node->setNode('display_end', new \Twig\Node\Node([new \Twig\Profiler\Node\LeaveProfileNode($varName), $node->getNode('display_end')])); + } elseif ($node instanceof \Twig\Node\BlockNode) { $varName = $this->getVarName(); - $node->setNode('body', new Twig_Node_Body([ - new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName), + $node->setNode('body', new \Twig\Node\BodyNode([ + new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::BLOCK, $node->getAttribute('name'), $varName), $node->getNode('body'), - new Twig_Profiler_Node_LeaveProfile($varName), + new \Twig\Profiler\Node\LeaveProfileNode($varName), ])); - } elseif ($node instanceof Twig_Node_Macro) { + } elseif ($node instanceof \Twig\Node\MacroNode) { $varName = $this->getVarName(); - $node->setNode('body', new Twig_Node_Body([ - new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node->getAttribute('name'), $varName), + $node->setNode('body', new \Twig\Node\BodyNode([ + new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::MACRO, $node->getAttribute('name'), $varName), $node->getNode('body'), - new Twig_Profiler_Node_LeaveProfile($varName), + new \Twig\Profiler\Node\LeaveProfileNode($varName), ])); } diff --git a/lib/Twig/Sandbox/SecurityError.php b/lib/Twig/Sandbox/SecurityError.php index b6707e3861..bb18c8f03a 100644 --- a/lib/Twig/Sandbox/SecurityError.php +++ b/lib/Twig/Sandbox/SecurityError.php @@ -14,7 +14,7 @@ * * @author Fabien Potencier */ -class Twig_Sandbox_SecurityError extends Twig_Error +class Twig_Sandbox_SecurityError extends \Twig\Error\Error { } diff --git a/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php b/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php index 6ee3c66eea..4d254d36aa 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php @@ -14,7 +14,7 @@ * * @author Martin Hasoň */ -class Twig_Sandbox_SecurityNotAllowedFilterError extends Twig_Sandbox_SecurityError +class Twig_Sandbox_SecurityNotAllowedFilterError extends \Twig\Sandbox\SecurityError { private $filterName; diff --git a/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php b/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php index 63159d15a7..8624cca53d 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php @@ -14,7 +14,7 @@ * * @author Martin Hasoň */ -class Twig_Sandbox_SecurityNotAllowedFunctionError extends Twig_Sandbox_SecurityError +class Twig_Sandbox_SecurityNotAllowedFunctionError extends \Twig\Sandbox\SecurityError { private $functionName; diff --git a/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php b/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php index 277522213a..3d49be38ae 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php @@ -14,7 +14,7 @@ * * @author Kit Burton-Senior */ -class Twig_Sandbox_SecurityNotAllowedMethodError extends Twig_Sandbox_SecurityError +class Twig_Sandbox_SecurityNotAllowedMethodError extends \Twig\Sandbox\SecurityError { private $className; private $methodName; diff --git a/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php b/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php index c9477e8e20..ae304833b6 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php @@ -14,7 +14,7 @@ * * @author Kit Burton-Senior */ -class Twig_Sandbox_SecurityNotAllowedPropertyError extends Twig_Sandbox_SecurityError +class Twig_Sandbox_SecurityNotAllowedPropertyError extends \Twig\Sandbox\SecurityError { private $className; private $propertyName; diff --git a/lib/Twig/Sandbox/SecurityNotAllowedTagError.php b/lib/Twig/Sandbox/SecurityNotAllowedTagError.php index 2fd1406285..c5bc54da3c 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedTagError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedTagError.php @@ -14,7 +14,7 @@ * * @author Martin Hasoň */ -class Twig_Sandbox_SecurityNotAllowedTagError extends Twig_Sandbox_SecurityError +class Twig_Sandbox_SecurityNotAllowedTagError extends \Twig\Sandbox\SecurityError { private $tagName; diff --git a/lib/Twig/Sandbox/SecurityPolicy.php b/lib/Twig/Sandbox/SecurityPolicy.php index cd24635da7..8b9465bb59 100644 --- a/lib/Twig/Sandbox/SecurityPolicy.php +++ b/lib/Twig/Sandbox/SecurityPolicy.php @@ -16,7 +16,7 @@ * * @author Fabien Potencier */ -class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterface +class Twig_Sandbox_SecurityPolicy implements \Twig\Sandbox\SecurityPolicyInterface { protected $allowedTags; protected $allowedFilters; @@ -65,26 +65,26 @@ public function checkSecurity($tags, $filters, $functions) { foreach ($tags as $tag) { if (!\in_array($tag, $this->allowedTags)) { - throw new Twig_Sandbox_SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); + throw new \Twig\Sandbox\SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); } } foreach ($filters as $filter) { if (!\in_array($filter, $this->allowedFilters)) { - throw new Twig_Sandbox_SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); + throw new \Twig\Sandbox\SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); } } foreach ($functions as $function) { if (!\in_array($function, $this->allowedFunctions)) { - throw new Twig_Sandbox_SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); + throw new \Twig\Sandbox\SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); } } } public function checkMethodAllowed($obj, $method) { - if ($obj instanceof Twig_TemplateInterface || $obj instanceof Twig_Markup) { + if ($obj instanceof Twig_TemplateInterface || $obj instanceof \Twig\Markup) { return true; } @@ -100,7 +100,7 @@ public function checkMethodAllowed($obj, $method) if (!$allowed) { $class = \get_class($obj); - throw new Twig_Sandbox_SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); + throw new \Twig\Sandbox\SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); } } @@ -117,7 +117,7 @@ public function checkPropertyAllowed($obj, $property) if (!$allowed) { $class = \get_class($obj); - throw new Twig_Sandbox_SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); + throw new \Twig\Sandbox\SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); } } } diff --git a/lib/Twig/SimpleFilter.php b/lib/Twig/SimpleFilter.php index a7787d77f3..f94f9469e6 100644 --- a/lib/Twig/SimpleFilter.php +++ b/lib/Twig/SimpleFilter.php @@ -35,7 +35,7 @@ public function __construct($name, $callable, array $options = []) 'is_safe_callback' => null, 'pre_escape' => null, 'preserves_safety' => null, - 'node_class' => 'Twig_Node_Expression_Filter', + 'node_class' => '\Twig\Node\Expression\FilterExpression', 'deprecated' => false, 'alternative' => null, ], $options); @@ -76,7 +76,7 @@ public function needsContext() return $this->options['needs_context']; } - public function getSafe(Twig_Node $filterArgs) + public function getSafe(\Twig\Node\Node $filterArgs) { if (null !== $this->options['is_safe']) { return $this->options['is_safe']; diff --git a/lib/Twig/SimpleFunction.php b/lib/Twig/SimpleFunction.php index 35699e0615..5920026090 100644 --- a/lib/Twig/SimpleFunction.php +++ b/lib/Twig/SimpleFunction.php @@ -33,7 +33,7 @@ public function __construct($name, $callable, array $options = []) 'is_variadic' => false, 'is_safe' => null, 'is_safe_callback' => null, - 'node_class' => 'Twig_Node_Expression_Function', + 'node_class' => '\Twig\Node\Expression\FunctionExpression', 'deprecated' => false, 'alternative' => null, ], $options); @@ -74,7 +74,7 @@ public function needsContext() return $this->options['needs_context']; } - public function getSafe(Twig_Node $functionArgs) + public function getSafe(\Twig\Node\Node $functionArgs) { if (null !== $this->options['is_safe']) { return $this->options['is_safe']; diff --git a/lib/Twig/SimpleTest.php b/lib/Twig/SimpleTest.php index 393fad1e0c..2da43b6218 100644 --- a/lib/Twig/SimpleTest.php +++ b/lib/Twig/SimpleTest.php @@ -30,7 +30,7 @@ public function __construct($name, $callable, array $options = []) $this->callable = $callable; $this->options = array_merge([ 'is_variadic' => false, - 'node_class' => 'Twig_Node_Expression_Test', + 'node_class' => '\Twig\Node\Expression\TestExpression', 'deprecated' => false, 'alternative' => null, ], $options); diff --git a/lib/Twig/SourceContextLoaderInterface.php b/lib/Twig/SourceContextLoaderInterface.php index a6e8c42550..c0b2b156e8 100644 --- a/lib/Twig/SourceContextLoaderInterface.php +++ b/lib/Twig/SourceContextLoaderInterface.php @@ -23,9 +23,9 @@ interface Twig_SourceContextLoaderInterface * * @param string $name The template logical name * - * @return Twig_Source + * @return \Twig\Source * - * @throws Twig_Error_Loader When $name is not found + * @throws \Twig\Error\LoaderError When $name is not found */ public function getSourceContext($name); } diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 1968767477..810536a107 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -34,7 +34,7 @@ abstract class Twig_Template implements Twig_TemplateInterface protected $blocks = []; protected $traits = []; - public function __construct(Twig_Environment $env) + public function __construct(\Twig\Environment $env) { $this->env = $env; } @@ -83,11 +83,11 @@ public function getSource() /** * Returns information about the original template source code. * - * @return Twig_Source + * @return \Twig\Source */ public function getSourceContext() { - return new Twig_Source('', $this->getTemplateName()); + return new \Twig\Source('', $this->getTemplateName()); } /** @@ -108,7 +108,7 @@ public function getEnvironment() * * @param array $context * - * @return Twig_TemplateInterface|Twig_TemplateWrapper|false The parent template or false if there is no parent + * @return Twig_TemplateInterface|\Twig\TemplateWrapper|false The parent template or false if there is no parent * * @internal */ @@ -125,14 +125,14 @@ public function getParent(array $context) return false; } - if ($parent instanceof self || $parent instanceof Twig_TemplateWrapper) { + if ($parent instanceof self || $parent instanceof \Twig\TemplateWrapper) { return $this->parents[$parent->getSourceContext()->getName()] = $parent; } if (!isset($this->parents[$parent])) { $this->parents[$parent] = $this->loadTemplate($parent); } - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { $e->setSourceContext(null); $e->guess(); @@ -173,7 +173,7 @@ public function displayParentBlock($name, array $context, array $blocks = []) } elseif (false !== $parent = $this->getParent($context)) { $parent->displayBlock($name, $context, $blocks, false); } else { - throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); + throw new \Twig\Error\RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); } } @@ -213,7 +213,7 @@ public function displayBlock($name, array $context, array $blocks = [], $useBloc if (null !== $template) { try { $template->$block($context, $blocks); - } catch (Twig_Error $e) { + } catch (\Twig\Error\Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($template->getSourceContext()); } @@ -227,7 +227,7 @@ public function displayBlock($name, array $context, array $blocks = [], $useBloc throw $e; } catch (\Exception $e) { - throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); + throw new \Twig\Error\RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); } } elseif (false !== $parent = $this->getParent($context)) { $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); @@ -355,14 +355,14 @@ protected function loadTemplate($template, $templateName = null, $line = null, $ return $this->env->resolveTemplate($template); } - if ($template instanceof self || $template instanceof Twig_TemplateWrapper) { + if ($template instanceof self || $template instanceof \Twig\TemplateWrapper) { return $template; } return $this->env->loadTemplate($template, $index); - } catch (Twig_Error $e) { + } catch (\Twig\Error\Error $e) { if (!$e->getSourceContext()) { - $e->setSourceContext($templateName ? new Twig_Source('', $templateName) : $this->getSourceContext()); + $e->setSourceContext($templateName ? new \Twig\Source('', $templateName) : $this->getSourceContext()); } if ($e->getTemplateLine()) { @@ -426,7 +426,7 @@ protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); - } catch (Twig_Error $e) { + } catch (\Twig\Error\Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } @@ -440,7 +440,7 @@ protected function displayWithErrorHandling(array $context, array $blocks = []) throw $e; } catch (\Exception $e) { - throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); + throw new \Twig\Error\RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); } } @@ -469,7 +469,7 @@ abstract protected function doDisplay(array $context, array $blocks = []); * * @return mixed The content of the context variable * - * @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode + * @throws \Twig\Error\RuntimeError if the variable does not exist and Twig is running in strict mode * * @internal */ @@ -480,7 +480,7 @@ final protected function getContext($context, $item, $ignoreStrictCheck = false) return; } - throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext()); + throw new \Twig\Error\RuntimeError(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext()); } return $context[$item]; @@ -498,7 +498,7 @@ final protected function getContext($context, $item, $ignoreStrictCheck = false) * * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true * - * @throws Twig_Error_Runtime if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false + * @throws \Twig\Error\RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false * * @internal */ @@ -549,7 +549,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); } - throw new Twig_Error_Runtime($message, -1, $this->getSourceContext()); + throw new \Twig\Error\RuntimeError($message, -1, $this->getSourceContext()); } } @@ -570,7 +570,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); } - throw new Twig_Error_Runtime($message, -1, $this->getSourceContext()); + throw new \Twig\Error\RuntimeError($message, -1, $this->getSourceContext()); } // object property @@ -580,8 +580,8 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s return true; } - if ($this->env->hasExtension('Twig_Extension_Sandbox')) { - $this->env->getExtension('Twig_Extension_Sandbox')->checkPropertyAllowed($object, $item); + if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) { + $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkPropertyAllowed($object, $item); } return $object->$item; @@ -655,15 +655,15 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s return; } - throw new Twig_Error_Runtime(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext()); + throw new \Twig\Error\RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext()); } if ($isDefinedTest) { return true; } - if ($this->env->hasExtension('Twig_Extension_Sandbox')) { - $this->env->getExtension('Twig_Extension_Sandbox')->checkMethodAllowed($object, $method); + if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) { + $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object, $method); } // Some objects throw exceptions when they have __call, and the method we try @@ -694,7 +694,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s } @trigger_error($message, E_USER_DEPRECATED); - return '' === $ret ? '' : new Twig_Markup($ret, $this->env->getCharset()); + return '' === $ret ? '' : new \Twig\Markup($ret, $this->env->getCharset()); } return $ret; diff --git a/lib/Twig/TemplateInterface.php b/lib/Twig/TemplateInterface.php index 4ab9c57014..3cbfe226f1 100644 --- a/lib/Twig/TemplateInterface.php +++ b/lib/Twig/TemplateInterface.php @@ -42,7 +42,7 @@ public function display(array $context, array $blocks = []); /** * Returns the bound environment for this template. * - * @return Twig_Environment + * @return \Twig\Environment */ public function getEnvironment(); } diff --git a/lib/Twig/TemplateWrapper.php b/lib/Twig/TemplateWrapper.php index 07ed715a30..3805fc6888 100644 --- a/lib/Twig/TemplateWrapper.php +++ b/lib/Twig/TemplateWrapper.php @@ -21,11 +21,11 @@ final class Twig_TemplateWrapper /** * This method is for internal use only and should never be called - * directly (use Twig_Environment::load() instead). + * directly (use \Twig\Environment::load() instead). * * @internal */ - public function __construct(Twig_Environment $env, Twig_Template $template) + public function __construct(\Twig\Environment $env, \Twig\Template $template) { $this->env = $env; $this->template = $template; @@ -126,7 +126,7 @@ public function displayBlock($name, $context = []) } /** - * @return Twig_Source + * @return \Twig\Source */ public function getSourceContext() { diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index a1b6efecf2..3a083734bf 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -25,7 +25,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase abstract protected function getFixturesDir(); /** - * @return Twig_RuntimeLoaderInterface[] + * @return \Twig\RuntimeLoader\RuntimeLoaderInterface[] */ protected function getRuntimeLoaders() { @@ -33,7 +33,7 @@ protected function getRuntimeLoaders() } /** - * @return Twig_ExtensionInterface[] + * @return \Twig\Extension\ExtensionInterface[] */ protected function getExtensions() { @@ -41,7 +41,7 @@ protected function getExtensions() } /** - * @return Twig_SimpleFilter[] + * @return \Twig\TwigFilter[] */ protected function getTwigFilters() { @@ -49,7 +49,7 @@ protected function getTwigFilters() } /** - * @return Twig_SimpleFunction[] + * @return \Twig\TwigFunction[] */ protected function getTwigFunctions() { @@ -57,7 +57,7 @@ protected function getTwigFunctions() } /** - * @return Twig_SimpleTest[] + * @return \Twig\TwigTest[] */ protected function getTwigTests() { @@ -142,14 +142,14 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e } } - $loader = new Twig_Loader_Array($templates); + $loader = new \Twig\Loader\ArrayLoader($templates); foreach ($outputs as $i => $match) { $config = array_merge([ 'cache' => false, 'strict_variables' => true, ], $match[2] ? eval($match[2].';') : []); - $twig = new Twig_Environment($loader, $config); + $twig = new \Twig\Environment($loader, $config); $twig->addGlobal('global', 'global'); foreach ($this->getRuntimeLoaders() as $runtimeLoader) { $twig->addRuntimeLoader($runtimeLoader); @@ -187,7 +187,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e return; } - throw new Twig_Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); + throw new \Twig\Error\Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); } try { @@ -199,7 +199,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e return; } - $e = new Twig_Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); + $e = new \Twig\Error\Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); $output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage())); } @@ -218,8 +218,8 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e foreach (array_keys($templates) as $name) { echo "Template: $name\n"; $loader = $twig->getLoader(); - if (!$loader instanceof Twig_SourceContextLoaderInterface) { - $source = new Twig_Source($loader->getSource($name), $name); + if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface) { + $source = new \Twig\Source($loader->getSource($name), $name); } else { $source = $loader->getSourceContext($name); } diff --git a/lib/Twig/Test/Method.php b/lib/Twig/Test/Method.php index 25d5dfc71f..e4124f223c 100644 --- a/lib/Twig/Test/Method.php +++ b/lib/Twig/Test/Method.php @@ -23,7 +23,7 @@ class Twig_Test_Method extends Twig_Test protected $extension; protected $method; - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = []) + public function __construct(\Twig\Extension\ExtensionInterface $extension, $method, array $options = []) { $options['callable'] = [$extension, $method]; diff --git a/lib/Twig/Test/NodeTestCase.php b/lib/Twig/Test/NodeTestCase.php index 083b3f2ead..ea0f8bb3f5 100644 --- a/lib/Twig/Test/NodeTestCase.php +++ b/lib/Twig/Test/NodeTestCase.php @@ -23,7 +23,7 @@ public function testCompile($node, $source, $environment = null, $isPattern = fa $this->assertNodeCompilation($source, $node, $environment, $isPattern); } - public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null, $isPattern = false) + public function assertNodeCompilation($source, \Twig\Node\Node $node, \Twig\Environment $environment = null, $isPattern = false) { $compiler = $this->getCompiler($environment); $compiler->compile($node); @@ -35,14 +35,14 @@ public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment } } - protected function getCompiler(Twig_Environment $environment = null) + protected function getCompiler(\Twig\Environment $environment = null) { - return new Twig_Compiler(null === $environment ? $this->getEnvironment() : $environment); + return new \Twig\Compiler(null === $environment ? $this->getEnvironment() : $environment); } protected function getEnvironment() { - return new Twig_Environment(new Twig_Loader_Array([])); + return new \Twig\Environment(new \Twig\Loader\ArrayLoader([])); } protected function getVariableGetter($name, $line = false) diff --git a/lib/Twig/Token.php b/lib/Twig/Token.php index 4faef4f56c..4bcd76b91e 100644 --- a/lib/Twig/Token.php +++ b/lib/Twig/Token.php @@ -159,7 +159,7 @@ public static function typeToString($type, $short = false) throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type)); } - return $short ? $name : 'Twig_Token::'.$name; + return $short ? $name : '\Twig\Token::'.$name; } /** diff --git a/lib/Twig/TokenParser.php b/lib/Twig/TokenParser.php index 1b4de14da5..e8fa01a25b 100644 --- a/lib/Twig/TokenParser.php +++ b/lib/Twig/TokenParser.php @@ -14,7 +14,7 @@ * * @author Fabien Potencier */ -abstract class Twig_TokenParser implements Twig_TokenParserInterface +abstract class Twig_TokenParser implements \Twig\TokenParser\TokenParserInterface { /** * @var Twig_Parser @@ -24,7 +24,7 @@ abstract class Twig_TokenParser implements Twig_TokenParserInterface /** * Sets the parser associated with this token parser. */ - public function setParser(Twig_Parser $parser) + public function setParser(\Twig\Parser $parser) { $this->parser = $parser; } diff --git a/lib/Twig/TokenParser/AutoEscape.php b/lib/Twig/TokenParser/AutoEscape.php index 7ea6ba5178..42f62d981b 100644 --- a/lib/Twig/TokenParser/AutoEscape.php +++ b/lib/Twig/TokenParser/AutoEscape.php @@ -27,19 +27,19 @@ * * @final */ -class Twig_TokenParser_AutoEscape extends Twig_TokenParser +class Twig_TokenParser_AutoEscape extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); - if ($stream->test(Twig_Token::BLOCK_END_TYPE)) { + if ($stream->test(\Twig\Token::BLOCK_END_TYPE)) { $value = 'html'; } else { $expr = $this->parser->getExpressionParser()->parseExpression(); - if (!$expr instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + if (!$expr instanceof \Twig\Node\Expression\ConstantExpression) { + throw new \Twig\Error\SyntaxError('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $value = $expr->getAttribute('value'); @@ -49,25 +49,25 @@ public function parse(Twig_Token $token) $value = 'html'; } - if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { + if ($compat && $stream->test(\Twig\Token::NAME_TYPE)) { @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED); if (false === $value) { - throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $value = $stream->next()->getValue(); } } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag()); + return new \Twig\Node\AutoEscapeNode($value, $body, $lineno, $this->getTag()); } - public function decideBlockEnd(Twig_Token $token) + public function decideBlockEnd(\Twig\Token $token) { return $token->test('endautoescape'); } diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php index ef5433cc11..c45289c5ba 100644 --- a/lib/Twig/TokenParser/Block.php +++ b/lib/Twig/TokenParser/Block.php @@ -20,44 +20,44 @@ * * @final */ -class Twig_TokenParser_Block extends Twig_TokenParser +class Twig_TokenParser_Block extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); if ($this->parser->hasBlock($name)) { - throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } - $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node([]), $lineno)); + $this->parser->setBlock($name, $block = new \Twig\Node\BlockNode($name, new \Twig\Node\Node([]), $lineno)); $this->parser->pushLocalScope(); $this->parser->pushBlockStack($name); - if ($stream->nextIf(Twig_Token::BLOCK_END_TYPE)) { + if ($stream->nextIf(\Twig\Token::BLOCK_END_TYPE)) { $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) { + if ($token = $stream->nextIf(\Twig\Token::NAME_TYPE)) { $value = $token->getValue(); if ($value != $name) { - throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } } } else { - $body = new Twig_Node([ - new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno), + $body = new \Twig\Node\Node([ + new \Twig\Node\PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno), ]); } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $block->setNode('body', $body); $this->parser->popBlockStack(); $this->parser->popLocalScope(); - return new Twig_Node_BlockReference($name, $lineno, $this->getTag()); + return new \Twig\Node\BlockReferenceNode($name, $lineno, $this->getTag()); } - public function decideBlockEnd(Twig_Token $token) + public function decideBlockEnd(\Twig\Token $token) { return $token->test('endblock'); } diff --git a/lib/Twig/TokenParser/Deprecated.php b/lib/Twig/TokenParser/Deprecated.php index 064fec7011..05ea042516 100644 --- a/lib/Twig/TokenParser/Deprecated.php +++ b/lib/Twig/TokenParser/Deprecated.php @@ -19,15 +19,15 @@ * * @final */ -class Twig_TokenParser_Deprecated extends Twig_TokenParser +class Twig_TokenParser_Deprecated extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_Deprecated($expr, $token->getLine(), $this->getTag()); + return new \Twig\Node\DeprecatedNode($expr, $token->getLine(), $this->getTag()); } public function getTag() diff --git a/lib/Twig/TokenParser/Do.php b/lib/Twig/TokenParser/Do.php index 8ce088089e..7d788668a5 100644 --- a/lib/Twig/TokenParser/Do.php +++ b/lib/Twig/TokenParser/Do.php @@ -14,15 +14,15 @@ * * @final */ -class Twig_TokenParser_Do extends Twig_TokenParser +class Twig_TokenParser_Do extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_Do($expr, $token->getLine(), $this->getTag()); + return new \Twig\Node\DoNode($expr, $token->getLine(), $this->getTag()); } public function getTag() diff --git a/lib/Twig/TokenParser/Embed.php b/lib/Twig/TokenParser/Embed.php index 62ad917096..7003f180ed 100644 --- a/lib/Twig/TokenParser/Embed.php +++ b/lib/Twig/TokenParser/Embed.php @@ -14,9 +14,9 @@ * * @final */ -class Twig_TokenParser_Embed extends Twig_TokenParser_Include +class Twig_TokenParser_Embed extends \Twig\TokenParser\IncludeTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $stream = $this->parser->getStream(); @@ -24,19 +24,19 @@ public function parse(Twig_Token $token) list($variables, $only, $ignoreMissing) = $this->parseArguments(); - $parentToken = $fakeParentToken = new Twig_Token(Twig_Token::STRING_TYPE, '__parent__', $token->getLine()); - if ($parent instanceof Twig_Node_Expression_Constant) { - $parentToken = new Twig_Token(Twig_Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine()); - } elseif ($parent instanceof Twig_Node_Expression_Name) { - $parentToken = new Twig_Token(Twig_Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine()); + $parentToken = $fakeParentToken = new \Twig\Token(\Twig\Token::STRING_TYPE, '__parent__', $token->getLine()); + if ($parent instanceof \Twig\Node\Expression\ConstantExpression) { + $parentToken = new \Twig\Token(\Twig\Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine()); + } elseif ($parent instanceof \Twig\Node\Expression\NameExpression) { + $parentToken = new \Twig\Token(\Twig\Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine()); } // inject a fake parent to make the parent() function work $stream->injectTokens([ - new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $token->getLine()), - new Twig_Token(Twig_Token::NAME_TYPE, 'extends', $token->getLine()), + new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', $token->getLine()), + new \Twig\Token(\Twig\Token::NAME_TYPE, 'extends', $token->getLine()), $parentToken, - new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', $token->getLine()), + new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', $token->getLine()), ]); $module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true); @@ -48,12 +48,12 @@ public function parse(Twig_Token $token) $this->parser->embedTemplate($module); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_Embed($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + return new \Twig\Node\EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); } - public function decideBlockEnd(Twig_Token $token) + public function decideBlockEnd(\Twig\Token $token) { return $token->test('endembed'); } diff --git a/lib/Twig/TokenParser/Extends.php b/lib/Twig/TokenParser/Extends.php index 0271598305..cb1c5fda35 100644 --- a/lib/Twig/TokenParser/Extends.php +++ b/lib/Twig/TokenParser/Extends.php @@ -17,22 +17,22 @@ * * @final */ -class Twig_TokenParser_Extends extends Twig_TokenParser +class Twig_TokenParser_Extends extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $stream = $this->parser->getStream(); if (!$this->parser->isMainScope()) { - throw new Twig_Error_Syntax('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext()); } if (null !== $this->parser->getParent()) { - throw new Twig_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); } $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); } public function getTag() diff --git a/lib/Twig/TokenParser/Filter.php b/lib/Twig/TokenParser/Filter.php index aa7aa9824e..ebb6cd99c2 100644 --- a/lib/Twig/TokenParser/Filter.php +++ b/lib/Twig/TokenParser/Filter.php @@ -18,26 +18,26 @@ * * @final */ -class Twig_TokenParser_Filter extends Twig_TokenParser +class Twig_TokenParser_Filter extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $name = $this->parser->getVarName(); - $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), null, $token->getLine(), $this->getTag()); + $ref = new \Twig\Node\Expression\BlockReferenceExpression(new \Twig\Node\Expression\ConstantExpression($name, $token->getLine()), null, $token->getLine(), $this->getTag()); $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); - $block = new Twig_Node_Block($name, $body, $token->getLine()); + $block = new \Twig\Node\BlockNode($name, $body, $token->getLine()); $this->parser->setBlock($name, $block); - return new Twig_Node_Print($filter, $token->getLine(), $this->getTag()); + return new \Twig\Node\PrintNode($filter, $token->getLine(), $this->getTag()); } - public function decideBlockEnd(Twig_Token $token) + public function decideBlockEnd(\Twig\Token $token) { return $token->test('endfilter'); } diff --git a/lib/Twig/TokenParser/Flush.php b/lib/Twig/TokenParser/Flush.php index 51832c77e1..67db2d87af 100644 --- a/lib/Twig/TokenParser/Flush.php +++ b/lib/Twig/TokenParser/Flush.php @@ -16,13 +16,13 @@ * * @final */ -class Twig_TokenParser_Flush extends Twig_TokenParser +class Twig_TokenParser_Flush extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_Flush($token->getLine(), $this->getTag()); + return new \Twig\Node\FlushNode($token->getLine(), $this->getTag()); } public function getTag() diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php index bbbe24c462..6518a2519f 100644 --- a/lib/Twig/TokenParser/For.php +++ b/lib/Twig/TokenParser/For.php @@ -21,40 +21,40 @@ * * @final */ -class Twig_TokenParser_For extends Twig_TokenParser +class Twig_TokenParser_For extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); - $stream->expect(Twig_Token::OPERATOR_TYPE, 'in'); + $stream->expect(\Twig\Token::OPERATOR_TYPE, 'in'); $seq = $this->parser->getExpressionParser()->parseExpression(); $ifexpr = null; - if ($stream->nextIf(Twig_Token::NAME_TYPE, 'if')) { + if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'if')) { $ifexpr = $this->parser->getExpressionParser()->parseExpression(); } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideForFork']); if ('else' == $stream->next()->getValue()) { - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $else = $this->parser->subparse([$this, 'decideForEnd'], true); } else { $else = null; } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); if (\count($targets) > 1) { $keyTarget = $targets->getNode(0); - $keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); + $keyTarget = new \Twig\Node\Expression\AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); $valueTarget = $targets->getNode(1); - $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + $valueTarget = new \Twig\Node\Expression\AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); } else { - $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno); + $keyTarget = new \Twig\Node\Expression\AssignNameExpression('_key', $lineno); $valueTarget = $targets->getNode(0); - $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + $valueTarget = new \Twig\Node\Expression\AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); } if ($ifexpr) { @@ -62,24 +62,24 @@ public function parse(Twig_Token $token) $this->checkLoopUsageBody($stream, $body); } - return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); + return new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); } - public function decideForFork(Twig_Token $token) + public function decideForFork(\Twig\Token $token) { return $token->test(['else', 'endfor']); } - public function decideForEnd(Twig_Token $token) + public function decideForEnd(\Twig\Token $token) { return $token->test('endfor'); } // the loop variable cannot be used in the condition - protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node) + protected function checkLoopUsageCondition(\Twig\TokenStream $stream, Twig_NodeInterface $node) { - if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { - throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()); + if ($node instanceof \Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \Twig\Node\Expression\NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { + throw new \Twig\Error\SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()); } foreach ($node as $n) { @@ -93,17 +93,17 @@ protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeIn // check usage of non-defined loop-items // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include) - protected function checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node) + protected function checkLoopUsageBody(\Twig\TokenStream $stream, Twig_NodeInterface $node) { - if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { + if ($node instanceof \Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \Twig\Node\Expression\NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { $attribute = $node->getNode('attribute'); - if ($attribute instanceof Twig_Node_Expression_Constant && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { - throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); + if ($attribute instanceof \Twig\Node\Expression\ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { + throw new \Twig\Error\SyntaxError(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); } } // should check for parent.loop.XXX usage - if ($node instanceof Twig_Node_For) { + if ($node instanceof \Twig\Node\ForNode) { return; } diff --git a/lib/Twig/TokenParser/From.php b/lib/Twig/TokenParser/From.php index 689cfa55be..50f7b5d4ce 100644 --- a/lib/Twig/TokenParser/From.php +++ b/lib/Twig/TokenParser/From.php @@ -16,9 +16,9 @@ * * @final */ -class Twig_TokenParser_From extends Twig_TokenParser +class Twig_TokenParser_From extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $macro = $this->parser->getExpressionParser()->parseExpression(); $stream = $this->parser->getStream(); @@ -26,27 +26,27 @@ public function parse(Twig_Token $token) $targets = []; do { - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); $alias = $name; if ($stream->nextIf('as')) { - $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $alias = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); } $targets[$name] = $alias; - if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { + if (!$stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) { break; } } while (true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); - $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); + $node = new \Twig\Node\ImportNode($macro, new \Twig\Node\Expression\AssignNameExpression($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); foreach ($targets as $name => $alias) { if ($this->parser->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); } $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var')); diff --git a/lib/Twig/TokenParser/If.php b/lib/Twig/TokenParser/If.php index 89f974bd7c..a26d0839e4 100644 --- a/lib/Twig/TokenParser/If.php +++ b/lib/Twig/TokenParser/If.php @@ -23,14 +23,14 @@ * * @final */ -class Twig_TokenParser_If extends Twig_TokenParser +class Twig_TokenParser_If extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); $expr = $this->parser->getExpressionParser()->parseExpression(); $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideIfFork']); $tests = [$expr, $body]; $else = null; @@ -39,13 +39,13 @@ public function parse(Twig_Token $token) while (!$end) { switch ($stream->next()->getValue()) { case 'else': - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $else = $this->parser->subparse([$this, 'decideIfEnd']); break; case 'elseif': $expr = $this->parser->getExpressionParser()->parseExpression(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideIfFork']); $tests[] = $expr; $tests[] = $body; @@ -56,21 +56,21 @@ public function parse(Twig_Token $token) break; default: - 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), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\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), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag()); + return new \Twig\Node\IfNode(new \Twig\Node\Node($tests), $else, $lineno, $this->getTag()); } - public function decideIfFork(Twig_Token $token) + public function decideIfFork(\Twig\Token $token) { return $token->test(['elseif', 'else', 'endif']); } - public function decideIfEnd(Twig_Token $token) + public function decideIfEnd(\Twig\Token $token) { return $token->test(['endif']); } diff --git a/lib/Twig/TokenParser/Import.php b/lib/Twig/TokenParser/Import.php index caebd80d80..3b5dd9ae49 100644 --- a/lib/Twig/TokenParser/Import.php +++ b/lib/Twig/TokenParser/Import.php @@ -16,18 +16,18 @@ * * @final */ -class Twig_TokenParser_Import extends Twig_TokenParser +class Twig_TokenParser_Import extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $macro = $this->parser->getExpressionParser()->parseExpression(); $this->parser->getStream()->expect('as'); - $var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(), $token->getLine()); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $var = new \Twig\Node\Expression\AssignNameExpression($this->parser->getStream()->expect(\Twig\Token::NAME_TYPE)->getValue(), $token->getLine()); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); $this->parser->addImportedSymbol('template', $var->getAttribute('name')); - return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag()); + return new \Twig\Node\ImportNode($macro, $var, $token->getLine(), $this->getTag()); } public function getTag() diff --git a/lib/Twig/TokenParser/Include.php b/lib/Twig/TokenParser/Include.php index f53f2a1643..a673a06639 100644 --- a/lib/Twig/TokenParser/Include.php +++ b/lib/Twig/TokenParser/Include.php @@ -17,15 +17,15 @@ * Body * {% include 'footer.html' %} */ -class Twig_TokenParser_Include extends Twig_TokenParser +class Twig_TokenParser_Include extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); list($variables, $only, $ignoreMissing) = $this->parseArguments(); - return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + return new \Twig\Node\IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); } protected function parseArguments() @@ -33,23 +33,23 @@ protected function parseArguments() $stream = $this->parser->getStream(); $ignoreMissing = false; - if ($stream->nextIf(Twig_Token::NAME_TYPE, 'ignore')) { - $stream->expect(Twig_Token::NAME_TYPE, 'missing'); + if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'ignore')) { + $stream->expect(\Twig\Token::NAME_TYPE, 'missing'); $ignoreMissing = true; } $variables = null; - if ($stream->nextIf(Twig_Token::NAME_TYPE, 'with')) { + if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'with')) { $variables = $this->parser->getExpressionParser()->parseExpression(); } $only = false; - if ($stream->nextIf(Twig_Token::NAME_TYPE, 'only')) { + if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'only')) { $only = true; } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); return [$variables, $only, $ignoreMissing]; } diff --git a/lib/Twig/TokenParser/Macro.php b/lib/Twig/TokenParser/Macro.php index 738731e6ce..e0462c76f4 100644 --- a/lib/Twig/TokenParser/Macro.php +++ b/lib/Twig/TokenParser/Macro.php @@ -18,33 +18,33 @@ * * @final */ -class Twig_TokenParser_Macro extends Twig_TokenParser +class Twig_TokenParser_Macro extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); $arguments = $this->parser->getExpressionParser()->parseArguments(true, true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $this->parser->pushLocalScope(); $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) { + if ($token = $stream->nextIf(\Twig\Token::NAME_TYPE)) { $value = $token->getValue(); if ($value != $name) { - throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } } $this->parser->popLocalScope(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); - $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body([$body]), $arguments, $lineno, $this->getTag())); + $this->parser->setMacro($name, new \Twig\Node\MacroNode($name, new \Twig\Node\BodyNode([$body]), $arguments, $lineno, $this->getTag())); } - public function decideBlockEnd(Twig_Token $token) + public function decideBlockEnd(\Twig\Token $token) { return $token->test('endmacro'); } diff --git a/lib/Twig/TokenParser/Sandbox.php b/lib/Twig/TokenParser/Sandbox.php index fa2045743f..9adfb0938d 100644 --- a/lib/Twig/TokenParser/Sandbox.php +++ b/lib/Twig/TokenParser/Sandbox.php @@ -20,32 +20,32 @@ * * @final */ -class Twig_TokenParser_Sandbox extends Twig_TokenParser +class Twig_TokenParser_Sandbox extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); // in a sandbox tag, only include tags are allowed - if (!$body instanceof Twig_Node_Include) { + if (!$body instanceof \Twig\Node\IncludeNode) { foreach ($body as $node) { - if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) { + if ($node instanceof \Twig\Node\TextNode && ctype_space($node->getAttribute('data'))) { continue; } - if (!$node instanceof Twig_Node_Include) { - throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); + if (!$node instanceof \Twig\Node\IncludeNode) { + throw new \Twig\Error\SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); } } } - return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag()); + return new \Twig\Node\SandboxNode($body, $token->getLine(), $this->getTag()); } - public function decideBlockEnd(Twig_Token $token) + public function decideBlockEnd(\Twig\Token $token) { return $token->test('endsandbox'); } diff --git a/lib/Twig/TokenParser/Set.php b/lib/Twig/TokenParser/Set.php index e60ee6c899..55a45f83f3 100644 --- a/lib/Twig/TokenParser/Set.php +++ b/lib/Twig/TokenParser/Set.php @@ -21,40 +21,40 @@ * * @final */ -class Twig_TokenParser_Set extends Twig_TokenParser +class Twig_TokenParser_Set extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); $capture = false; - if ($stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) { + if ($stream->nextIf(\Twig\Token::OPERATOR_TYPE, '=')) { $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); if (\count($names) !== \count($values)) { - throw new Twig_Error_Syntax('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } } else { $capture = true; if (\count($names) > 1) { - throw new Twig_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new \Twig\Error\SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $values = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); } - return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag()); + return new \Twig\Node\SetNode($capture, $names, $values, $lineno, $this->getTag()); } - public function decideBlockEnd(Twig_Token $token) + public function decideBlockEnd(\Twig\Token $token) { return $token->test('endset'); } diff --git a/lib/Twig/TokenParser/Spaceless.php b/lib/Twig/TokenParser/Spaceless.php index 6a3f33ffc7..3b303ea5a3 100644 --- a/lib/Twig/TokenParser/Spaceless.php +++ b/lib/Twig/TokenParser/Spaceless.php @@ -21,20 +21,20 @@ * * @final */ -class Twig_TokenParser_Spaceless extends Twig_TokenParser +class Twig_TokenParser_Spaceless extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_Spaceless($body, $lineno, $this->getTag()); + return new \Twig\Node\SpacelessNode($body, $lineno, $this->getTag()); } - public function decideSpacelessEnd(Twig_Token $token) + public function decideSpacelessEnd(\Twig\Token $token) { return $token->test('endspaceless'); } diff --git a/lib/Twig/TokenParser/Use.php b/lib/Twig/TokenParser/Use.php index 7e293001e4..1a515e836f 100644 --- a/lib/Twig/TokenParser/Use.php +++ b/lib/Twig/TokenParser/Use.php @@ -23,40 +23,40 @@ * * @final */ -class Twig_TokenParser_Use extends Twig_TokenParser +class Twig_TokenParser_Use extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $template = $this->parser->getExpressionParser()->parseExpression(); $stream = $this->parser->getStream(); - if (!$template instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + if (!$template instanceof \Twig\Node\Expression\ConstantExpression) { + throw new \Twig\Error\SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $targets = []; if ($stream->nextIf('with')) { do { - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); $alias = $name; if ($stream->nextIf('as')) { - $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $alias = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); } - $targets[$name] = new Twig_Node_Expression_Constant($alias, -1); + $targets[$name] = new \Twig\Node\Expression\ConstantExpression($alias, -1); - if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { + if (!$stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) { break; } } while (true); } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); - $this->parser->addTrait(new Twig_Node(['template' => $template, 'targets' => new Twig_Node($targets)])); + $this->parser->addTrait(new \Twig\Node\Node(['template' => $template, 'targets' => new \Twig\Node\Node($targets)])); - return new Twig_Node(); + return new \Twig\Node\Node(); } public function getTag() diff --git a/lib/Twig/TokenParser/With.php b/lib/Twig/TokenParser/With.php index 34a0812207..66e55ace53 100644 --- a/lib/Twig/TokenParser/With.php +++ b/lib/Twig/TokenParser/With.php @@ -16,29 +16,29 @@ * * @final */ -class Twig_TokenParser_With extends Twig_TokenParser +class Twig_TokenParser_With extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { $stream = $this->parser->getStream(); $variables = null; $only = false; - if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) { + if (!$stream->test(\Twig\Token::BLOCK_END_TYPE)) { $variables = $this->parser->getExpressionParser()->parseExpression(); - $only = $stream->nextIf(Twig_Token::NAME_TYPE, 'only'); + $only = $stream->nextIf(\Twig\Token::NAME_TYPE, 'only'); } - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideWithEnd'], true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_With($body, $variables, $only, $token->getLine(), $this->getTag()); + return new \Twig\Node\WithNode($body, $variables, $only, $token->getLine(), $this->getTag()); } - public function decideWithEnd(Twig_Token $token) + public function decideWithEnd(\Twig\Token $token) { return $token->test('endwith'); } diff --git a/lib/Twig/TokenParserBroker.php b/lib/Twig/TokenParserBroker.php index e7f787969b..3e1871f48b 100644 --- a/lib/Twig/TokenParserBroker.php +++ b/lib/Twig/TokenParserBroker.php @@ -35,7 +35,7 @@ public function __construct($parsers = [], $brokers = [], $triggerDeprecationErr } foreach ($parsers as $parser) { - if (!$parser instanceof Twig_TokenParserInterface) { + if (!$parser instanceof \Twig\TokenParser\TokenParserInterface) { throw new \LogicException('$parsers must a an array of Twig_TokenParserInterface.'); } $this->parsers[$parser->getTag()] = $parser; @@ -48,12 +48,12 @@ public function __construct($parsers = [], $brokers = [], $triggerDeprecationErr } } - public function addTokenParser(Twig_TokenParserInterface $parser) + public function addTokenParser(\Twig\TokenParser\TokenParserInterface $parser) { $this->parsers[$parser->getTag()] = $parser; } - public function removeTokenParser(Twig_TokenParserInterface $parser) + public function removeTokenParser(\Twig\TokenParser\TokenParserInterface $parser) { $name = $parser->getTag(); if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) { @@ -80,7 +80,7 @@ public function removeTokenParserBroker(self $broker) * * @param string $tag A tag name * - * @return Twig_TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found + * @return \Twig\TokenParser\TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found */ public function getTokenParser($tag) { diff --git a/lib/Twig/TokenParserBrokerInterface.php b/lib/Twig/TokenParserBrokerInterface.php index c239c2ec82..7a5d563eca 100644 --- a/lib/Twig/TokenParserBrokerInterface.php +++ b/lib/Twig/TokenParserBrokerInterface.php @@ -26,12 +26,12 @@ interface Twig_TokenParserBrokerInterface * * @param string $tag A tag name * - * @return Twig_TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found + * @return \Twig\TokenParser\TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found */ public function getTokenParser($tag); /** - * Calls Twig_TokenParserInterface::setParser on all parsers the implementation knows of. + * Calls \Twig\TokenParser\TokenParserInterface::setParser on all parsers the implementation knows of. */ public function setParser(Twig_ParserInterface $parser); diff --git a/lib/Twig/TokenParserInterface.php b/lib/Twig/TokenParserInterface.php index 14acc8084b..2090ae187e 100644 --- a/lib/Twig/TokenParserInterface.php +++ b/lib/Twig/TokenParserInterface.php @@ -19,16 +19,16 @@ interface Twig_TokenParserInterface /** * Sets the parser associated with this token parser. */ - public function setParser(Twig_Parser $parser); + public function setParser(\Twig\Parser $parser); /** * Parses a token and returns a node. * * @return Twig_NodeInterface * - * @throws Twig_Error_Syntax + * @throws \Twig\Error\SyntaxError */ - public function parse(Twig_Token $token); + public function parse(\Twig\Token $token); /** * Gets the tag name associated with this token parser. diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index 73374908b8..89b1fb711e 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -32,11 +32,11 @@ class Twig_TokenStream */ public function __construct(array $tokens, $name = null, $source = null) { - if (!$name instanceof Twig_Source) { + if (!$name instanceof \Twig\Source) { if (null !== $name || null !== $source) { @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); } - $this->source = new Twig_Source($source, $name); + $this->source = new \Twig\Source($source, $name); } else { $this->source = $name; } @@ -60,12 +60,12 @@ public function injectTokens(array $tokens) /** * Sets the pointer to the next token and returns the old one. * - * @return Twig_Token + * @return \Twig\Token */ public function next() { if (!isset($this->tokens[++$this->current])) { - throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); + throw new \Twig\Error\SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); } return $this->tokens[$this->current - 1]; @@ -74,7 +74,7 @@ public function next() /** * Tests a token, sets the pointer to the next one and returns it or throws a syntax error. * - * @return Twig_Token|null The next token if the condition is true, null otherwise + * @return \Twig\Token|null The next token if the condition is true, null otherwise */ public function nextIf($primary, $secondary = null) { @@ -86,17 +86,17 @@ public function nextIf($primary, $secondary = null) /** * Tests a token and returns it or throws a syntax error. * - * @return Twig_Token + * @return \Twig\Token */ public function expect($type, $value = null, $message = null) { $token = $this->tokens[$this->current]; if (!$token->test($type, $value)) { $line = $token->getLine(); - throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', + throw new \Twig\Error\SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', $message ? $message.'. ' : '', - Twig_Token::typeToEnglish($token->getType()), $token->getValue(), - Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), + \Twig\Token::typeToEnglish($token->getType()), $token->getValue(), + \Twig\Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), $line, $this->source ); @@ -111,12 +111,12 @@ public function expect($type, $value = null, $message = null) * * @param int $number * - * @return Twig_Token + * @return \Twig\Token */ public function look($number = 1) { if (!isset($this->tokens[$this->current + $number])) { - throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); + throw new \Twig\Error\SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); } return $this->tokens[$this->current + $number]; @@ -139,11 +139,11 @@ public function test($primary, $secondary = null) */ public function isEOF() { - return Twig_Token::EOF_TYPE === $this->tokens[$this->current]->getType(); + return \Twig\Token::EOF_TYPE === $this->tokens[$this->current]->getType(); } /** - * @return Twig_Token + * @return \Twig\Token */ public function getCurrent() { @@ -183,7 +183,7 @@ public function getSource() /** * Gets the source associated with this stream. * - * @return Twig_Source + * @return \Twig\Source * * @internal */ diff --git a/lib/Twig/Util/DeprecationCollector.php b/lib/Twig/Util/DeprecationCollector.php index 6f3da609af..f4c2bd25e2 100644 --- a/lib/Twig/Util/DeprecationCollector.php +++ b/lib/Twig/Util/DeprecationCollector.php @@ -19,7 +19,7 @@ class Twig_Util_DeprecationCollector private $twig; private $deprecations; - public function __construct(Twig_Environment $twig) + public function __construct(\Twig\Environment $twig) { $this->twig = $twig; } @@ -40,7 +40,7 @@ public function collectDir($dir, $ext = '.twig') ), '{'.preg_quote($ext).'$}' ); - return $this->collect(new Twig_Util_TemplateDirIterator($iterator)); + return $this->collect(new \Twig\Util\TemplateDirIterator($iterator)); } /** @@ -58,8 +58,8 @@ public function collect(\Traversable $iterator) foreach ($iterator as $name => $contents) { try { - $this->twig->parse($this->twig->tokenize(new Twig_Source($contents, $name))); - } catch (Twig_Error_Syntax $e) { + $this->twig->parse($this->twig->tokenize(new \Twig\Source($contents, $name))); + } catch (\Twig\Error\SyntaxError $e) { // ignore templates containing syntax errors } } diff --git a/test/Twig/Tests/Cache/FilesystemTest.php b/test/Twig/Tests/Cache/FilesystemTest.php index 806143eeb2..9657a1adb9 100644 --- a/test/Twig/Tests/Cache/FilesystemTest.php +++ b/test/Twig/Tests/Cache/FilesystemTest.php @@ -22,7 +22,7 @@ protected function setUp() $nonce = hash('sha256', uniqid(mt_rand(), true)); $this->classname = '__Twig_Tests_Cache_FilesystemTest_Template_'.$nonce; $this->directory = sys_get_temp_dir().'/twig-test'; - $this->cache = new Twig_Cache_Filesystem($this->directory); + $this->cache = new \Twig\Cache\FilesystemCache($this->directory); } protected function tearDown() @@ -166,7 +166,7 @@ public function testGetTimestampMissingFile() */ public function testGenerateKey($expected, $input) { - $cache = new Twig_Cache_Filesystem($input); + $cache = new \Twig\Cache\FilesystemCache($input); $this->assertRegExp($expected, $cache->generateKey('_test_', \get_class($this))); } diff --git a/test/Twig/Tests/CompilerTest.php b/test/Twig/Tests/CompilerTest.php index 62f2c36c8c..f02a0ce06a 100644 --- a/test/Twig/Tests/CompilerTest.php +++ b/test/Twig/Tests/CompilerTest.php @@ -13,7 +13,7 @@ class Twig_Tests_CompilerTest extends \PHPUnit\Framework\TestCase { public function testReprNumericValueWithLocale() { - $compiler = new Twig_Compiler(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new \Twig\Compiler(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $locale = setlocale(LC_NUMERIC, 0); if (false === $locale) { diff --git a/test/Twig/Tests/ContainerRuntimeLoaderTest.php b/test/Twig/Tests/ContainerRuntimeLoaderTest.php index 73f1ba6bba..3eefcfb9af 100644 --- a/test/Twig/Tests/ContainerRuntimeLoaderTest.php +++ b/test/Twig/Tests/ContainerRuntimeLoaderTest.php @@ -20,7 +20,7 @@ public function testLoad() $container->expects($this->once())->method('has')->with('stdClass')->willReturn(true); $container->expects($this->once())->method('get')->with('stdClass')->willReturn(new \stdClass()); - $loader = new Twig_ContainerRuntimeLoader($container); + $loader = new \Twig\RuntimeLoader\ContainerRuntimeLoader($container); $this->assertInstanceOf('stdClass', $loader->load('stdClass')); } @@ -34,7 +34,7 @@ public function testLoadUnknownRuntimeReturnsNull() $container->expects($this->once())->method('has')->with('Foo'); $container->expects($this->never())->method('get'); - $loader = new Twig_ContainerRuntimeLoader($container); + $loader = new \Twig\RuntimeLoader\ContainerRuntimeLoader($container); $this->assertNull($loader->load('Foo')); } } diff --git a/test/Twig/Tests/CustomExtensionTest.php b/test/Twig/Tests/CustomExtensionTest.php index 6dd959dd84..40dc3fe9ec 100644 --- a/test/Twig/Tests/CustomExtensionTest.php +++ b/test/Twig/Tests/CustomExtensionTest.php @@ -15,7 +15,7 @@ class CustomExtensionTest extends \PHPUnit\Framework\TestCase * @requires PHP 5.3 * @dataProvider provideInvalidExtensions */ - public function testGetInvalidOperators(Twig_ExtensionInterface $extension, $expectedExceptionMessage) + public function testGetInvalidOperators(\Twig\Extension\ExtensionInterface $extension, $expectedExceptionMessage) { if (method_exists($this, 'expectException')) { $this->expectException('InvalidArgumentException'); @@ -24,7 +24,7 @@ public function testGetInvalidOperators(Twig_ExtensionInterface $extension, $exp $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); } - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $env->addExtension($extension); $env->getUnaryOperators(); } @@ -38,7 +38,7 @@ public function provideInvalidExtensions() } } -class InvalidOperatorExtension implements Twig_ExtensionInterface +class InvalidOperatorExtension implements \Twig\Extension\ExtensionInterface { private $operators; @@ -47,7 +47,7 @@ public function __construct($operators) $this->operators = $operators; } - public function initRuntime(Twig_Environment $environment) + public function initRuntime(\Twig\Environment $environment) { } diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index 8c177755b4..78f2268383 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -20,7 +20,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase */ public function testLegacyTokenizeSignature() { - $env = new Twig_Environment(); + $env = new \Twig\Environment(); $stream = $env->tokenize('{{ foo }}', 'foo'); $this->assertEquals('{{ foo }}', $stream->getSource()); $this->assertEquals('foo', $stream->getFilename()); @@ -31,8 +31,8 @@ public function testLegacyTokenizeSignature() */ public function testLegacyCompileSourceSignature() { - $loader = new Twig_Loader_Array(['foo' => '{{ foo }}']); - $env = new Twig_Environment($loader); + $loader = new \Twig\Loader\ArrayLoader(['foo' => '{{ foo }}']); + $env = new \Twig\Environment($loader); $this->assertContains('getTemplateName', $env->compileSource('{{ foo }}', 'foo')); } @@ -43,18 +43,18 @@ public function testLegacyCompileSourceSignature() */ public function testRenderNoLoader() { - $env = new Twig_Environment(); + $env = new \Twig\Environment(); $env->render('test'); } public function testAutoescapeOption() { - $loader = new Twig_Loader_Array([ + $loader = new \Twig\Loader\ArrayLoader([ 'html' => '{{ foo }} {{ foo }}', 'js' => '{{ bar }} {{ bar }}', ]); - $twig = new Twig_Environment($loader, [ + $twig = new \Twig\Environment($loader, [ 'debug' => true, 'cache' => false, 'autoescape' => [$this, 'escapingStrategyCallback'], @@ -73,12 +73,12 @@ public function testGlobals() { // to be removed in 2.0 $loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock(); - //$loader = $this->getMockBuilder(['Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'])->getMock(); - $loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new Twig_Source('', ''))); + //$loader = $this->getMockBuilder(['\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface'])->getMock(); + $loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new \Twig\Source('', ''))); // globals can be added after calling getGlobals - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->addGlobal('foo', 'bar'); @@ -86,7 +86,7 @@ public function testGlobals() $this->assertEquals('bar', $globals['foo']); // globals can be modified after a template has been loaded - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->loadTemplate('index'); @@ -95,7 +95,7 @@ public function testGlobals() $this->assertEquals('bar', $globals['foo']); // globals can be modified after extensions init - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->getFunctions(); @@ -104,8 +104,8 @@ public function testGlobals() $this->assertEquals('bar', $globals['foo']); // globals can be modified after extensions and a template has been loaded - $arrayLoader = new Twig_Loader_Array(['index' => '{{foo}}']); - $twig = new Twig_Environment($arrayLoader); + $arrayLoader = new \Twig\Loader\ArrayLoader(['index' => '{{foo}}']); + $twig = new \Twig\Environment($arrayLoader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->getFunctions(); @@ -114,7 +114,7 @@ public function testGlobals() $globals = $twig->getGlobals(); $this->assertEquals('bar', $globals['foo']); - $twig = new Twig_Environment($arrayLoader); + $twig = new \Twig\Environment($arrayLoader); $twig->getGlobals(); $twig->addGlobal('foo', 'bar'); $template = $twig->loadTemplate('index'); @@ -122,7 +122,7 @@ public function testGlobals() /* to be uncomment in Twig 2.0 // globals cannot be added after a template has been loaded - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->loadTemplate('index'); @@ -134,7 +134,7 @@ public function testGlobals() } // globals cannot be added after extensions init - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->getFunctions(); @@ -146,7 +146,7 @@ public function testGlobals() } // globals cannot be added after extensions and a template has been loaded - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->getFunctions(); @@ -159,7 +159,7 @@ public function testGlobals() } // test adding globals after a template has been loaded without call to getGlobals - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->loadTemplate('index'); try { $twig->addGlobal('bar', 'bar'); @@ -172,18 +172,18 @@ public function testGlobals() public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate() { - $cache = new Twig_Cache_Filesystem($dir = sys_get_temp_dir().'/twig'); + $cache = new \Twig\Cache\FilesystemCache($dir = sys_get_temp_dir().'/twig'); $options = ['cache' => $cache, 'auto_reload' => false, 'debug' => false]; // force compilation - $twig = new Twig_Environment($loader = new Twig_Loader_Array(['index' => '{{ foo }}']), $options); + $twig = new \Twig\Environment($loader = new \Twig\Loader\ArrayLoader(['index' => '{{ foo }}']), $options); $key = $cache->generateKey('index', $twig->getTemplateClass('index')); - $cache->write($key, $twig->compileSource(new Twig_Source('{{ foo }}', 'index'))); + $cache->write($key, $twig->compileSource(new \Twig\Source('{{ foo }}', 'index'))); // check that extensions won't be initialized when rendering a template that is already in the cache $twig = $this - ->getMockBuilder('Twig_Environment') + ->getMockBuilder('\Twig\Environment') ->setConstructorArgs([$loader, $options]) ->setMethods(['initExtensions']) ->getMock() @@ -203,9 +203,9 @@ public function testAutoReloadCacheMiss() $templateName = __FUNCTION__; $templateContent = __FUNCTION__; - $cache = $this->getMockBuilder('Twig_CacheInterface')->getMock(); + $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock(); $loader = $this->getMockLoader($templateName, $templateContent); - $twig = new Twig_Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); + $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); // Cache miss: getTimestamp returns 0 and as a result the load() is // skipped. @@ -230,9 +230,9 @@ public function testAutoReloadCacheHit() $templateName = __FUNCTION__; $templateContent = __FUNCTION__; - $cache = $this->getMockBuilder('Twig_CacheInterface')->getMock(); + $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock(); $loader = $this->getMockLoader($templateName, $templateContent); - $twig = new Twig_Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); + $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); $now = time(); @@ -258,9 +258,9 @@ public function testAutoReloadOutdatedCacheHit() $templateName = __FUNCTION__; $templateContent = __FUNCTION__; - $cache = $this->getMockBuilder('Twig_CacheInterface')->getMock(); + $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock(); $loader = $this->getMockLoader($templateName, $templateContent); - $twig = new Twig_Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); + $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); $now = time(); @@ -286,7 +286,7 @@ public function testAutoReloadOutdatedCacheHit() */ public function testHasGetExtensionWithDynamicName() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $ext1 = new Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName('ext1'); $ext2 = new Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName('ext2'); @@ -304,7 +304,7 @@ public function testHasGetExtensionWithDynamicName() public function testHasGetExtensionByClassName() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension($ext = new Twig_Tests_EnvironmentTest_Extension()); $this->assertTrue($twig->hasExtension('Twig_Tests_EnvironmentTest_Extension')); $this->assertTrue($twig->hasExtension('\Twig_Tests_EnvironmentTest_Extension')); @@ -318,7 +318,7 @@ public function testHasGetExtensionByClassName() public function testAddExtension() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension()); $this->assertArrayHasKey('test', $twig->getTags()); @@ -343,7 +343,7 @@ public function testAddExtension() */ public function testAddExtensionWithDeprecatedGetGlobals() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithGlobals()); $this->deprecations = []; @@ -362,7 +362,7 @@ public function testAddExtensionWithDeprecatedGetGlobals() */ public function testRemoveExtension() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName()); $twig->removeExtension('environment_test'); @@ -379,27 +379,27 @@ public function testRemoveExtension() public function testAddMockExtension() { // should be replaced by the following in 2.0 (this current code is just to avoid a dep notice) - // $extension = $this->getMockBuilder('Twig_Extension')->getMock(); + // $extension = $this->getMockBuilder('\Twig\Extension\AbstractExtension')->getMock(); $extension = eval(<< 'hey']); + $loader = new \Twig\Loader\ArrayLoader(['page' => 'hey']); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addExtension($extension); - $this->assertInstanceOf('Twig_ExtensionInterface', $twig->getExtension(\get_class($extension))); + $this->assertInstanceOf('\Twig\Extension\ExtensionInterface', $twig->getExtension(\get_class($extension))); $this->assertTrue($twig->isTemplateFresh('page', time())); } public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime()); $twig->initRuntime(); @@ -413,7 +413,7 @@ public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation() */ public function testInitRuntimeWithAnExtensionUsingInitRuntimeDeprecation() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime()); $this->deprecations = []; @@ -439,7 +439,7 @@ public function handleError($type, $msg) */ public function testOverrideExtension() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime()); $this->deprecations = []; @@ -456,10 +456,10 @@ public function testOverrideExtension() public function testAddRuntimeLoader() { - $runtimeLoader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock(); + $runtimeLoader = $this->getMockBuilder('\Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock(); $runtimeLoader->expects($this->any())->method('load')->will($this->returnValue(new Twig_Tests_EnvironmentTest_Runtime())); - $loader = new Twig_Loader_Array([ + $loader = new \Twig\Loader\ArrayLoader([ 'func_array' => '{{ from_runtime_array("foo") }}', 'func_array_default' => '{{ from_runtime_array() }}', 'func_array_named_args' => '{{ from_runtime_array(name="foo") }}', @@ -468,7 +468,7 @@ public function testAddRuntimeLoader() 'func_string_named_args' => '{{ from_runtime_string(name="foo") }}', ]); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime()); $twig->addRuntimeLoader($runtimeLoader); @@ -481,12 +481,12 @@ public function testAddRuntimeLoader() } /** - * @expectedException \Twig_Error_Runtime + * @expectedException \Twig\Error\RuntimeError * @expectedExceptionMessage Circular reference detected for Twig template "base.html.twig", path: base.html.twig -> base.html.twig in "base.html.twig" at line 1 */ public function testFailLoadTemplateOnCircularReference() { - $twig = new Twig_Environment(new Twig_Loader_Array([ + $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ 'base.html.twig' => '{% extends "base.html.twig" %}', ])); @@ -494,12 +494,12 @@ public function testFailLoadTemplateOnCircularReference() } /** - * @expectedException \Twig_Error_Runtime + * @expectedException \Twig\Error\RuntimeError * @expectedExceptionMessage Circular reference detected for Twig template "base1.html.twig", path: base1.html.twig -> base2.html.twig -> base1.html.twig in "base1.html.twig" at line 1 */ public function testFailLoadTemplateOnComplexCircularReference() { - $twig = new Twig_Environment(new Twig_Loader_Array([ + $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ 'base1.html.twig' => '{% extends "base2.html.twig" %}', 'base2.html.twig' => '{% extends "base1.html.twig" %}', ])); @@ -511,11 +511,11 @@ protected function getMockLoader($templateName, $templateContent) { // to be removed in 2.0 $loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock(); - //$loader = $this->getMockBuilder(['Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'])->getMock(); + //$loader = $this->getMockBuilder(['\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface'])->getMock(); $loader->expects($this->any()) ->method('getSourceContext') ->with($templateName) - ->will($this->returnValue(new Twig_Source($templateContent, $templateName))); + ->will($this->returnValue(new \Twig\Source($templateContent, $templateName))); $loader->expects($this->any()) ->method('getCacheKey') ->with($templateName) @@ -525,7 +525,7 @@ protected function getMockLoader($templateName, $templateContent) } } -class Twig_Tests_EnvironmentTest_Extension_WithGlobals extends Twig_Extension +class Twig_Tests_EnvironmentTest_Extension_WithGlobals extends \Twig\Extension\AbstractExtension { public function getGlobals() { @@ -535,7 +535,7 @@ public function getGlobals() } } -class Twig_Tests_EnvironmentTest_Extension extends Twig_Extension implements Twig_Extension_GlobalsInterface +class Twig_Tests_EnvironmentTest_Extension extends \Twig\Extension\AbstractExtension implements \Twig\Extension\GlobalsInterface { public function getTokenParsers() { @@ -554,21 +554,21 @@ public function getNodeVisitors() public function getFilters() { return [ - new Twig_SimpleFilter('foo_filter', 'foo_filter'), + new \Twig\TwigFilter('foo_filter', 'foo_filter'), ]; } public function getTests() { return [ - new Twig_SimpleTest('foo_test', 'foo_test'), + new \Twig\TwigTest('foo_test', 'foo_test'), ]; } public function getFunctions() { return [ - new Twig_SimpleFunction('foo_function', 'foo_function'), + new \Twig\TwigFunction('foo_function', 'foo_function'), ]; } @@ -589,7 +589,7 @@ public function getGlobals() } class_alias('Twig_Tests_EnvironmentTest_Extension', 'Twig\Tests\EnvironmentTest\Extension', false); -class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends Twig_Extension +class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends \Twig\Extension\AbstractExtension { public function getName() { @@ -597,7 +597,7 @@ public function getName() } } -class Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName extends Twig_Extension +class Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName extends \Twig\Extension\AbstractExtension { private $name; @@ -612,9 +612,9 @@ public function getName() } } -class Twig_Tests_EnvironmentTest_TokenParser extends Twig_TokenParser +class Twig_Tests_EnvironmentTest_TokenParser extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { } @@ -624,14 +624,14 @@ public function getTag() } } -class Twig_Tests_EnvironmentTest_NodeVisitor implements Twig_NodeVisitorInterface +class Twig_Tests_EnvironmentTest_NodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface { - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env) { return $node; } - public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env) { return $node; } @@ -642,27 +642,27 @@ public function getPriority() } } -class Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime extends Twig_Extension +class Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime extends \Twig\Extension\AbstractExtension { - public function initRuntime(Twig_Environment $env) + public function initRuntime(\Twig\Environment $env) { } } -class Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime extends Twig_Extension implements Twig_Extension_InitRuntimeInterface +class Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime extends \Twig\Extension\AbstractExtension implements \Twig\Extension\InitRuntimeInterface { - public function initRuntime(Twig_Environment $env) + public function initRuntime(\Twig\Environment $env) { } } -class Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime extends Twig_Extension +class Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime extends \Twig\Extension\AbstractExtension { public function getFunctions() { return [ - new Twig_SimpleFunction('from_runtime_array', ['Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime']), - new Twig_SimpleFunction('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'), + new \Twig\TwigFunction('from_runtime_array', ['Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime']), + new \Twig\TwigFunction('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'), ]; } @@ -681,6 +681,6 @@ public function fromRuntime($name = 'bar') } // to be removed in 2.0 -interface Twig_EnvironmentTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface +interface Twig_EnvironmentTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface { } diff --git a/test/Twig/Tests/ErrorTest.php b/test/Twig/Tests/ErrorTest.php index 3b39ace64e..2337e2399e 100644 --- a/test/Twig/Tests/ErrorTest.php +++ b/test/Twig/Tests/ErrorTest.php @@ -13,23 +13,23 @@ class Twig_Tests_ErrorTest extends \PHPUnit\Framework\TestCase { public function testErrorWithObjectFilename() { - $error = new Twig_Error('foo'); - $error->setSourceContext(new Twig_Source('', new \SplFileInfo(__FILE__))); + $error = new \Twig\Error\Error('foo'); + $error->setSourceContext(new \Twig\Source('', new \SplFileInfo(__FILE__))); $this->assertContains('test'.DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage()); } public function testErrorWithArrayFilename() { - $error = new Twig_Error('foo'); - $error->setSourceContext(new Twig_Source('', ['foo' => 'bar'])); + $error = new \Twig\Error\Error('foo'); + $error->setSourceContext(new \Twig\Source('', ['foo' => 'bar'])); $this->assertEquals('foo in {"foo":"bar"}', $error->getMessage()); } public function testTwigExceptionGuessWithMissingVarAndArrayLoader() { - $loader = new Twig_Loader_Array([ + $loader = new \Twig\Loader\ArrayLoader([ 'base.html' => '{% block content %}{% endblock %}', 'index.html' => << true, 'debug' => true, 'cache' => false]); + $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index.html'); try { $template->render([]); $this->fail(); - } catch (Twig_Error_Runtime $e) { + } catch (\Twig\Error\RuntimeError $e) { $this->assertEquals('Variable "foo" does not exist in "index.html" at line 3.', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getSourceContext()->getName()); @@ -57,7 +57,7 @@ public function testTwigExceptionGuessWithMissingVarAndArrayLoader() public function testTwigExceptionGuessWithExceptionAndArrayLoader() { - $loader = new Twig_Loader_Array([ + $loader = new \Twig\Loader\ArrayLoader([ 'base.html' => '{% block content %}{% endblock %}', 'index.html' => << true, 'debug' => true, 'cache' => false]); + $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index.html'); try { $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); $this->fail(); - } catch (Twig_Error_Runtime $e) { + } catch (\Twig\Error\RuntimeError $e) { $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getSourceContext()->getName()); @@ -85,15 +85,15 @@ public function testTwigExceptionGuessWithExceptionAndArrayLoader() public function testTwigExceptionGuessWithMissingVarAndFilesystemLoader() { - $loader = new Twig_Loader_Filesystem(__DIR__.'/Fixtures/errors'); - $twig = new Twig_Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); + $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Fixtures/errors'); + $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index.html'); try { $template->render([]); $this->fail(); - } catch (Twig_Error_Runtime $e) { + } catch (\Twig\Error\RuntimeError $e) { $this->assertEquals('Variable "foo" does not exist.', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getSourceContext()->getName()); @@ -104,15 +104,15 @@ public function testTwigExceptionGuessWithMissingVarAndFilesystemLoader() public function testTwigExceptionGuessWithExceptionAndFilesystemLoader() { - $loader = new Twig_Loader_Filesystem(__DIR__.'/Fixtures/errors'); - $twig = new Twig_Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); + $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Fixtures/errors'); + $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index.html'); try { $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); $this->fail(); - } catch (Twig_Error_Runtime $e) { + } catch (\Twig\Error\RuntimeError $e) { $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getSourceContext()->getName()); @@ -126,8 +126,8 @@ public function testTwigExceptionGuessWithExceptionAndFilesystemLoader() */ public function testTwigExceptionAddsFileAndLine($templates, $name, $line) { - $loader = new Twig_Loader_Array($templates); - $twig = new Twig_Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); + $loader = new \Twig\Loader\ArrayLoader($templates); + $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index'); @@ -135,7 +135,7 @@ public function testTwigExceptionAddsFileAndLine($templates, $name, $line) $template->render([]); $this->fail(); - } catch (Twig_Error_Runtime $e) { + } catch (\Twig\Error\RuntimeError $e) { $this->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d.', $name, $line), $e->getMessage()); $this->assertEquals($line, $e->getTemplateLine()); $this->assertEquals($name, $e->getSourceContext()->getName()); @@ -145,7 +145,7 @@ public function testTwigExceptionAddsFileAndLine($templates, $name, $line) $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); $this->fail(); - } catch (Twig_Error_Runtime $e) { + } catch (\Twig\Error\RuntimeError $e) { $this->assertEquals(sprintf('An exception has been thrown during the rendering of a template ("Runtime error...") in "%s" at line %d.', $name, $line), $e->getMessage()); $this->assertEquals($line, $e->getTemplateLine()); $this->assertEquals($name, $e->getSourceContext()->getName()); diff --git a/test/Twig/Tests/ExpressionParserTest.php b/test/Twig/Tests/ExpressionParserTest.php index 64a47f24a0..6982c66bf8 100644 --- a/test/Twig/Tests/ExpressionParserTest.php +++ b/test/Twig/Tests/ExpressionParserTest.php @@ -12,15 +12,15 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase { /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @dataProvider getFailingTestsForAssignment */ public function testCanOnlyAssignToNames($template) { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source($template, 'index'))); + $parser->parse($env->tokenize(new \Twig\Source($template, 'index'))); } public function getFailingTestsForAssignment() @@ -46,23 +46,23 @@ public function getFailingTestsForAssignment() */ public function testArrayExpression($template, $expected) { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $stream = $env->tokenize(new Twig_Source($template, '')); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $stream = $env->tokenize(new \Twig\Source($template, '')); + $parser = new \Twig\Parser($env); $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @dataProvider getFailingTestsForArray */ public function testArraySyntaxError($template) { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source($template, 'index'))); + $parser->parse($env->tokenize(new \Twig\Source($template, 'index'))); } public function getFailingTestsForArray() @@ -77,86 +77,86 @@ public function getTestsForArray() { return [ // simple array - ['{{ [1, 2] }}', new Twig_Node_Expression_Array([ - new Twig_Node_Expression_Constant(0, 1), - new Twig_Node_Expression_Constant(1, 1), + ['{{ [1, 2] }}', new \Twig\Node\Expression\ArrayExpression([ + new \Twig\Node\Expression\ConstantExpression(0, 1), + new \Twig\Node\Expression\ConstantExpression(1, 1), - new Twig_Node_Expression_Constant(1, 1), - new Twig_Node_Expression_Constant(2, 1), + new \Twig\Node\Expression\ConstantExpression(1, 1), + new \Twig\Node\Expression\ConstantExpression(2, 1), ], 1), ], // array with trailing , - ['{{ [1, 2, ] }}', new Twig_Node_Expression_Array([ - new Twig_Node_Expression_Constant(0, 1), - new Twig_Node_Expression_Constant(1, 1), + ['{{ [1, 2, ] }}', new \Twig\Node\Expression\ArrayExpression([ + new \Twig\Node\Expression\ConstantExpression(0, 1), + new \Twig\Node\Expression\ConstantExpression(1, 1), - new Twig_Node_Expression_Constant(1, 1), - new Twig_Node_Expression_Constant(2, 1), + new \Twig\Node\Expression\ConstantExpression(1, 1), + new \Twig\Node\Expression\ConstantExpression(2, 1), ], 1), ], // simple hash - ['{{ {"a": "b", "b": "c"} }}', new Twig_Node_Expression_Array([ - new Twig_Node_Expression_Constant('a', 1), - new Twig_Node_Expression_Constant('b', 1), + ['{{ {"a": "b", "b": "c"} }}', new \Twig\Node\Expression\ArrayExpression([ + new \Twig\Node\Expression\ConstantExpression('a', 1), + new \Twig\Node\Expression\ConstantExpression('b', 1), - new Twig_Node_Expression_Constant('b', 1), - new Twig_Node_Expression_Constant('c', 1), + new \Twig\Node\Expression\ConstantExpression('b', 1), + new \Twig\Node\Expression\ConstantExpression('c', 1), ], 1), ], // hash with trailing , - ['{{ {"a": "b", "b": "c", } }}', new Twig_Node_Expression_Array([ - new Twig_Node_Expression_Constant('a', 1), - new Twig_Node_Expression_Constant('b', 1), + ['{{ {"a": "b", "b": "c", } }}', new \Twig\Node\Expression\ArrayExpression([ + new \Twig\Node\Expression\ConstantExpression('a', 1), + new \Twig\Node\Expression\ConstantExpression('b', 1), - new Twig_Node_Expression_Constant('b', 1), - new Twig_Node_Expression_Constant('c', 1), + new \Twig\Node\Expression\ConstantExpression('b', 1), + new \Twig\Node\Expression\ConstantExpression('c', 1), ], 1), ], // hash in an array - ['{{ [1, {"a": "b", "b": "c"}] }}', new Twig_Node_Expression_Array([ - new Twig_Node_Expression_Constant(0, 1), - new Twig_Node_Expression_Constant(1, 1), + ['{{ [1, {"a": "b", "b": "c"}] }}', new \Twig\Node\Expression\ArrayExpression([ + new \Twig\Node\Expression\ConstantExpression(0, 1), + new \Twig\Node\Expression\ConstantExpression(1, 1), - new Twig_Node_Expression_Constant(1, 1), - new Twig_Node_Expression_Array([ - new Twig_Node_Expression_Constant('a', 1), - new Twig_Node_Expression_Constant('b', 1), + new \Twig\Node\Expression\ConstantExpression(1, 1), + new \Twig\Node\Expression\ArrayExpression([ + new \Twig\Node\Expression\ConstantExpression('a', 1), + new \Twig\Node\Expression\ConstantExpression('b', 1), - new Twig_Node_Expression_Constant('b', 1), - new Twig_Node_Expression_Constant('c', 1), + new \Twig\Node\Expression\ConstantExpression('b', 1), + new \Twig\Node\Expression\ConstantExpression('c', 1), ], 1), ], 1), ], // array in a hash - ['{{ {"a": [1, 2], "b": "c"} }}', new Twig_Node_Expression_Array([ - new Twig_Node_Expression_Constant('a', 1), - new Twig_Node_Expression_Array([ - new Twig_Node_Expression_Constant(0, 1), - new Twig_Node_Expression_Constant(1, 1), - - new Twig_Node_Expression_Constant(1, 1), - new Twig_Node_Expression_Constant(2, 1), + ['{{ {"a": [1, 2], "b": "c"} }}', new \Twig\Node\Expression\ArrayExpression([ + new \Twig\Node\Expression\ConstantExpression('a', 1), + new \Twig\Node\Expression\ArrayExpression([ + new \Twig\Node\Expression\ConstantExpression(0, 1), + new \Twig\Node\Expression\ConstantExpression(1, 1), + + new \Twig\Node\Expression\ConstantExpression(1, 1), + new \Twig\Node\Expression\ConstantExpression(2, 1), ], 1), - new Twig_Node_Expression_Constant('b', 1), - new Twig_Node_Expression_Constant('c', 1), + new \Twig\Node\Expression\ConstantExpression('b', 1), + new \Twig\Node\Expression\ConstantExpression('c', 1), ], 1), ], ]; } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError */ public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); - $stream = $env->tokenize(new Twig_Source('{{ "a" "b" }}', 'index')); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); + $stream = $env->tokenize(new \Twig\Source('{{ "a" "b" }}', 'index')); + $parser = new \Twig\Parser($env); $parser->parse($stream); } @@ -166,9 +166,9 @@ public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings() */ public function testStringExpression($template, $expected) { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); - $stream = $env->tokenize(new Twig_Source($template, '')); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); + $stream = $env->tokenize(new \Twig\Source($template, '')); + $parser = new \Twig\Parser($env); $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); } @@ -177,43 +177,43 @@ public function getTestsForString() { return [ [ - '{{ "foo" }}', new Twig_Node_Expression_Constant('foo', 1), + '{{ "foo" }}', new \Twig\Node\Expression\ConstantExpression('foo', 1), ], [ - '{{ "foo #{bar}" }}', new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Constant('foo ', 1), - new Twig_Node_Expression_Name('bar', 1), + '{{ "foo #{bar}" }}', new \Twig\Node\Expression\Binary\ConcatBinary( + new \Twig\Node\Expression\ConstantExpression('foo ', 1), + new \Twig\Node\Expression\NameExpression('bar', 1), 1 ), ], [ - '{{ "foo #{bar} baz" }}', new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Constant('foo ', 1), - new Twig_Node_Expression_Name('bar', 1), + '{{ "foo #{bar} baz" }}', new \Twig\Node\Expression\Binary\ConcatBinary( + new \Twig\Node\Expression\Binary\ConcatBinary( + new \Twig\Node\Expression\ConstantExpression('foo ', 1), + new \Twig\Node\Expression\NameExpression('bar', 1), 1 ), - new Twig_Node_Expression_Constant(' baz', 1), + new \Twig\Node\Expression\ConstantExpression(' baz', 1), 1 ), ], [ - '{{ "foo #{"foo #{bar} baz"} baz" }}', new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Constant('foo ', 1), - new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Constant('foo ', 1), - new Twig_Node_Expression_Name('bar', 1), + '{{ "foo #{"foo #{bar} baz"} baz" }}', new \Twig\Node\Expression\Binary\ConcatBinary( + new \Twig\Node\Expression\Binary\ConcatBinary( + new \Twig\Node\Expression\ConstantExpression('foo ', 1), + new \Twig\Node\Expression\Binary\ConcatBinary( + new \Twig\Node\Expression\Binary\ConcatBinary( + new \Twig\Node\Expression\ConstantExpression('foo ', 1), + new \Twig\Node\Expression\NameExpression('bar', 1), 1 ), - new Twig_Node_Expression_Constant(' baz', 1), + new \Twig\Node\Expression\ConstantExpression(' baz', 1), 1 ), 1 ), - new Twig_Node_Expression_Constant(' baz', 1), + new \Twig\Node\Expression\ConstantExpression(' baz', 1), 1 ), ], @@ -221,50 +221,50 @@ public function getTestsForString() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError */ public function testAttributeCallDoesNotSupportNamedArguments() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source('{{ foo.bar(name="Foo") }}', 'index'))); + $parser->parse($env->tokenize(new \Twig\Source('{{ foo.bar(name="Foo") }}', 'index'))); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError */ public function testMacroCallDoesNotSupportNamedArguments() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index'))); + $parser->parse($env->tokenize(new \Twig\Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index'))); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1. */ public function testMacroDefinitionDoesNotSupportNonNameVariableName() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source('{% macro foo("a") %}{% endmacro %}', 'index'))); + $parser->parse($env->tokenize(new \Twig\Source('{% macro foo("a") %}{% endmacro %}', 'index'))); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1 * @dataProvider getMacroDefinitionDoesNotSupportNonConstantDefaultValues */ public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template) { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source($template, 'index'))); + $parser->parse($env->tokenize(new \Twig\Source($template, 'index'))); } public function getMacroDefinitionDoesNotSupportNonConstantDefaultValues() @@ -280,10 +280,10 @@ public function getMacroDefinitionDoesNotSupportNonConstantDefaultValues() */ public function testMacroDefinitionSupportsConstantDefaultValues($template) { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source($template, 'index'))); + $parser->parse($env->tokenize(new \Twig\Source($template, 'index'))); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -304,74 +304,74 @@ public function getMacroDefinitionSupportsConstantDefaultValues() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown "cycl" function. Did you mean "cycle" in "index" at line 1? */ public function testUnknownFunction() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source('{{ cycl() }}', 'index'))); + $parser->parse($env->tokenize(new \Twig\Source('{{ cycl() }}', 'index'))); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown "foobar" function in "index" at line 1. */ public function testUnknownFunctionWithoutSuggestions() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source('{{ foobar() }}', 'index'))); + $parser->parse($env->tokenize(new \Twig\Source('{{ foobar() }}', 'index'))); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown "lowe" filter. Did you mean "lower" in "index" at line 1? */ public function testUnknownFilter() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source('{{ 1|lowe }}', 'index'))); + $parser->parse($env->tokenize(new \Twig\Source('{{ 1|lowe }}', 'index'))); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown "foobar" filter in "index" at line 1. */ public function testUnknownFilterWithoutSuggestions() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source('{{ 1|foobar }}', 'index'))); + $parser->parse($env->tokenize(new \Twig\Source('{{ 1|foobar }}', 'index'))); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown "nul" test. Did you mean "null" in "index" at line 1 */ public function testUnknownTest() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); - $stream = $env->tokenize(new Twig_Source('{{ 1 is nul }}', 'index')); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); + $stream = $env->tokenize(new \Twig\Source('{{ 1 is nul }}', 'index')); $parser->parse($stream); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown "foobar" test in "index" at line 1. */ public function testUnknownTestWithoutSuggestions() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new Twig_Parser($env); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new \Twig\Parser($env); - $parser->parse($env->tokenize(new Twig_Source('{{ 1 is foobar }}', 'index'))); + $parser->parse($env->tokenize(new \Twig\Source('{{ 1 is foobar }}', 'index'))); } } diff --git a/test/Twig/Tests/Extension/CoreTest.php b/test/Twig/Tests/Extension/CoreTest.php index 61f29099cc..a8b707b145 100644 --- a/test/Twig/Tests/Extension/CoreTest.php +++ b/test/Twig/Tests/Extension/CoreTest.php @@ -16,7 +16,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase */ public function testRandomFunction($value, $expectedInArray) { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); for ($i = 0; $i < 100; ++$i) { $this->assertTrue(\in_array(twig_random($env, $value), $expectedInArray, true)); // assertContains() would not consider the type @@ -62,26 +62,26 @@ public function testRandomFunctionWithoutParameter() $max = mt_getrandmax(); for ($i = 0; $i < 100; ++$i) { - $val = twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $val = twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $this->assertTrue(\is_int($val) && $val >= 0 && $val <= $max); } } public function testRandomFunctionReturnsAsIs() { - $this->assertSame('', twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), '')); - $this->assertSame('', twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['charset' => null]), '')); + $this->assertSame('', twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), '')); + $this->assertSame('', twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['charset' => null]), '')); $instance = new \stdClass(); - $this->assertSame($instance, twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), $instance)); + $this->assertSame($instance, twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), $instance)); } /** - * @expectedException \Twig_Error_Runtime + * @expectedException \Twig\Error\RuntimeError */ public function testRandomFunctionOfEmptyArrayThrowsException() { - twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), []); + twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), []); } public function testRandomFunctionOnNonUTF8String() @@ -90,7 +90,7 @@ public function testRandomFunctionOnNonUTF8String() $this->markTestSkipped('needs iconv or mbstring'); } - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->setCharset('ISO-8859-1'); $text = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8'); @@ -106,7 +106,7 @@ public function testReverseFilterOnNonUTF8String() $this->markTestSkipped('needs iconv or mbstring'); } - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->setCharset('ISO-8859-1'); $input = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8'); @@ -120,8 +120,8 @@ public function testReverseFilterOnNonUTF8String() */ public function testCustomEscaper($expected, $string, $strategy) { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $twig->getExtension('Twig_Extension_Core')->setEscaper('foo', 'foo_escaper_for_test'); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig->getExtension('\Twig\Extension\CoreExtension')->setEscaper('foo', 'foo_escaper_for_test'); $this->assertSame($expected, twig_escape_filter($twig, $string, $strategy)); } @@ -136,11 +136,11 @@ public function provideCustomEscaperCases() } /** - * @expectedException \Twig_Error_Runtime + * @expectedException \Twig\Error\RuntimeError */ public function testUnknownCustomEscaper() { - twig_escape_filter(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), 'foo', 'bar'); + twig_escape_filter(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), 'foo', 'bar'); } /** @@ -148,7 +148,7 @@ public function testUnknownCustomEscaper() */ public function testTwigFirst($expected, $input) { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $this->assertSame($expected, twig_first($twig, $input)); } @@ -170,7 +170,7 @@ public function provideTwigFirstCases() */ public function testTwigLast($expected, $input) { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $this->assertSame($expected, twig_last($twig, $input)); } @@ -243,7 +243,7 @@ public function provideInFilterCases() */ public function testSliceFilter($expected, $input, $start, $length = null, $preserveKeys = false) { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $this->assertSame($expected, twig_slice($twig, $input, $start, $length, $preserveKeys)); } diff --git a/test/Twig/Tests/Extension/SandboxTest.php b/test/Twig/Tests/Extension/SandboxTest.php index a9177736c6..5e49f9f0ce 100644 --- a/test/Twig/Tests/Extension/SandboxTest.php +++ b/test/Twig/Tests/Extension/SandboxTest.php @@ -41,7 +41,7 @@ protected function setUp() } /** - * @expectedException \Twig_Sandbox_SecurityError + * @expectedException \Twig\Sandbox\SecurityError * @expectedExceptionMessage Filter "json_encode" is not allowed in "1_child" at line 3. */ public function testSandboxWithInheritance() @@ -62,8 +62,8 @@ public function testSandboxUnallowedMethodAccessor() try { $twig->loadTemplate('1_basic1')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method is called'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class'); $this->assertEquals('foo', $e->getMethodName(), 'Exception should be raised on the "foo" method'); } @@ -75,8 +75,8 @@ public function testSandboxUnallowedFilter() try { $twig->loadTemplate('1_basic2')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError'); $this->assertEquals('upper', $e->getFilterName(), 'Exception should be raised on the "upper" filter'); } } @@ -87,8 +87,8 @@ public function testSandboxUnallowedTag() try { $twig->loadTemplate('1_basic3')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed tag is used in the template'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); $this->assertEquals('if', $e->getTagName(), 'Exception should be raised on the "if" tag'); } } @@ -99,8 +99,8 @@ public function testSandboxUnallowedProperty() try { $twig->loadTemplate('1_basic4')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed property is called in the template'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedPropertyError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedPropertyError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError'); $this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class'); $this->assertEquals('bar', $e->getPropertyName(), 'Exception should be raised on the "bar" property'); } @@ -112,8 +112,8 @@ public function testSandboxUnallowedToString() try { $twig->loadTemplate('1_basic5')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class'); $this->assertEquals('__tostring', $e->getMethodName(), 'Exception should be raised on the "__toString" method'); } @@ -125,8 +125,8 @@ public function testSandboxUnallowedToStringArray() try { $twig->loadTemplate('1_basic6')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class'); $this->assertEquals('__tostring', $e->getMethodName(), 'Exception should be raised on the "__toString" method'); } @@ -138,8 +138,8 @@ public function testSandboxUnallowedFunction() try { $twig->loadTemplate('1_basic7')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed function is called in the template'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); $this->assertEquals('cycle', $e->getFunctionName(), 'Exception should be raised on the "cycle" function'); } } @@ -150,8 +150,8 @@ public function testSandboxUnallowedRangeOperator() try { $twig->loadTemplate('1_range_operator')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if the unallowed range operator is called'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); $this->assertEquals('range', $e->getFunctionName(), 'Exception should be raised on the "range" function'); } } @@ -241,8 +241,8 @@ public function testSandboxLocallySetForAnInclude() try { $twig->loadTemplate('3_basic')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception when the included file is sandboxed'); - } catch (Twig_Sandbox_SecurityError $e) { - $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); + } catch (\Twig\Sandbox\SecurityError $e) { + $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); $this->assertEquals('sandbox', $e->getTagName()); } } @@ -275,15 +275,15 @@ public function testSandboxDisabledAfterIncludeFunctionError() $this->fail('An exception should be thrown for this test to be valid.'); } - $this->assertFalse($twig->getExtension('Twig_Extension_Sandbox')->isSandboxed(), 'Sandboxed include() function call should not leave Sandbox enabled when an error occurs.'); + $this->assertFalse($twig->getExtension('\Twig\Extension\SandboxExtension')->isSandboxed(), 'Sandboxed include() function call should not leave Sandbox enabled when an error occurs.'); } protected function getEnvironment($sandboxed, $options, $templates, $tags = [], $filters = [], $methods = [], $properties = [], $functions = []) { - $loader = new Twig_Loader_Array($templates); - $twig = new Twig_Environment($loader, array_merge(['debug' => true, 'cache' => false, 'autoescape' => false], $options)); - $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions); - $twig->addExtension(new Twig_Extension_Sandbox($policy, $sandboxed)); + $loader = new \Twig\Loader\ArrayLoader($templates); + $twig = new \Twig\Environment($loader, array_merge(['debug' => true, 'cache' => false, 'autoescape' => false], $options)); + $policy = new \Twig\Sandbox\SecurityPolicy($tags, $filters, $methods, $properties, $functions); + $twig->addExtension(new \Twig\Extension\SandboxExtension($policy, $sandboxed)); return $twig; } diff --git a/test/Twig/Tests/FactoryRuntimeLoaderTest.php b/test/Twig/Tests/FactoryRuntimeLoaderTest.php index 59da9c2adf..59328eeea0 100644 --- a/test/Twig/Tests/FactoryRuntimeLoaderTest.php +++ b/test/Twig/Tests/FactoryRuntimeLoaderTest.php @@ -13,14 +13,14 @@ class Twig_Tests_FactoryRuntimeLoaderTest extends \PHPUnit\Framework\TestCase { public function testLoad() { - $loader = new Twig_FactoryRuntimeLoader(['stdClass' => 'getRuntime']); + $loader = new \Twig\RuntimeLoader\FactoryRuntimeLoader(['stdClass' => 'getRuntime']); $this->assertInstanceOf('stdClass', $loader->load('stdClass')); } public function testLoadReturnsNullForUnmappedRuntime() { - $loader = new Twig_FactoryRuntimeLoader(); + $loader = new \Twig\RuntimeLoader\FactoryRuntimeLoader(); $this->assertNull($loader->load('stdClass')); } diff --git a/test/Twig/Tests/FileCachingTest.php b/test/Twig/Tests/FileCachingTest.php index df5344573f..640f13b4af 100644 --- a/test/Twig/Tests/FileCachingTest.php +++ b/test/Twig/Tests/FileCachingTest.php @@ -27,7 +27,7 @@ protected function setUp() $this->markTestSkipped(sprintf('Unable to run the tests as "%s" is not writable.', $this->tmpDir)); } - $this->env = new Twig_Environment(new Twig_Loader_Array(['index' => 'index', 'index2' => 'index2']), ['cache' => $this->tmpDir]); + $this->env = new \Twig\Environment(new \Twig\Loader\ArrayLoader(['index' => 'index', 'index2' => 'index2']), ['cache' => $this->tmpDir]); } protected function tearDown() diff --git a/test/Twig/Tests/FileExtensionEscapingStrategyTest.php b/test/Twig/Tests/FileExtensionEscapingStrategyTest.php index 6cdff00fac..a6959744be 100644 --- a/test/Twig/Tests/FileExtensionEscapingStrategyTest.php +++ b/test/Twig/Tests/FileExtensionEscapingStrategyTest.php @@ -16,7 +16,7 @@ class Twig_Tests_FileExtensionEscapingStrategyTest extends \PHPUnit\Framework\Te */ public function testGuess($strategy, $filename) { - $this->assertSame($strategy, Twig_FileExtensionEscapingStrategy::guess($filename)); + $this->assertSame($strategy, \Twig\FileExtensionEscapingStrategy::guess($filename)); } public function getGuessData() diff --git a/test/Twig/Tests/Fixtures/filters/date_default_format.test b/test/Twig/Tests/Fixtures/filters/date_default_format.test index bd27863684..c6e81302df 100644 --- a/test/Twig/Tests/Fixtures/filters/date_default_format.test +++ b/test/Twig/Tests/Fixtures/filters/date_default_format.test @@ -5,7 +5,7 @@ {{ date1|date('d/m/Y') }} --DATA-- date_default_timezone_set('UTC'); -$twig->getExtension('Twig_Extension_Core')->setDateFormat('Y-m-d', '%d days %h hours'); +$twig->getExtension('\Twig\Extension\CoreExtension')->setDateFormat('Y-m-d', '%d days %h hours'); return [ 'date1' => mktime(13, 45, 0, 10, 4, 2010), ] diff --git a/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test b/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test index 88d663be2e..a72fb81d62 100644 --- a/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test +++ b/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test @@ -7,7 +7,7 @@ version_compare(phpversion(), '5.3.0', '>=') {{ date2|date('%d days') }} --DATA-- date_default_timezone_set('UTC'); -$twig->getExtension('Twig_Extension_Core')->setDateFormat('Y-m-d', '%d days %h hours'); +$twig->getExtension('\Twig\Extension\CoreExtension')->setDateFormat('Y-m-d', '%d days %h hours'); return [ 'date2' => new \DateInterval('P2D'), ] diff --git a/test/Twig/Tests/Fixtures/filters/json_encode.test b/test/Twig/Tests/Fixtures/filters/json_encode.test index ea45218f63..902f90b337 100644 --- a/test/Twig/Tests/Fixtures/filters/json_encode.test +++ b/test/Twig/Tests/Fixtures/filters/json_encode.test @@ -5,7 +5,7 @@ {{ foo|json_encode|raw }} {{ [foo, "foo"]|json_encode|raw }} --DATA-- -return ['foo' => new Twig_Markup('foo', 'UTF-8')] +return ['foo' => new \Twig\Markup('foo', 'UTF-8')] --EXPECT-- "foo" "foo" diff --git a/test/Twig/Tests/Fixtures/filters/length_utf8.test b/test/Twig/Tests/Fixtures/filters/length_utf8.test index be2170715b..b1e9681a5d 100644 --- a/test/Twig/Tests/Fixtures/filters/length_utf8.test +++ b/test/Twig/Tests/Fixtures/filters/length_utf8.test @@ -6,7 +6,7 @@ function_exists('mb_get_info') {{ string|length }} {{ markup|length }} --DATA-- -return ['string' => 'été', 'markup' => new Twig_Markup('foo', 'UTF-8')] +return ['string' => 'été', 'markup' => new \Twig\Markup('foo', 'UTF-8')] --EXPECT-- 3 3 diff --git a/test/Twig/Tests/Fixtures/filters/number_format_default.test b/test/Twig/Tests/Fixtures/filters/number_format_default.test index c550bb6740..beedd901a0 100644 --- a/test/Twig/Tests/Fixtures/filters/number_format_default.test +++ b/test/Twig/Tests/Fixtures/filters/number_format_default.test @@ -9,7 +9,7 @@ {{ 1020.25|number_format(2, ',') }} {{ 1020.25|number_format(2, ',', '.') }} --DATA-- -$twig->getExtension('Twig_Extension_Core')->setNumberFormat(2, '!', '='); +$twig->getExtension('\Twig\Extension\CoreExtension')->setNumberFormat(2, '!', '='); return [] --EXPECT-- 20!00 diff --git a/test/Twig/Tests/Fixtures/tests/empty.test b/test/Twig/Tests/Fixtures/tests/empty.test index f227cda957..3e7fcf0183 100644 --- a/test/Twig/Tests/Fixtures/tests/empty.test +++ b/test/Twig/Tests/Fixtures/tests/empty.test @@ -23,7 +23,7 @@ return [ 'magically_callable' => new MagicCallStub(), 'countable_empty' => new CountableStub([]), 'countable_not_empty' => new CountableStub([1, 2]), 'tostring_empty' => new ToStringStub(''), 'tostring_not_empty' => new ToStringStub('0' /* edge case of using "0" as the string */), - 'markup_empty' => new Twig_Markup('', 'UTF-8'), 'markup_not_empty' => new Twig_Markup('test', 'UTF-8'), + 'markup_empty' => new \Twig\Markup('', 'UTF-8'), 'markup_not_empty' => new \Twig\Markup('test', 'UTF-8'), ] --EXPECT-- ok diff --git a/test/Twig/Tests/IntegrationTest.php b/test/Twig/Tests/IntegrationTest.php index 9afc0b1b5c..1cef44929b 100644 --- a/test/Twig/Tests/IntegrationTest.php +++ b/test/Twig/Tests/IntegrationTest.php @@ -16,16 +16,16 @@ function html() return 'foo'; } -class Twig_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase +class Twig_Tests_IntegrationTest extends \Twig\Test\IntegrationTestCase { public function getExtensions() { - $policy = new Twig_Sandbox_SecurityPolicy([], [], [], [], []); + $policy = new \Twig\Sandbox\SecurityPolicy([], [], [], [], []); return [ - new Twig_Extension_Debug(), - new Twig_Extension_Sandbox($policy, false), - new Twig_Extension_StringLoader(), + new \Twig\Extension\DebugExtension(), + new \Twig\Extension\SandboxExtension($policy, false), + new \Twig\Extension\StringLoaderExtension(), new TwigTestExtension(), ]; } @@ -109,13 +109,13 @@ public function valid() } } -class TwigTestTokenParser_§ extends Twig_TokenParser +class TwigTestTokenParser_§ extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node_Print(new Twig_Node_Expression_Constant('§', -1), -1); + return new \Twig\Node\PrintNode(new \Twig\Node\Expression\ConstantExpression('§', -1), -1); } public function getTag() @@ -124,7 +124,7 @@ public function getTag() } } -class TwigTestExtension extends Twig_Extension +class TwigTestExtension extends \Twig\Extension\AbstractExtension { public function getTokenParsers() { @@ -136,39 +136,39 @@ public function getTokenParsers() public function getFilters() { return [ - new Twig_SimpleFilter('§', [$this, '§Filter']), - new Twig_SimpleFilter('escape_and_nl2br', [$this, 'escape_and_nl2br'], ['needs_environment' => true, 'is_safe' => ['html']]), - new Twig_SimpleFilter('nl2br', [$this, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]), - new Twig_SimpleFilter('escape_something', [$this, 'escape_something'], ['is_safe' => ['something']]), - new Twig_SimpleFilter('preserves_safety', [$this, 'preserves_safety'], ['preserves_safety' => ['html']]), - new Twig_SimpleFilter('static_call_string', 'TwigTestExtension::staticCall'), - new Twig_SimpleFilter('static_call_array', ['TwigTestExtension', 'staticCall']), - new Twig_SimpleFilter('magic_call', [$this, 'magicCall']), - new Twig_SimpleFilter('magic_call_string', 'TwigTestExtension::magicStaticCall'), - new Twig_SimpleFilter('magic_call_array', ['TwigTestExtension', 'magicStaticCall']), - new Twig_SimpleFilter('*_path', [$this, 'dynamic_path']), - new Twig_SimpleFilter('*_foo_*_bar', [$this, 'dynamic_foo']), + new \Twig\TwigFilter('§', [$this, '§Filter']), + new \Twig\TwigFilter('escape_and_nl2br', [$this, 'escape_and_nl2br'], ['needs_environment' => true, 'is_safe' => ['html']]), + new \Twig\TwigFilter('nl2br', [$this, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]), + new \Twig\TwigFilter('escape_something', [$this, 'escape_something'], ['is_safe' => ['something']]), + new \Twig\TwigFilter('preserves_safety', [$this, 'preserves_safety'], ['preserves_safety' => ['html']]), + new \Twig\TwigFilter('static_call_string', 'TwigTestExtension::staticCall'), + new \Twig\TwigFilter('static_call_array', ['TwigTestExtension', 'staticCall']), + new \Twig\TwigFilter('magic_call', [$this, 'magicCall']), + new \Twig\TwigFilter('magic_call_string', 'TwigTestExtension::magicStaticCall'), + new \Twig\TwigFilter('magic_call_array', ['TwigTestExtension', 'magicStaticCall']), + new \Twig\TwigFilter('*_path', [$this, 'dynamic_path']), + new \Twig\TwigFilter('*_foo_*_bar', [$this, 'dynamic_foo']), ]; } public function getFunctions() { return [ - new Twig_SimpleFunction('§', [$this, '§Function']), - new Twig_SimpleFunction('safe_br', [$this, 'br'], ['is_safe' => ['html']]), - new Twig_SimpleFunction('unsafe_br', [$this, 'br']), - new Twig_SimpleFunction('static_call_string', 'TwigTestExtension::staticCall'), - new Twig_SimpleFunction('static_call_array', ['TwigTestExtension', 'staticCall']), - new Twig_SimpleFunction('*_path', [$this, 'dynamic_path']), - new Twig_SimpleFunction('*_foo_*_bar', [$this, 'dynamic_foo']), + new \Twig\TwigFunction('§', [$this, '§Function']), + new \Twig\TwigFunction('safe_br', [$this, 'br'], ['is_safe' => ['html']]), + new \Twig\TwigFunction('unsafe_br', [$this, 'br']), + new \Twig\TwigFunction('static_call_string', 'TwigTestExtension::staticCall'), + new \Twig\TwigFunction('static_call_array', ['TwigTestExtension', 'staticCall']), + new \Twig\TwigFunction('*_path', [$this, 'dynamic_path']), + new \Twig\TwigFunction('*_foo_*_bar', [$this, 'dynamic_foo']), ]; } public function getTests() { return [ - new Twig_SimpleTest('multi word', [$this, 'is_multi_word']), - new Twig_SimpleTest('test_*', [$this, 'dynamic_test']), + new \Twig\TwigTest('multi word', [$this, 'is_multi_word']), + new \Twig\TwigTest('test_*', [$this, 'dynamic_test']), ]; } diff --git a/test/Twig/Tests/LegacyIntegrationTest.php b/test/Twig/Tests/LegacyIntegrationTest.php index fce3eac8c7..578609546a 100644 --- a/test/Twig/Tests/LegacyIntegrationTest.php +++ b/test/Twig/Tests/LegacyIntegrationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -class Twig_Tests_LegacyIntegrationTest extends Twig_Test_IntegrationTestCase +class Twig_Tests_LegacyIntegrationTest extends \Twig\Test\IntegrationTestCase { public function getExtensions() { @@ -33,7 +33,7 @@ public function getTests($name, $legacyTests = false) } } -class LegacyTwigTestExtension extends Twig_Extension +class LegacyTwigTestExtension extends \Twig\Extension\AbstractExtension { public function getTests() { diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php index c7521a7cde..8984c7f341 100644 --- a/test/Twig/Tests/LexerTest.php +++ b/test/Twig/Tests/LexerTest.php @@ -15,7 +15,7 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase */ public function testLegacyConstructorSignature() { - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $stream = $lexer->tokenize('{{ foo }}', 'foo'); $this->assertEquals('foo', $stream->getFilename()); $this->assertEquals('{{ foo }}', $stream->getSource()); @@ -25,36 +25,36 @@ public function testNameLabelForTag() { $template = '{% § %}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(Twig_Token::BLOCK_START_TYPE); - $this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue()); + $stream->expect(\Twig\Token::BLOCK_START_TYPE); + $this->assertSame('§', $stream->expect(\Twig\Token::NAME_TYPE)->getValue()); } public function testNameLabelForFunction() { $template = '{{ §() }}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(Twig_Token::VAR_START_TYPE); - $this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue()); + $stream->expect(\Twig\Token::VAR_START_TYPE); + $this->assertSame('§', $stream->expect(\Twig\Token::NAME_TYPE)->getValue()); } public function testBracketsNesting() { $template = '{{ {"a":{"b":"c"}} }}'; - $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '{')); - $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '}')); + $this->assertEquals(2, $this->countToken($template, \Twig\Token::PUNCTUATION_TYPE, '{')); + $this->assertEquals(2, $this->countToken($template, \Twig\Token::PUNCTUATION_TYPE, '}')); } protected function countToken($template, $type, $value = null) { - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); $count = 0; while (!$stream->isEOF()) { @@ -78,17 +78,17 @@ public function testLineDirective() ."baz\n" ."}}\n"; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); // foo\nbar\n - $this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine()); + $this->assertSame(1, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine()); // \n (after {% line %}) - $this->assertSame(10, $stream->expect(Twig_Token::TEXT_TYPE)->getLine()); + $this->assertSame(10, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine()); // {{ - $this->assertSame(11, $stream->expect(Twig_Token::VAR_START_TYPE)->getLine()); + $this->assertSame(11, $stream->expect(\Twig\Token::VAR_START_TYPE)->getLine()); // baz - $this->assertSame(12, $stream->expect(Twig_Token::NAME_TYPE)->getLine()); + $this->assertSame(12, $stream->expect(\Twig\Token::NAME_TYPE)->getLine()); } public function testLineDirectiveInline() @@ -98,23 +98,23 @@ public function testLineDirectiveInline() ."baz\n" ."}}\n"; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); // foo\nbar - $this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine()); + $this->assertSame(1, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine()); // {{ - $this->assertSame(10, $stream->expect(Twig_Token::VAR_START_TYPE)->getLine()); + $this->assertSame(10, $stream->expect(\Twig\Token::VAR_START_TYPE)->getLine()); // baz - $this->assertSame(11, $stream->expect(Twig_Token::NAME_TYPE)->getLine()); + $this->assertSame(11, $stream->expect(\Twig\Token::NAME_TYPE)->getLine()); } public function testLongComments() { $template = '{# '.str_repeat('*', 100000).' #}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new \Twig\Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -125,8 +125,8 @@ public function testLongVerbatim() { $template = '{% verbatim %}'.str_repeat('*', 100000).'{% endverbatim %}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new \Twig\Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -137,8 +137,8 @@ public function testLongVar() { $template = '{{ '.str_repeat('x', 100000).' }}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new \Twig\Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -149,8 +149,8 @@ public function testLongBlock() { $template = '{% '.str_repeat('x', 100000).' %}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new \Twig\Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -161,8 +161,8 @@ public function testBigNumbers() { $template = '{{ 922337203685477580700 }}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); $stream->next(); $node = $stream->next(); $this->assertEquals('922337203685477580700', $node->getValue()); @@ -174,11 +174,11 @@ public function testStringWithEscapedDelimiter() "{{ 'foo \' bar' }}" => 'foo \' bar', '{{ "foo \" bar" }}' => 'foo " bar', ]; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); foreach ($tests as $template => $expected) { - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); - $stream->expect(Twig_Token::VAR_START_TYPE); - $stream->expect(Twig_Token::STRING_TYPE, $expected); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $stream->expect(\Twig\Token::VAR_START_TYPE); + $stream->expect(\Twig\Token::STRING_TYPE, $expected); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -190,17 +190,17 @@ public function testStringWithInterpolation() { $template = 'foo {{ "bar #{ baz + 1 }" }}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); - $stream->expect(Twig_Token::TEXT_TYPE, 'foo '); - $stream->expect(Twig_Token::VAR_START_TYPE); - $stream->expect(Twig_Token::STRING_TYPE, 'bar '); - $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); - $stream->expect(Twig_Token::NAME_TYPE, 'baz'); - $stream->expect(Twig_Token::OPERATOR_TYPE, '+'); - $stream->expect(Twig_Token::NUMBER_TYPE, '1'); - $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); - $stream->expect(Twig_Token::VAR_END_TYPE); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $stream->expect(\Twig\Token::TEXT_TYPE, 'foo '); + $stream->expect(\Twig\Token::VAR_START_TYPE); + $stream->expect(\Twig\Token::STRING_TYPE, 'bar '); + $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); + $stream->expect(\Twig\Token::NAME_TYPE, 'baz'); + $stream->expect(\Twig\Token::OPERATOR_TYPE, '+'); + $stream->expect(\Twig\Token::NUMBER_TYPE, '1'); + $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); + $stream->expect(\Twig\Token::VAR_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -211,11 +211,11 @@ public function testStringWithEscapedInterpolation() { $template = '{{ "bar \#{baz+1}" }}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); - $stream->expect(Twig_Token::VAR_START_TYPE); - $stream->expect(Twig_Token::STRING_TYPE, 'bar #{baz+1}'); - $stream->expect(Twig_Token::VAR_END_TYPE); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $stream->expect(\Twig\Token::VAR_START_TYPE); + $stream->expect(\Twig\Token::STRING_TYPE, 'bar #{baz+1}'); + $stream->expect(\Twig\Token::VAR_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -226,11 +226,11 @@ public function testStringWithHash() { $template = '{{ "bar # baz" }}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); - $stream->expect(Twig_Token::VAR_START_TYPE); - $stream->expect(Twig_Token::STRING_TYPE, 'bar # baz'); - $stream->expect(Twig_Token::VAR_END_TYPE); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $stream->expect(\Twig\Token::VAR_START_TYPE); + $stream->expect(\Twig\Token::STRING_TYPE, 'bar # baz'); + $stream->expect(\Twig\Token::VAR_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -238,32 +238,32 @@ public function testStringWithHash() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unclosed """ */ public function testStringWithUnterminatedInterpolation() { $template = '{{ "bar #{x" }}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new \Twig\Source($template, 'index')); } public function testStringWithNestedInterpolations() { $template = '{{ "bar #{ "foo#{bar}" }" }}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); - $stream->expect(Twig_Token::VAR_START_TYPE); - $stream->expect(Twig_Token::STRING_TYPE, 'bar '); - $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); - $stream->expect(Twig_Token::STRING_TYPE, 'foo'); - $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); - $stream->expect(Twig_Token::NAME_TYPE, 'bar'); - $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); - $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); - $stream->expect(Twig_Token::VAR_END_TYPE); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $stream->expect(\Twig\Token::VAR_START_TYPE); + $stream->expect(\Twig\Token::STRING_TYPE, 'bar '); + $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); + $stream->expect(\Twig\Token::STRING_TYPE, 'foo'); + $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); + $stream->expect(\Twig\Token::NAME_TYPE, 'bar'); + $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); + $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); + $stream->expect(\Twig\Token::VAR_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -274,18 +274,18 @@ public function testStringWithNestedInterpolationsInBlock() { $template = '{% foo "bar #{ "foo#{bar}" }" %}'; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); - $stream->expect(Twig_Token::BLOCK_START_TYPE); - $stream->expect(Twig_Token::NAME_TYPE, 'foo'); - $stream->expect(Twig_Token::STRING_TYPE, 'bar '); - $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); - $stream->expect(Twig_Token::STRING_TYPE, 'foo'); - $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); - $stream->expect(Twig_Token::NAME_TYPE, 'bar'); - $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); - $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $stream->expect(\Twig\Token::BLOCK_START_TYPE); + $stream->expect(\Twig\Token::NAME_TYPE, 'foo'); + $stream->expect(\Twig\Token::STRING_TYPE, 'bar '); + $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); + $stream->expect(\Twig\Token::STRING_TYPE, 'foo'); + $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); + $stream->expect(\Twig\Token::NAME_TYPE, 'bar'); + $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); + $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -296,11 +296,11 @@ public function testOperatorEndingWithALetterAtTheEndOfALine() { $template = "{{ 1 and\n0}}"; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new Twig_Source($template, 'index')); - $stream->expect(Twig_Token::VAR_START_TYPE); - $stream->expect(Twig_Token::NUMBER_TYPE, 1); - $stream->expect(Twig_Token::OPERATOR_TYPE, 'and'); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $stream->expect(\Twig\Token::VAR_START_TYPE); + $stream->expect(\Twig\Token::NUMBER_TYPE, 1); + $stream->expect(\Twig\Token::OPERATOR_TYPE, 'and'); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -308,7 +308,7 @@ public function testOperatorEndingWithALetterAtTheEndOfALine() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unclosed "variable" in "index" at line 3 */ public function testUnterminatedVariable() @@ -322,12 +322,12 @@ public function testUnterminatedVariable() '; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new \Twig\Source($template, 'index')); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unclosed "block" in "index" at line 3 */ public function testUnterminatedBlock() @@ -341,7 +341,7 @@ public function testUnterminatedBlock() '; - $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $lexer->tokenize(new Twig_Source($template, 'index')); + $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new \Twig\Source($template, 'index')); } } diff --git a/test/Twig/Tests/Loader/ArrayTest.php b/test/Twig/Tests/Loader/ArrayTest.php index 74be2c80a0..bc9fa2ffa6 100644 --- a/test/Twig/Tests/Loader/ArrayTest.php +++ b/test/Twig/Tests/Loader/ArrayTest.php @@ -16,42 +16,42 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase */ public function testGetSource() { - $loader = new Twig_Loader_Array(['foo' => 'bar']); + $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']); $this->assertEquals('bar', $loader->getSource('foo')); } /** * @group legacy - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testGetSourceWhenTemplateDoesNotExist() { - $loader = new Twig_Loader_Array([]); + $loader = new \Twig\Loader\ArrayLoader([]); $loader->getSource('foo'); } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testGetSourceContextWhenTemplateDoesNotExist() { - $loader = new Twig_Loader_Array([]); + $loader = new \Twig\Loader\ArrayLoader([]); $loader->getSourceContext('foo'); } public function testGetCacheKey() { - $loader = new Twig_Loader_Array(['foo' => 'bar']); + $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']); $this->assertEquals('foo:bar', $loader->getCacheKey('foo')); } public function testGetCacheKeyWhenTemplateHasDuplicateContent() { - $loader = new Twig_Loader_Array([ + $loader = new \Twig\Loader\ArrayLoader([ 'foo' => 'bar', 'baz' => 'bar', ]); @@ -62,7 +62,7 @@ public function testGetCacheKeyWhenTemplateHasDuplicateContent() public function testGetCacheKeyIsProtectedFromEdgeCollisions() { - $loader = new Twig_Loader_Array([ + $loader = new \Twig\Loader\ArrayLoader([ 'foo__' => 'bar', 'foo' => '__bar', ]); @@ -72,18 +72,18 @@ public function testGetCacheKeyIsProtectedFromEdgeCollisions() } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testGetCacheKeyWhenTemplateDoesNotExist() { - $loader = new Twig_Loader_Array([]); + $loader = new \Twig\Loader\ArrayLoader([]); $loader->getCacheKey('foo'); } public function testSetTemplate() { - $loader = new Twig_Loader_Array([]); + $loader = new \Twig\Loader\ArrayLoader([]); $loader->setTemplate('foo', 'bar'); $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode()); @@ -91,16 +91,16 @@ public function testSetTemplate() public function testIsFresh() { - $loader = new Twig_Loader_Array(['foo' => 'bar']); + $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']); $this->assertTrue($loader->isFresh('foo', time())); } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testIsFreshWhenTemplateDoesNotExist() { - $loader = new Twig_Loader_Array([]); + $loader = new \Twig\Loader\ArrayLoader([]); $loader->isFresh('foo', time()); } @@ -108,7 +108,7 @@ public function testIsFreshWhenTemplateDoesNotExist() public function testTemplateReference() { $name = new Twig_Test_Loader_TemplateReference('foo'); - $loader = new Twig_Loader_Array(['foo' => 'bar']); + $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']); $loader->getCacheKey($name); $loader->getSourceContext($name); diff --git a/test/Twig/Tests/Loader/ChainTest.php b/test/Twig/Tests/Loader/ChainTest.php index a42ad932ad..609a979b93 100644 --- a/test/Twig/Tests/Loader/ChainTest.php +++ b/test/Twig/Tests/Loader/ChainTest.php @@ -16,9 +16,9 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase */ public function testGetSource() { - $loader = new Twig_Loader_Chain([ - new Twig_Loader_Array(['foo' => 'bar']), - new Twig_Loader_Array(['foo' => 'foobar', 'bar' => 'foo']), + $loader = new \Twig\Loader\ChainLoader([ + new \Twig\Loader\ArrayLoader(['foo' => 'bar']), + new \Twig\Loader\ArrayLoader(['foo' => 'foobar', 'bar' => 'foo']), ]); $this->assertEquals('bar', $loader->getSource('foo')); @@ -28,10 +28,10 @@ public function testGetSource() public function testGetSourceContext() { $path = __DIR__.'/../Fixtures'; - $loader = new Twig_Loader_Chain([ - new Twig_Loader_Array(['foo' => 'bar']), - new Twig_Loader_Array(['errors/index.html' => 'baz']), - new Twig_Loader_Filesystem([$path]), + $loader = new \Twig\Loader\ChainLoader([ + new \Twig\Loader\ArrayLoader(['foo' => 'bar']), + new \Twig\Loader\ArrayLoader(['errors/index.html' => 'baz']), + new \Twig\Loader\FilesystemLoader([$path]), ]); $this->assertEquals('foo', $loader->getSourceContext('foo')->getName()); @@ -47,31 +47,31 @@ public function testGetSourceContext() } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testGetSourceContextWhenTemplateDoesNotExist() { - $loader = new Twig_Loader_Chain([]); + $loader = new \Twig\Loader\ChainLoader([]); $loader->getSourceContext('foo'); } /** * @group legacy - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testGetSourceWhenTemplateDoesNotExist() { - $loader = new Twig_Loader_Chain([]); + $loader = new \Twig\Loader\ChainLoader([]); $loader->getSource('foo'); } public function testGetCacheKey() { - $loader = new Twig_Loader_Chain([ - new Twig_Loader_Array(['foo' => 'bar']), - new Twig_Loader_Array(['foo' => 'foobar', 'bar' => 'foo']), + $loader = new \Twig\Loader\ChainLoader([ + new \Twig\Loader\ArrayLoader(['foo' => 'bar']), + new \Twig\Loader\ArrayLoader(['foo' => 'foobar', 'bar' => 'foo']), ]); $this->assertEquals('foo:bar', $loader->getCacheKey('foo')); @@ -79,19 +79,19 @@ public function testGetCacheKey() } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testGetCacheKeyWhenTemplateDoesNotExist() { - $loader = new Twig_Loader_Chain([]); + $loader = new \Twig\Loader\ChainLoader([]); $loader->getCacheKey('foo'); } public function testAddLoader() { - $loader = new Twig_Loader_Chain(); - $loader->addLoader(new Twig_Loader_Array(['foo' => 'bar'])); + $loader = new \Twig\Loader\ChainLoader(); + $loader->addLoader(new \Twig\Loader\ArrayLoader(['foo' => 'bar'])); $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode()); } @@ -104,10 +104,10 @@ public function testExists() // can be removed in 2.0 $loader2 = $this->getMockBuilder('Twig_ChainTestLoaderInterface')->getMock(); - //$loader2 = $this->getMockBuilder(['Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'])->getMock(); - $loader2->expects($this->once())->method('getSourceContext')->will($this->returnValue(new Twig_Source('content', 'index'))); + //$loader2 = $this->getMockBuilder(['\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface'])->getMock(); + $loader2->expects($this->once())->method('getSourceContext')->will($this->returnValue(new \Twig\Source('content', 'index'))); - $loader = new Twig_Loader_Chain(); + $loader = new \Twig\Loader\ChainLoader(); $loader->addLoader($loader1); $loader->addLoader($loader2); @@ -115,10 +115,10 @@ public function testExists() } } -interface Twig_ChainTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface +interface Twig_ChainTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface { } -interface Twig_ChainTestLoaderWithExistsInterface extends Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +interface Twig_ChainTestLoaderWithExistsInterface extends \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { } diff --git a/test/Twig/Tests/Loader/FilesystemTest.php b/test/Twig/Tests/Loader/FilesystemTest.php index d8ae84b4a4..c9574cd985 100644 --- a/test/Twig/Tests/Loader/FilesystemTest.php +++ b/test/Twig/Tests/Loader/FilesystemTest.php @@ -14,7 +14,7 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase public function testGetSourceContext() { $path = __DIR__.'/../Fixtures'; - $loader = new Twig_Loader_Filesystem([$path]); + $loader = new \Twig\Loader\FilesystemLoader([$path]); $this->assertEquals('errors/index.html', $loader->getSourceContext('errors/index.html')->getName()); $this->assertEquals(realpath($path.'/errors/index.html'), realpath($loader->getSourceContext('errors/index.html')->getPath())); } @@ -24,12 +24,12 @@ public function testGetSourceContext() */ public function testSecurity($template) { - $loader = new Twig_Loader_Filesystem([__DIR__.'/../Fixtures']); + $loader = new \Twig\Loader\FilesystemLoader([__DIR__.'/../Fixtures']); try { $loader->getCacheKey($template); $this->fail(); - } catch (Twig_Error_Loader $e) { + } catch (\Twig\Error\LoaderError $e) { $this->assertNotContains('Unable to find template', $e->getMessage()); } } @@ -64,7 +64,7 @@ public function getSecurityTests() */ public function testPaths($basePath, $cacheKey, $rootPath) { - $loader = new Twig_Loader_Filesystem([$basePath.'/normal', $basePath.'/normal_bis'], $rootPath); + $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal', $basePath.'/normal_bis'], $rootPath); $loader->setPaths([$basePath.'/named', $basePath.'/named_bis'], 'named'); $loader->addPath($basePath.'/named_ter', 'named'); $loader->addPath($basePath.'/normal_ter'); @@ -126,30 +126,30 @@ public function getBasePaths() public function testEmptyConstructor() { - $loader = new Twig_Loader_Filesystem(); + $loader = new \Twig\Loader\FilesystemLoader(); $this->assertEquals([], $loader->getPaths()); } public function testGetNamespaces() { - $loader = new Twig_Loader_Filesystem(sys_get_temp_dir()); - $this->assertEquals([Twig_Loader_Filesystem::MAIN_NAMESPACE], $loader->getNamespaces()); + $loader = new \Twig\Loader\FilesystemLoader(sys_get_temp_dir()); + $this->assertEquals([\Twig\Loader\FilesystemLoader::MAIN_NAMESPACE], $loader->getNamespaces()); $loader->addPath(sys_get_temp_dir(), 'named'); - $this->assertEquals([Twig_Loader_Filesystem::MAIN_NAMESPACE, 'named'], $loader->getNamespaces()); + $this->assertEquals([\Twig\Loader\FilesystemLoader::MAIN_NAMESPACE, 'named'], $loader->getNamespaces()); } public function testFindTemplateExceptionNamespace() { $basePath = __DIR__.'/Fixtures'; - $loader = new Twig_Loader_Filesystem([$basePath.'/normal']); + $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal']); $loader->addPath($basePath.'/named', 'named'); try { $loader->getSourceContext('@named/nowhere.html'); } catch (\Exception $e) { - $this->assertInstanceOf('Twig_Error_Loader', $e); + $this->assertInstanceOf('\Twig\Error\LoaderError', $e); $this->assertContains('Unable to find template "@named/nowhere.html"', $e->getMessage()); } } @@ -158,7 +158,7 @@ public function testFindTemplateWithCache() { $basePath = __DIR__.'/Fixtures'; - $loader = new Twig_Loader_Filesystem([$basePath.'/normal']); + $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal']); $loader->addPath($basePath.'/named', 'named'); // prime the cache for index.html in the named namespace @@ -171,12 +171,12 @@ public function testFindTemplateWithCache() public function testLoadTemplateAndRenderBlockWithCache() { - $loader = new Twig_Loader_Filesystem([]); + $loader = new \Twig\Loader\FilesystemLoader([]); $loader->addPath(__DIR__.'/Fixtures/themes/theme2'); $loader->addPath(__DIR__.'/Fixtures/themes/theme1'); $loader->addPath(__DIR__.'/Fixtures/themes/theme1', 'default_theme'); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $template = $twig->loadTemplate('blocks.html.twig'); $this->assertSame('block from theme 1', $template->renderBlock('b1', [])); @@ -202,10 +202,10 @@ public function getArrayInheritanceTests() */ public function testArrayInheritance($templateName) { - $loader = new Twig_Loader_Filesystem([]); + $loader = new \Twig\Loader\FilesystemLoader([]); $loader->addPath(__DIR__.'/Fixtures/inheritance'); - $twig = new Twig_Environment($loader); + $twig = new \Twig\Environment($loader); $template = $twig->loadTemplate($templateName); $this->assertSame('VALID Child', $template->renderBlock('body', [])); @@ -216,7 +216,7 @@ public function testArrayInheritance($templateName) */ public function testLoadTemplateFromPhar() { - $loader = new Twig_Loader_Filesystem([]); + $loader = new \Twig\Loader\FilesystemLoader([]); // phar-sample.phar was created with the following script: // $f = new Phar('phar-test.phar'); // $f->addFromString('hello.twig', 'hello from phar'); @@ -226,7 +226,7 @@ public function testLoadTemplateFromPhar() public function testTemplateExistsAlwaysReturnsBool() { - $loader = new Twig_Loader_Filesystem([]); + $loader = new \Twig\Loader\FilesystemLoader([]); $this->assertFalse($loader->exists("foo\0.twig")); $this->assertFalse($loader->exists('../foo.twig')); $this->assertFalse($loader->exists('@foo')); diff --git a/test/Twig/Tests/NativeExtensionTest.php b/test/Twig/Tests/NativeExtensionTest.php index 2b969a024c..379132d774 100644 --- a/test/Twig/Tests/NativeExtensionTest.php +++ b/test/Twig/Tests/NativeExtensionTest.php @@ -20,7 +20,7 @@ public function testGetProperties() $this->markTestSkipped('Extension is not available on PHP 7+'); } - $twig = new Twig_Environment(new Twig_Loader_Array(['index' => '{{ d1.date }}{{ d2.date }}']), [ + $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader(['index' => '{{ d1.date }}{{ d2.date }}']), [ 'debug' => true, 'cache' => false, 'autoescape' => false, diff --git a/test/Twig/Tests/Node/AutoEscapeTest.php b/test/Twig/Tests/Node/AutoEscapeTest.php index 1c9f09393e..1eeddc457d 100644 --- a/test/Twig/Tests/Node/AutoEscapeTest.php +++ b/test/Twig/Tests/Node/AutoEscapeTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_AutoEscapeTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_AutoEscapeTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $body = new Twig_Node([new Twig_Node_Text('foo', 1)]); - $node = new Twig_Node_AutoEscape(true, $body, 1); + $body = new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)]); + $node = new \Twig\Node\AutoEscapeNode(true, $body, 1); $this->assertEquals($body, $node->getNode('body')); $this->assertTrue($node->getAttribute('value')); @@ -22,8 +22,8 @@ public function testConstructor() public function getTests() { - $body = new Twig_Node([new Twig_Node_Text('foo', 1)]); - $node = new Twig_Node_AutoEscape(true, $body, 1); + $body = new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)]); + $node = new \Twig\Node\AutoEscapeNode(true, $body, 1); return [ [$node, "// line 1\necho \"foo\";"], diff --git a/test/Twig/Tests/Node/BlockReferenceTest.php b/test/Twig/Tests/Node/BlockReferenceTest.php index 0eb60ca019..de37e37f15 100644 --- a/test/Twig/Tests/Node/BlockReferenceTest.php +++ b/test/Twig/Tests/Node/BlockReferenceTest.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_BlockReferenceTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_BlockReferenceTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $node = new Twig_Node_BlockReference('foo', 1); + $node = new \Twig\Node\BlockReferenceNode('foo', 1); $this->assertEquals('foo', $node->getAttribute('name')); } @@ -21,7 +21,7 @@ public function testConstructor() public function getTests() { return [ - [new Twig_Node_BlockReference('foo', 1), <<displayBlock('foo', \$context, \$blocks); EOF diff --git a/test/Twig/Tests/Node/BlockTest.php b/test/Twig/Tests/Node/BlockTest.php index 0b347df029..d2256a6d88 100644 --- a/test/Twig/Tests/Node/BlockTest.php +++ b/test/Twig/Tests/Node/BlockTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_BlockTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_BlockTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $body = new Twig_Node_Text('foo', 1); - $node = new Twig_Node_Block('foo', $body, 1); + $body = new \Twig\Node\TextNode('foo', 1); + $node = new \Twig\Node\BlockNode('foo', $body, 1); $this->assertEquals($body, $node->getNode('body')); $this->assertEquals('foo', $node->getAttribute('name')); @@ -22,8 +22,8 @@ public function testConstructor() public function getTests() { - $body = new Twig_Node_Text('foo', 1); - $node = new Twig_Node_Block('foo', $body, 1); + $body = new \Twig\Node\TextNode('foo', 1); + $node = new \Twig\Node\BlockNode('foo', $body, 1); return [ [$node, <<assertEquals($expr, $node->getNode('expr')); } @@ -23,8 +23,8 @@ public function getTests() { $tests = []; - $expr = new Twig_Node_Expression_Constant('This section is deprecated', 1); - $node = new Twig_Node_Deprecated($expr, 1, 'deprecated'); + $expr = new \Twig\Node\Expression\ConstantExpression('This section is deprecated', 1); + $node = new \Twig\Node\DeprecatedNode($expr, 1, 'deprecated'); $node->setTemplateName('foo.twig'); $tests[] = [$node, <<setTemplateName('foo.twig'); $tests[] = [$node, <<getMockBuilder('Twig_LoaderInterface')->getMock()); - $environment->addFunction(new Twig_SimpleFunction('foo', 'foo', [])); + $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $environment->addFunction(new \Twig\TwigFunction('foo', 'foo', [])); - $expr = new Twig_Node_Expression_Function('foo', new Twig_Node(), 1); - $node = new Twig_Node_Deprecated($expr, 1, 'deprecated'); + $expr = new \Twig\Node\Expression\FunctionExpression('foo', new \Twig\Node\Node(), 1); + $node = new \Twig\Node\DeprecatedNode($expr, 1, 'deprecated'); $node->setTemplateName('foo.twig'); $compiler = $this->getCompiler($environment); diff --git a/test/Twig/Tests/Node/DoTest.php b/test/Twig/Tests/Node/DoTest.php index 64d6eead30..6e60ab413e 100644 --- a/test/Twig/Tests/Node/DoTest.php +++ b/test/Twig/Tests/Node/DoTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_DoTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_DoTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $expr = new Twig_Node_Expression_Constant('foo', 1); - $node = new Twig_Node_Do($expr, 1); + $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); + $node = new \Twig\Node\DoNode($expr, 1); $this->assertEquals($expr, $node->getNode('expr')); } @@ -23,8 +23,8 @@ public function getTests() { $tests = []; - $expr = new Twig_Node_Expression_Constant('foo', 1); - $node = new Twig_Node_Do($expr, 1); + $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); + $node = new \Twig\Node\DoNode($expr, 1); $tests[] = [$node, "// line 1\n\"foo\";"]; return $tests; diff --git a/test/Twig/Tests/Node/Expression/ArrayTest.php b/test/Twig/Tests/Node/Expression/ArrayTest.php index ecb5055d2d..2175ccc2e4 100644 --- a/test/Twig/Tests/Node/Expression/ArrayTest.php +++ b/test/Twig/Tests/Node/Expression/ArrayTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_ArrayTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_ArrayTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $elements = [new Twig_Node_Expression_Constant('foo', 1), $foo = new Twig_Node_Expression_Constant('bar', 1)]; - $node = new Twig_Node_Expression_Array($elements, 1); + $elements = [new \Twig\Node\Expression\ConstantExpression('foo', 1), $foo = new \Twig\Node\Expression\ConstantExpression('bar', 1)]; + $node = new \Twig\Node\Expression\ArrayExpression($elements, 1); $this->assertEquals($foo, $node->getNode(1)); } @@ -22,13 +22,13 @@ public function testConstructor() public function getTests() { $elements = [ - new Twig_Node_Expression_Constant('foo', 1), - new Twig_Node_Expression_Constant('bar', 1), + new \Twig\Node\Expression\ConstantExpression('foo', 1), + new \Twig\Node\Expression\ConstantExpression('bar', 1), - new Twig_Node_Expression_Constant('bar', 1), - new Twig_Node_Expression_Constant('foo', 1), + new \Twig\Node\Expression\ConstantExpression('bar', 1), + new \Twig\Node\Expression\ConstantExpression('foo', 1), ]; - $node = new Twig_Node_Expression_Array($elements, 1); + $node = new \Twig\Node\Expression\ArrayExpression($elements, 1); return [ [$node, '["foo" => "bar", "bar" => "foo"]'], diff --git a/test/Twig/Tests/Node/Expression/AssignNameTest.php b/test/Twig/Tests/Node/Expression/AssignNameTest.php index a325f0b4ab..28470e5000 100644 --- a/test/Twig/Tests/Node/Expression/AssignNameTest.php +++ b/test/Twig/Tests/Node/Expression/AssignNameTest.php @@ -9,18 +9,18 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_AssignNameTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_AssignNameTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $node = new Twig_Node_Expression_AssignName('foo', 1); + $node = new \Twig\Node\Expression\AssignNameExpression('foo', 1); $this->assertEquals('foo', $node->getAttribute('name')); } public function getTests() { - $node = new Twig_Node_Expression_AssignName('foo', 1); + $node = new \Twig\Node\Expression\AssignNameExpression('foo', 1); return [ [$node, '$context["foo"]'], diff --git a/test/Twig/Tests/Node/Expression/Binary/AddTest.php b/test/Twig/Tests/Node/Expression/Binary/AddTest.php index 333b2056a8..64a1c06b79 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AddTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AddTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_AddTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_AddTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Add($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\AddBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Add($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\AddBinary($left, $right, 1); return [ [$node, '(1 + 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/AndTest.php b/test/Twig/Tests/Node/Expression/Binary/AndTest.php index 56c055e7d3..6292f9e382 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AndTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AndTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_AndTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_AndTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_And($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\AndBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_And($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\AndBinary($left, $right, 1); return [ [$node, '(1 && 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php index e83712e50e..9a6f56acfa 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_ConcatTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_ConcatTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Concat($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\ConcatBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Concat($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\ConcatBinary($left, $right, 1); return [ [$node, '(1 . 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/DivTest.php b/test/Twig/Tests/Node/Expression/Binary/DivTest.php index 011e7ce4fb..58719c2b20 100644 --- a/test/Twig/Tests/Node/Expression/Binary/DivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/DivTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_DivTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_DivTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Div($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\DivBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Div($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\DivBinary($left, $right, 1); return [ [$node, '(1 / 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php index 1131a4e226..4ca3840210 100644 --- a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_FloorDivTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_FloorDivTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_FloorDiv($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\FloorDivBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_FloorDiv($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\FloorDivBinary($left, $right, 1); return [ [$node, '(int) floor((1 / 2))'], diff --git a/test/Twig/Tests/Node/Expression/Binary/ModTest.php b/test/Twig/Tests/Node/Expression/Binary/ModTest.php index 7c3d00b8af..d4d48acdb3 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ModTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ModTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_ModTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_ModTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Mod($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\ModBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Mod($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\ModBinary($left, $right, 1); return [ [$node, '(1 % 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/MulTest.php b/test/Twig/Tests/Node/Expression/Binary/MulTest.php index 6ed79bc48c..b35655b752 100644 --- a/test/Twig/Tests/Node/Expression/Binary/MulTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/MulTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_MulTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_MulTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Mul($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\MulBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Mul($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\MulBinary($left, $right, 1); return [ [$node, '(1 * 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/OrTest.php b/test/Twig/Tests/Node/Expression/Binary/OrTest.php index fe9acb0c58..9a40ffbd91 100644 --- a/test/Twig/Tests/Node/Expression/Binary/OrTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/OrTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_OrTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_OrTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Or($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\OrBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Or($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\OrBinary($left, $right, 1); return [ [$node, '(1 || 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/SubTest.php b/test/Twig/Tests/Node/Expression/Binary/SubTest.php index e142016125..191ad7e96c 100644 --- a/test/Twig/Tests/Node/Expression/Binary/SubTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/SubTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_SubTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Binary_SubTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Sub($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\SubBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +23,9 @@ public function testConstructor() public function getTests() { - $left = new Twig_Node_Expression_Constant(1, 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_Binary_Sub($left, $right, 1); + $left = new \Twig\Node\Expression\ConstantExpression(1, 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\Binary\SubBinary($left, $right, 1); return [ [$node, '(1 - 2)'], diff --git a/test/Twig/Tests/Node/Expression/CallTest.php b/test/Twig/Tests/Node/Expression/CallTest.php index ede330987c..72780d7115 100644 --- a/test/Twig/Tests/Node/Expression/CallTest.php +++ b/test/Twig/Tests/Node/Expression/CallTest.php @@ -18,7 +18,7 @@ public function testGetArguments() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Positional arguments cannot be used after named arguments for function "date". */ public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments() @@ -28,7 +28,7 @@ public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Argument "format" is defined twice for function "date". */ public function testGetArgumentsWhenArgumentIsDefinedTwice() @@ -38,7 +38,7 @@ public function testGetArgumentsWhenArgumentIsDefinedTwice() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown argument "unknown" for function "date(format, timestamp)". */ public function testGetArgumentsWithWrongNamedArgumentName() @@ -48,7 +48,7 @@ public function testGetArgumentsWithWrongNamedArgumentName() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)". */ public function testGetArgumentsWithWrongNamedArgumentNames() @@ -58,7 +58,7 @@ public function testGetArgumentsWithWrongNamedArgumentNames() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Argument "case_sensitivity" could not be assigned for function "substr_compare(main_str, str, offset, length, case_sensitivity)" because it is mapped to an internal PHP function which cannot determine default value for optional argument "length". */ public function testResolveArgumentsWithMissingValueForOptionalArgument() @@ -123,7 +123,7 @@ public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnO } } -class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call +class Twig_Tests_Node_Expression_Call extends \Twig\Node\Expression\CallExpression { public function getArguments($callable, $arguments) { diff --git a/test/Twig/Tests/Node/Expression/ConditionalTest.php b/test/Twig/Tests/Node/Expression/ConditionalTest.php index ff9a5ad484..1c37e6106f 100644 --- a/test/Twig/Tests/Node/Expression/ConditionalTest.php +++ b/test/Twig/Tests/Node/Expression/ConditionalTest.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_ConditionalTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_ConditionalTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $expr1 = new Twig_Node_Expression_Constant(1, 1); - $expr2 = new Twig_Node_Expression_Constant(2, 1); - $expr3 = new Twig_Node_Expression_Constant(3, 1); - $node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 1); + $expr1 = new \Twig\Node\Expression\ConstantExpression(1, 1); + $expr2 = new \Twig\Node\Expression\ConstantExpression(2, 1); + $expr3 = new \Twig\Node\Expression\ConstantExpression(3, 1); + $node = new \Twig\Node\Expression\ConditionalExpression($expr1, $expr2, $expr3, 1); $this->assertEquals($expr1, $node->getNode('expr1')); $this->assertEquals($expr2, $node->getNode('expr2')); @@ -27,10 +27,10 @@ public function getTests() { $tests = []; - $expr1 = new Twig_Node_Expression_Constant(1, 1); - $expr2 = new Twig_Node_Expression_Constant(2, 1); - $expr3 = new Twig_Node_Expression_Constant(3, 1); - $node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 1); + $expr1 = new \Twig\Node\Expression\ConstantExpression(1, 1); + $expr2 = new \Twig\Node\Expression\ConstantExpression(2, 1); + $expr3 = new \Twig\Node\Expression\ConstantExpression(3, 1); + $node = new \Twig\Node\Expression\ConditionalExpression($expr1, $expr2, $expr3, 1); $tests[] = [$node, '((1) ? (2) : (3))']; return $tests; diff --git a/test/Twig/Tests/Node/Expression/ConstantTest.php b/test/Twig/Tests/Node/Expression/ConstantTest.php index c43de0020f..1cb1242e7a 100644 --- a/test/Twig/Tests/Node/Expression/ConstantTest.php +++ b/test/Twig/Tests/Node/Expression/ConstantTest.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_ConstantTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_ConstantTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $node = new Twig_Node_Expression_Constant('foo', 1); + $node = new \Twig\Node\Expression\ConstantExpression('foo', 1); $this->assertEquals('foo', $node->getAttribute('value')); } @@ -22,7 +22,7 @@ public function getTests() { $tests = []; - $node = new Twig_Node_Expression_Constant('foo', 1); + $node = new \Twig\Node\Expression\ConstantExpression('foo', 1); $tests[] = [$node, '"foo"']; return $tests; diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php index 05dd264d40..a21650f839 100644 --- a/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/test/Twig/Tests/Node/Expression/FilterTest.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $expr = new Twig_Node_Expression_Constant('foo', 1); - $name = new Twig_Node_Expression_Constant('upper', 1); - $args = new Twig_Node(); - $node = new Twig_Node_Expression_Filter($expr, $name, $args, 1); + $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); + $name = new \Twig\Node\Expression\ConstantExpression('upper', 1); + $args = new \Twig\Node\Node(); + $node = new \Twig\Node\Expression\FilterExpression($expr, $name, $args, 1); $this->assertEquals($expr, $node->getNode('node')); $this->assertEquals($name, $node->getNode('filter')); @@ -25,15 +25,15 @@ public function testConstructor() public function getTests() { - $environment = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $environment->addFilter(new Twig_SimpleFilter('bar', 'bar', ['needs_environment' => true])); - $environment->addFilter(new Twig_SimpleFilter('barbar', 'twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true])); + $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $environment->addFilter(new \Twig\TwigFilter('bar', 'bar', ['needs_environment' => true])); + $environment->addFilter(new \Twig\TwigFilter('barbar', 'twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true])); $tests = []; - $expr = new Twig_Node_Expression_Constant('foo', 1); + $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); $node = $this->createFilter($expr, 'upper'); - $node = $this->createFilter($node, 'number_format', [new Twig_Node_Expression_Constant(2, 1), new Twig_Node_Expression_Constant('.', 1), new Twig_Node_Expression_Constant(',', 1)]); + $node = $this->createFilter($node, 'number_format', [new \Twig\Node\Expression\ConstantExpression(2, 1), new \Twig\Node\Expression\ConstantExpression('.', 1), new \Twig\Node\Expression\ConstantExpression(',', 1)]); if (\function_exists('mb_get_info')) { $tests[] = [$node, 'twig_number_format_filter($this->env, twig_upper_filter($this->env, "foo"), 2, ".", ",")']; @@ -42,34 +42,34 @@ public function getTests() } // named arguments - $date = new Twig_Node_Expression_Constant(0, 1); + $date = new \Twig\Node\Expression\ConstantExpression(0, 1); $node = $this->createFilter($date, 'date', [ - 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1), - 'format' => new Twig_Node_Expression_Constant('d/m/Y H:i:s P', 1), + 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1), + 'format' => new \Twig\Node\Expression\ConstantExpression('d/m/Y H:i:s P', 1), ]); $tests[] = [$node, 'twig_date_format_filter($this->env, 0, "d/m/Y H:i:s P", "America/Chicago")']; // skip an optional argument - $date = new Twig_Node_Expression_Constant(0, 1); + $date = new \Twig\Node\Expression\ConstantExpression(0, 1); $node = $this->createFilter($date, 'date', [ - 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1), + 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1), ]); $tests[] = [$node, 'twig_date_format_filter($this->env, 0, null, "America/Chicago")']; // underscores vs camelCase for named arguments - $string = new Twig_Node_Expression_Constant('abc', 1); + $string = new \Twig\Node\Expression\ConstantExpression('abc', 1); $node = $this->createFilter($string, 'reverse', [ - 'preserve_keys' => new Twig_Node_Expression_Constant(true, 1), + 'preserve_keys' => new \Twig\Node\Expression\ConstantExpression(true, 1), ]); $tests[] = [$node, 'twig_reverse_filter($this->env, "abc", true)']; $node = $this->createFilter($string, 'reverse', [ - 'preserveKeys' => new Twig_Node_Expression_Constant(true, 1), + 'preserveKeys' => new \Twig\Node\Expression\ConstantExpression(true, 1), ]); $tests[] = [$node, 'twig_reverse_filter($this->env, "abc", true)']; // filter as an anonymous function if (PHP_VERSION_ID >= 50300) { - $node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous'); + $node = $this->createFilter(new \Twig\Node\Expression\ConstantExpression('foo', 1), 'anonymous'); $tests[] = [$node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), ["foo"])']; } @@ -77,24 +77,24 @@ public function getTests() $node = $this->createFilter($string, 'bar'); $tests[] = [$node, 'bar($this->env, "abc")', $environment]; - $node = $this->createFilter($string, 'bar', [new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createFilter($string, 'bar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'bar($this->env, "abc", "bar")', $environment]; // arbitrary named arguments $node = $this->createFilter($string, 'barbar'); $tests[] = [$node, 'twig_tests_filter_barbar($context, "abc")', $environment]; - $node = $this->createFilter($string, 'barbar', ['foo' => new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createFilter($string, 'barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", null, null, ["foo" => "bar"])', $environment]; - $node = $this->createFilter($string, 'barbar', ['arg2' => new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createFilter($string, 'barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", null, "bar")', $environment]; $node = $this->createFilter($string, 'barbar', [ - new Twig_Node_Expression_Constant('1', 1), - new Twig_Node_Expression_Constant('2', 1), - new Twig_Node_Expression_Constant('3', 1), - 'foo' => new Twig_Node_Expression_Constant('bar', 1), + new \Twig\Node\Expression\ConstantExpression('1', 1), + new \Twig\Node\Expression\ConstantExpression('2', 1), + new \Twig\Node\Expression\ConstantExpression('3', 1), + 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1), ]); $tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", "1", "2", [0 => "3", "foo" => "bar"])', $environment]; @@ -102,14 +102,14 @@ public function getTests() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown argument "foobar" for filter "date(format, timezone)" at line 1. */ public function testCompileWithWrongNamedArgumentName() { - $date = new Twig_Node_Expression_Constant(0, 1); + $date = new \Twig\Node\Expression\ConstantExpression(0, 1); $node = $this->createFilter($date, 'date', [ - 'foobar' => new Twig_Node_Expression_Constant('America/Chicago', 1), + 'foobar' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1), ]); $compiler = $this->getCompiler(); @@ -117,14 +117,14 @@ public function testCompileWithWrongNamedArgumentName() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Value for argument "from" is required for filter "replace" at line 1. */ public function testCompileWithMissingNamedArgument() { - $value = new Twig_Node_Expression_Constant(0, 1); + $value = new \Twig\Node\Expression\ConstantExpression(0, 1); $node = $this->createFilter($value, 'replace', [ - 'to' => new Twig_Node_Expression_Constant('foo', 1), + 'to' => new \Twig\Node\Expression\ConstantExpression('foo', 1), ]); $compiler = $this->getCompiler(); @@ -133,10 +133,10 @@ public function testCompileWithMissingNamedArgument() protected function createFilter($node, $name, array $arguments = []) { - $name = new Twig_Node_Expression_Constant($name, 1); - $arguments = new Twig_Node($arguments); + $name = new \Twig\Node\Expression\ConstantExpression($name, 1); + $arguments = new \Twig\Node\Node($arguments); - return new Twig_Node_Expression_Filter($node, $name, $arguments, 1); + return new \Twig\Node\Expression\FilterExpression($node, $name, $arguments, 1); } protected function getEnvironment() diff --git a/test/Twig/Tests/Node/Expression/FunctionTest.php b/test/Twig/Tests/Node/Expression/FunctionTest.php index ef1d29cd3e..2aa3a2c2dc 100644 --- a/test/Twig/Tests/Node/Expression/FunctionTest.php +++ b/test/Twig/Tests/Node/Expression/FunctionTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_FunctionTest extends \Twig\Test\NodeTestCase { public function testConstructor() { $name = 'function'; - $args = new Twig_Node(); - $node = new Twig_Node_Expression_Function($name, $args, 1); + $args = new \Twig\Node\Node(); + $node = new \Twig\Node\Expression\FunctionExpression($name, $args, 1); $this->assertEquals($name, $node->getAttribute('name')); $this->assertEquals($args, $node->getNode('arguments')); @@ -23,43 +23,43 @@ public function testConstructor() public function getTests() { - $environment = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $environment->addFunction(new Twig_SimpleFunction('foo', 'foo', [])); - $environment->addFunction(new Twig_SimpleFunction('bar', 'bar', ['needs_environment' => true])); - $environment->addFunction(new Twig_SimpleFunction('foofoo', 'foofoo', ['needs_context' => true])); - $environment->addFunction(new Twig_SimpleFunction('foobar', 'foobar', ['needs_environment' => true, 'needs_context' => true])); - $environment->addFunction(new Twig_SimpleFunction('barbar', 'twig_tests_function_barbar', ['is_variadic' => true])); + $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $environment->addFunction(new \Twig\TwigFunction('foo', 'foo', [])); + $environment->addFunction(new \Twig\TwigFunction('bar', 'bar', ['needs_environment' => true])); + $environment->addFunction(new \Twig\TwigFunction('foofoo', 'foofoo', ['needs_context' => true])); + $environment->addFunction(new \Twig\TwigFunction('foobar', 'foobar', ['needs_environment' => true, 'needs_context' => true])); + $environment->addFunction(new \Twig\TwigFunction('barbar', 'twig_tests_function_barbar', ['is_variadic' => true])); $tests = []; $node = $this->createFunction('foo'); $tests[] = [$node, 'foo()', $environment]; - $node = $this->createFunction('foo', [new Twig_Node_Expression_Constant('bar', 1), new Twig_Node_Expression_Constant('foobar', 1)]); + $node = $this->createFunction('foo', [new \Twig\Node\Expression\ConstantExpression('bar', 1), new \Twig\Node\Expression\ConstantExpression('foobar', 1)]); $tests[] = [$node, 'foo("bar", "foobar")', $environment]; $node = $this->createFunction('bar'); $tests[] = [$node, 'bar($this->env)', $environment]; - $node = $this->createFunction('bar', [new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createFunction('bar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'bar($this->env, "bar")', $environment]; $node = $this->createFunction('foofoo'); $tests[] = [$node, 'foofoo($context)', $environment]; - $node = $this->createFunction('foofoo', [new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createFunction('foofoo', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'foofoo($context, "bar")', $environment]; $node = $this->createFunction('foobar'); $tests[] = [$node, 'foobar($this->env, $context)', $environment]; - $node = $this->createFunction('foobar', [new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createFunction('foobar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'foobar($this->env, $context, "bar")', $environment]; // named arguments $node = $this->createFunction('date', [ - 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1), - 'date' => new Twig_Node_Expression_Constant(0, 1), + 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1), + 'date' => new \Twig\Node\Expression\ConstantExpression(0, 1), ]); $tests[] = [$node, 'twig_date_converter($this->env, 0, "America/Chicago")']; @@ -67,23 +67,23 @@ public function getTests() $node = $this->createFunction('barbar'); $tests[] = [$node, 'twig_tests_function_barbar()', $environment]; - $node = $this->createFunction('barbar', ['foo' => new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createFunction('barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_function_barbar(null, null, ["foo" => "bar"])', $environment]; - $node = $this->createFunction('barbar', ['arg2' => new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createFunction('barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_function_barbar(null, "bar")', $environment]; $node = $this->createFunction('barbar', [ - new Twig_Node_Expression_Constant('1', 1), - new Twig_Node_Expression_Constant('2', 1), - new Twig_Node_Expression_Constant('3', 1), - 'foo' => new Twig_Node_Expression_Constant('bar', 1), + new \Twig\Node\Expression\ConstantExpression('1', 1), + new \Twig\Node\Expression\ConstantExpression('2', 1), + new \Twig\Node\Expression\ConstantExpression('3', 1), + 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1), ]); $tests[] = [$node, 'twig_tests_function_barbar("1", "2", [0 => "3", "foo" => "bar"])', $environment]; // function as an anonymous function if (PHP_VERSION_ID >= 50300) { - $node = $this->createFunction('anonymous', [new Twig_Node_Expression_Constant('foo', 1)]); + $node = $this->createFunction('anonymous', [new \Twig\Node\Expression\ConstantExpression('foo', 1)]); $tests[] = [$node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), ["foo"])']; } @@ -92,7 +92,7 @@ public function getTests() protected function createFunction($name, array $arguments = []) { - return new Twig_Node_Expression_Function($name, new Twig_Node($arguments), 1); + return new \Twig\Node\Expression\FunctionExpression($name, new \Twig\Node\Node($arguments), 1); } protected function getEnvironment() diff --git a/test/Twig/Tests/Node/Expression/GetAttrTest.php b/test/Twig/Tests/Node/Expression/GetAttrTest.php index 1a465509e7..130fd9fb48 100644 --- a/test/Twig/Tests/Node/Expression/GetAttrTest.php +++ b/test/Twig/Tests/Node/Expression/GetAttrTest.php @@ -9,40 +9,40 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_GetAttrTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $expr = new Twig_Node_Expression_Name('foo', 1); - $attr = new Twig_Node_Expression_Constant('bar', 1); - $args = new Twig_Node_Expression_Array([], 1); - $args->addElement(new Twig_Node_Expression_Name('foo', 1)); - $args->addElement(new Twig_Node_Expression_Constant('bar', 1)); - $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1); + $expr = new \Twig\Node\Expression\NameExpression('foo', 1); + $attr = new \Twig\Node\Expression\ConstantExpression('bar', 1); + $args = new \Twig\Node\Expression\ArrayExpression([], 1); + $args->addElement(new \Twig\Node\Expression\NameExpression('foo', 1)); + $args->addElement(new \Twig\Node\Expression\ConstantExpression('bar', 1)); + $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ARRAY_CALL, 1); $this->assertEquals($expr, $node->getNode('node')); $this->assertEquals($attr, $node->getNode('attribute')); $this->assertEquals($args, $node->getNode('arguments')); - $this->assertEquals(Twig_Template::ARRAY_CALL, $node->getAttribute('type')); + $this->assertEquals(\Twig\Template::ARRAY_CALL, $node->getAttribute('type')); } public function getTests() { $tests = []; - $expr = new Twig_Node_Expression_Name('foo', 1); - $attr = new Twig_Node_Expression_Constant('bar', 1); - $args = new Twig_Node_Expression_Array([], 1); - $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1); + $expr = new \Twig\Node\Expression\NameExpression('foo', 1); + $attr = new \Twig\Node\Expression\ConstantExpression('bar', 1); + $args = new \Twig\Node\Expression\ArrayExpression([], 1); + $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ANY_CALL, 1); $tests[] = [$node, sprintf('%s%s, "bar", [])', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))]; - $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1); + $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ARRAY_CALL, 1); $tests[] = [$node, sprintf('%s%s, "bar", [], "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))]; - $args = new Twig_Node_Expression_Array([], 1); - $args->addElement(new Twig_Node_Expression_Name('foo', 1)); - $args->addElement(new Twig_Node_Expression_Constant('bar', 1)); - $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1); + $args = new \Twig\Node\Expression\ArrayExpression([], 1); + $args->addElement(new \Twig\Node\Expression\NameExpression('foo', 1)); + $args->addElement(new \Twig\Node\Expression\ConstantExpression('bar', 1)); + $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::METHOD_CALL, 1); $tests[] = [$node, sprintf('%s%s, "bar", [0 => %s, 1 => "bar"], "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo'))]; return $tests; diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index 73c050b6ae..25eaa02736 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -9,22 +9,22 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_NameTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $node = new Twig_Node_Expression_Name('foo', 1); + $node = new \Twig\Node\Expression\NameExpression('foo', 1); $this->assertEquals('foo', $node->getAttribute('name')); } public function getTests() { - $node = new Twig_Node_Expression_Name('foo', 1); - $context = new Twig_Node_Expression_Name('_context', 1); + $node = new \Twig\Node\Expression\NameExpression('foo', 1); + $context = new \Twig\Node\Expression\NameExpression('_context', 1); - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => true]); - $env1 = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => false]); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true]); + $env1 = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => false]); if (PHP_VERSION_ID >= 70000) { $output = '($context["foo"] ?? $this->getContext($context, "foo"))'; diff --git a/test/Twig/Tests/Node/Expression/NullCoalesceTest.php b/test/Twig/Tests/Node/Expression/NullCoalesceTest.php index 39b5d704cc..398c12f469 100644 --- a/test/Twig/Tests/Node/Expression/NullCoalesceTest.php +++ b/test/Twig/Tests/Node/Expression/NullCoalesceTest.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_NullCoalesceTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_NullCoalesceTest extends \Twig\Test\NodeTestCase { public function getTests() { $tests = []; - $left = new Twig_Node_Expression_Name('foo', 1); - $right = new Twig_Node_Expression_Constant(2, 1); - $node = new Twig_Node_Expression_NullCoalesce($left, $right, 1); + $left = new \Twig\Node\Expression\NameExpression('foo', 1); + $right = new \Twig\Node\Expression\ConstantExpression(2, 1); + $node = new \Twig\Node\Expression\NullCoalesceExpression($left, $right, 1); if (PHP_VERSION_ID >= 70000) { $tests[] = [$node, "((// line 1\n\$context[\"foo\"]) ?? (2))"]; } elseif (PHP_VERSION_ID >= 50400) { diff --git a/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php b/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php index 3a9ff41a61..5ea41d80bb 100644 --- a/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php +++ b/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php @@ -1,6 +1,6 @@ addFilter(new Twig_SimpleFilter('anonymous', function () {})); +$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([])); +$env->addFilter(new \Twig\TwigFilter('anonymous', function () {})); return $env; diff --git a/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php b/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php index 57ee62ad3c..44cd979974 100644 --- a/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php +++ b/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php @@ -1,6 +1,6 @@ addFunction(new Twig_SimpleFunction('anonymous', function () {})); +$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([])); +$env->addFunction(new \Twig\TwigFunction('anonymous', function () {})); return $env; diff --git a/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php b/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php index eba333db1e..1f30a71ecf 100644 --- a/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php +++ b/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php @@ -1,6 +1,6 @@ addTest(new Twig_SimpleTest('anonymous', function () {})); +$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([])); +$env->addTest(new \Twig\TwigTest('anonymous', function () {})); return $env; diff --git a/test/Twig/Tests/Node/Expression/ParentTest.php b/test/Twig/Tests/Node/Expression/ParentTest.php index 4e25a8bee6..940db7169c 100644 --- a/test/Twig/Tests/Node/Expression/ParentTest.php +++ b/test/Twig/Tests/Node/Expression/ParentTest.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_ParentTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_ParentTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $node = new Twig_Node_Expression_Parent('foo', 1); + $node = new \Twig\Node\Expression\ParentExpression('foo', 1); $this->assertEquals('foo', $node->getAttribute('name')); } @@ -21,7 +21,7 @@ public function testConstructor() public function getTests() { $tests = []; - $tests[] = [new Twig_Node_Expression_Parent('foo', 1), '$this->renderParentBlock("foo", $context, $blocks)']; + $tests[] = [new \Twig\Node\Expression\ParentExpression('foo', 1), '$this->renderParentBlock("foo", $context, $blocks)']; return $tests; } diff --git a/test/Twig/Tests/Node/Expression/TestTest.php b/test/Twig/Tests/Node/Expression/TestTest.php index 28de6cbfdf..c23b2b2225 100644 --- a/test/Twig/Tests/Node/Expression/TestTest.php +++ b/test/Twig/Tests/Node/Expression/TestTest.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_TestTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $expr = new Twig_Node_Expression_Constant('foo', 1); - $name = new Twig_Node_Expression_Constant('null', 1); - $args = new Twig_Node(); - $node = new Twig_Node_Expression_Test($expr, $name, $args, 1); + $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); + $name = new \Twig\Node\Expression\ConstantExpression('null', 1); + $args = new \Twig\Node\Node(); + $node = new \Twig\Node\Expression\TestExpression($expr, $name, $args, 1); $this->assertEquals($expr, $node->getNode('node')); $this->assertEquals($args, $node->getNode('arguments')); @@ -25,37 +25,37 @@ public function testConstructor() public function getTests() { - $environment = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $environment->addTest(new Twig_SimpleTest('barbar', 'twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true])); + $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $environment->addTest(new \Twig\TwigTest('barbar', 'twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true])); $tests = []; - $expr = new Twig_Node_Expression_Constant('foo', 1); - $node = new Twig_Node_Expression_Test_Null($expr, 'null', new Twig_Node([]), 1); + $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); + $node = new \Twig\Node\Expression\Test\NullTest($expr, 'null', new \Twig\Node\Node([]), 1); $tests[] = [$node, '(null === "foo")']; // test as an anonymous function if (PHP_VERSION_ID >= 50300) { - $node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', [new Twig_Node_Expression_Constant('foo', 1)]); + $node = $this->createTest(new \Twig\Node\Expression\ConstantExpression('foo', 1), 'anonymous', [new \Twig\Node\Expression\ConstantExpression('foo', 1)]); $tests[] = [$node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), ["foo", "foo"])']; } // arbitrary named arguments - $string = new Twig_Node_Expression_Constant('abc', 1); + $string = new \Twig\Node\Expression\ConstantExpression('abc', 1); $node = $this->createTest($string, 'barbar'); $tests[] = [$node, 'twig_tests_test_barbar("abc")', $environment]; - $node = $this->createTest($string, 'barbar', ['foo' => new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createTest($string, 'barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_test_barbar("abc", null, null, ["foo" => "bar"])', $environment]; - $node = $this->createTest($string, 'barbar', ['arg2' => new Twig_Node_Expression_Constant('bar', 1)]); + $node = $this->createTest($string, 'barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_test_barbar("abc", null, "bar")', $environment]; $node = $this->createTest($string, 'barbar', [ - new Twig_Node_Expression_Constant('1', 1), - new Twig_Node_Expression_Constant('2', 1), - new Twig_Node_Expression_Constant('3', 1), - 'foo' => new Twig_Node_Expression_Constant('bar', 1), + new \Twig\Node\Expression\ConstantExpression('1', 1), + new \Twig\Node\Expression\ConstantExpression('2', 1), + new \Twig\Node\Expression\ConstantExpression('3', 1), + 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1), ]); $tests[] = [$node, 'twig_tests_test_barbar("abc", "1", "2", [0 => "3", "foo" => "bar"])', $environment]; @@ -64,7 +64,7 @@ public function getTests() protected function createTest($node, $name, array $arguments = []) { - return new Twig_Node_Expression_Test($node, $name, new Twig_Node($arguments), 1); + return new \Twig\Node\Expression\TestExpression($node, $name, new \Twig\Node\Node($arguments), 1); } protected function getEnvironment() diff --git a/test/Twig/Tests/Node/Expression/Unary/NegTest.php b/test/Twig/Tests/Node/Expression/Unary/NegTest.php index 5c058816ee..d46f2ae9ac 100644 --- a/test/Twig/Tests/Node/Expression/Unary/NegTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/NegTest.php @@ -9,24 +9,24 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Unary_NegTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Unary_NegTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $expr = new Twig_Node_Expression_Constant(1, 1); - $node = new Twig_Node_Expression_Unary_Neg($expr, 1); + $expr = new \Twig\Node\Expression\ConstantExpression(1, 1); + $node = new \Twig\Node\Expression\Unary\NegUnary($expr, 1); $this->assertEquals($expr, $node->getNode('node')); } public function getTests() { - $node = new Twig_Node_Expression_Constant(1, 1); - $node = new Twig_Node_Expression_Unary_Neg($node, 1); + $node = new \Twig\Node\Expression\ConstantExpression(1, 1); + $node = new \Twig\Node\Expression\Unary\NegUnary($node, 1); return [ [$node, '-1'], - [new Twig_Node_Expression_Unary_Neg($node, 1), '- -1'], + [new \Twig\Node\Expression\Unary\NegUnary($node, 1), '- -1'], ]; } } diff --git a/test/Twig/Tests/Node/Expression/Unary/NotTest.php b/test/Twig/Tests/Node/Expression/Unary/NotTest.php index 9e45760a4a..95ab487e22 100644 --- a/test/Twig/Tests/Node/Expression/Unary/NotTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/NotTest.php @@ -9,20 +9,20 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Unary_NotTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Unary_NotTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $expr = new Twig_Node_Expression_Constant(1, 1); - $node = new Twig_Node_Expression_Unary_Not($expr, 1); + $expr = new \Twig\Node\Expression\ConstantExpression(1, 1); + $node = new \Twig\Node\Expression\Unary\NotUnary($expr, 1); $this->assertEquals($expr, $node->getNode('node')); } public function getTests() { - $node = new Twig_Node_Expression_Constant(1, 1); - $node = new Twig_Node_Expression_Unary_Not($node, 1); + $node = new \Twig\Node\Expression\ConstantExpression(1, 1); + $node = new \Twig\Node\Expression\Unary\NotUnary($node, 1); return [ [$node, '!1'], diff --git a/test/Twig/Tests/Node/Expression/Unary/PosTest.php b/test/Twig/Tests/Node/Expression/Unary/PosTest.php index bddcc4bf98..38469c4377 100644 --- a/test/Twig/Tests/Node/Expression/Unary/PosTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/PosTest.php @@ -9,20 +9,20 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Unary_PosTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_Expression_Unary_PosTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $expr = new Twig_Node_Expression_Constant(1, 1); - $node = new Twig_Node_Expression_Unary_Pos($expr, 1); + $expr = new \Twig\Node\Expression\ConstantExpression(1, 1); + $node = new \Twig\Node\Expression\Unary\PosUnary($expr, 1); $this->assertEquals($expr, $node->getNode('node')); } public function getTests() { - $node = new Twig_Node_Expression_Constant(1, 1); - $node = new Twig_Node_Expression_Unary_Pos($node, 1); + $node = new \Twig\Node\Expression\ConstantExpression(1, 1); + $node = new \Twig\Node\Expression\Unary\PosUnary($node, 1); return [ [$node, '+1'], diff --git a/test/Twig/Tests/Node/ForTest.php b/test/Twig/Tests/Node/ForTest.php index bfb4d0ceaf..5a065681ee 100644 --- a/test/Twig/Tests/Node/ForTest.php +++ b/test/Twig/Tests/Node/ForTest.php @@ -9,29 +9,29 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_ForTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_ForTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $keyTarget = new Twig_Node_Expression_AssignName('key', 1); - $valueTarget = new Twig_Node_Expression_AssignName('item', 1); - $seq = new Twig_Node_Expression_Name('items', 1); - $ifexpr = new Twig_Node_Expression_Constant(true, 1); - $body = new Twig_Node([new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1)], [], 1); + $keyTarget = new \Twig\Node\Expression\AssignNameExpression('key', 1); + $valueTarget = new \Twig\Node\Expression\AssignNameExpression('item', 1); + $seq = new \Twig\Node\Expression\NameExpression('items', 1); + $ifexpr = new \Twig\Node\Expression\ConstantExpression(true, 1); + $body = new \Twig\Node\Node([new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1)], [], 1); $else = null; - $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); $node->setAttribute('with_loop', false); $this->assertEquals($keyTarget, $node->getNode('key_target')); $this->assertEquals($valueTarget, $node->getNode('value_target')); $this->assertEquals($seq, $node->getNode('seq')); $this->assertTrue($node->getAttribute('ifexpr')); - $this->assertInstanceOf('Twig_Node_If', $node->getNode('body')); + $this->assertInstanceOf('\Twig\Node\IfNode', $node->getNode('body')); $this->assertEquals($body, $node->getNode('body')->getNode('tests')->getNode(1)->getNode(0)); $this->assertFalse($node->hasNode('else')); - $else = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1); - $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $else = new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1); + $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); $node->setAttribute('with_loop', false); $this->assertEquals($else, $node->getNode('else')); } @@ -40,13 +40,13 @@ public function getTests() { $tests = []; - $keyTarget = new Twig_Node_Expression_AssignName('key', 1); - $valueTarget = new Twig_Node_Expression_AssignName('item', 1); - $seq = new Twig_Node_Expression_Name('items', 1); + $keyTarget = new \Twig\Node\Expression\AssignNameExpression('key', 1); + $valueTarget = new \Twig\Node\Expression\AssignNameExpression('item', 1); + $seq = new \Twig\Node\Expression\NameExpression('items', 1); $ifexpr = null; - $body = new Twig_Node([new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1)], [], 1); + $body = new \Twig\Node\Node([new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1)], [], 1); $else = null; - $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); $node->setAttribute('with_loop', false); $tests[] = [$node, <<setAttribute('with_loop', true); $tests[] = [$node, <<setAttribute('with_loop', true); $tests[] = [$node, <<setAttribute('with_loop', true); $tests[] = [$node, <<assertEquals($t, $node->getNode('tests')); $this->assertFalse($node->hasNode('else')); - $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1); - $node = new Twig_Node_If($t, $else, 1); + $else = new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('bar', 1), 1); + $node = new \Twig\Node\IfNode($t, $else, 1); $this->assertEquals($else, $node->getNode('else')); } @@ -32,12 +32,12 @@ public function getTests() { $tests = []; - $t = new Twig_Node([ - new Twig_Node_Expression_Constant(true, 1), - new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1), + $t = new \Twig\Node\Node([ + new \Twig\Node\Expression\ConstantExpression(true, 1), + new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1), ], [], 1); $else = null; - $node = new Twig_Node_If($t, $else, 1); + $node = new \Twig\Node\IfNode($t, $else, 1); $tests[] = [$node, <<assertEquals($macro, $node->getNode('expr')); $this->assertEquals($var, $node->getNode('var')); @@ -25,9 +25,9 @@ public function getTests() { $tests = []; - $macro = new Twig_Node_Expression_Constant('foo.twig', 1); - $var = new Twig_Node_Expression_AssignName('macro', 1); - $node = new Twig_Node_Import($macro, $var, 1); + $macro = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1); + $var = new \Twig\Node\Expression\AssignNameExpression('macro', 1); + $node = new \Twig\Node\ImportNode($macro, $var, 1); $tests[] = [$node, <<assertFalse($node->hasNode('variables')); $this->assertEquals($expr, $node->getNode('expr')); $this->assertFalse($node->getAttribute('only')); - $vars = new Twig_Node_Expression_Array([new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)], 1); - $node = new Twig_Node_Include($expr, $vars, true, false, 1); + $vars = new \Twig\Node\Expression\ArrayExpression([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\ConstantExpression(true, 1)], 1); + $node = new \Twig\Node\IncludeNode($expr, $vars, true, false, 1); $this->assertEquals($vars, $node->getNode('variables')); $this->assertTrue($node->getAttribute('only')); } @@ -30,49 +30,49 @@ public function getTests() { $tests = []; - $expr = new Twig_Node_Expression_Constant('foo.twig', 1); - $node = new Twig_Node_Include($expr, null, false, false, 1); + $expr = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1); + $node = new \Twig\Node\IncludeNode($expr, null, false, false, 1); $tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(\$context); EOF ]; - $expr = new Twig_Node_Expression_Conditional( - new Twig_Node_Expression_Constant(true, 1), - new Twig_Node_Expression_Constant('foo', 1), - new Twig_Node_Expression_Constant('foo', 1), + $expr = new \Twig\Node\Expression\ConditionalExpression( + new \Twig\Node\Expression\ConstantExpression(true, 1), + new \Twig\Node\Expression\ConstantExpression('foo', 1), + new \Twig\Node\Expression\ConstantExpression('foo', 1), 0 ); - $node = new Twig_Node_Include($expr, null, false, false, 1); + $node = new \Twig\Node\IncludeNode($expr, null, false, false, 1); $tests[] = [$node, <<loadTemplate(((true) ? ("foo") : ("foo")), null, 1)->display(\$context); EOF ]; - $expr = new Twig_Node_Expression_Constant('foo.twig', 1); - $vars = new Twig_Node_Expression_Array([new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)], 1); - $node = new Twig_Node_Include($expr, $vars, false, false, 1); + $expr = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1); + $vars = new \Twig\Node\Expression\ArrayExpression([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\ConstantExpression(true, 1)], 1); + $node = new \Twig\Node\IncludeNode($expr, $vars, false, false, 1); $tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, ["foo" => true])); EOF ]; - $node = new Twig_Node_Include($expr, $vars, true, false, 1); + $node = new \Twig\Node\IncludeNode($expr, $vars, true, false, 1); $tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(["foo" => true]); EOF ]; - $node = new Twig_Node_Include($expr, $vars, true, true, 1); + $node = new \Twig\Node\IncludeNode($expr, $vars, true, true, 1); $tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(["foo" => true]); -} catch (Twig_Error_Loader \$e) { +} catch (\Twig\Error\LoaderError \$e) { // ignore missing template } EOF diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index 69203f31f1..944532ca11 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_MacroTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $body = new Twig_Node_Text('foo', 1); - $arguments = new Twig_Node([new Twig_Node_Expression_Name('foo', 1)], [], 1); - $node = new Twig_Node_Macro('foo', $body, $arguments, 1); + $body = new \Twig\Node\TextNode('foo', 1); + $arguments = new \Twig\Node\Node([new \Twig\Node\Expression\NameExpression('foo', 1)], [], 1); + $node = new \Twig\Node\MacroNode('foo', $body, $arguments, 1); $this->assertEquals($body, $node->getNode('body')); $this->assertEquals($arguments, $node->getNode('arguments')); @@ -24,12 +24,12 @@ public function testConstructor() public function getTests() { - $body = new Twig_Node_Text('foo', 1); - $arguments = new Twig_Node([ - 'foo' => new Twig_Node_Expression_Constant(null, 1), - 'bar' => new Twig_Node_Expression_Constant('Foo', 1), + $body = new \Twig\Node\TextNode('foo', 1); + $arguments = new \Twig\Node\Node([ + 'foo' => new \Twig\Node\Expression\ConstantExpression(null, 1), + 'bar' => new \Twig\Node\Expression\ConstantExpression('Foo', 1), ], [], 1); - $node = new Twig_Node_Macro('foo', $body, $arguments, 1); + $node = new \Twig\Node\MacroNode('foo', $body, $arguments, 1); if (PHP_VERSION_ID >= 50600) { $declaration = ', ...$__varargs__'; @@ -65,7 +65,7 @@ public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration) throw \$e; } - return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset()); + return ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset()); } EOF ], diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index 07be195479..61c94a10a2 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -9,17 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_ModuleTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_ModuleTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $body = new Twig_Node_Text('foo', 1); - $parent = new Twig_Node_Expression_Constant('layout.twig', 1); - $blocks = new Twig_Node(); - $macros = new Twig_Node(); - $traits = new Twig_Node(); - $source = new Twig_Source('{{ foo }}', 'foo.twig'); - $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $traits, new Twig_Node([]), $source); + $body = new \Twig\Node\TextNode('foo', 1); + $parent = new \Twig\Node\Expression\ConstantExpression('layout.twig', 1); + $blocks = new \Twig\Node\Node(); + $macros = new \Twig\Node\Node(); + $traits = new \Twig\Node\Node(); + $source = new \Twig\Source('{{ foo }}', 'foo.twig'); + $node = new \Twig\Node\ModuleNode($body, $parent, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source); $this->assertEquals($body, $node->getNode('body')); $this->assertEquals($blocks, $node->getNode('blocks')); @@ -30,25 +30,25 @@ public function testConstructor() public function getTests() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $tests = []; - $body = new Twig_Node_Text('foo', 1); + $body = new \Twig\Node\TextNode('foo', 1); $extends = null; - $blocks = new Twig_Node(); - $macros = new Twig_Node(); - $traits = new Twig_Node(); - $source = new Twig_Source('{{ foo }}', 'foo.twig'); + $blocks = new \Twig\Node\Node(); + $macros = new \Twig\Node\Node(); + $traits = new \Twig\Node\Node(); + $source = new \Twig\Source('{{ foo }}', 'foo.twig'); - $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node([]), $source); + $node = new \Twig\Node\ModuleNode($body, $extends, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source); $tests[] = [$node, <<getMockBuilder('Twig_LoaderInterface')->getMock(), ['debug' => true]); - $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node([]), $source); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['debug' => true]); + $node = new \Twig\Node\ModuleNode($body, $extends, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source); $tests[] = [$node, <<assertEquals($expr, $node->getNode('expr')); } @@ -22,7 +22,7 @@ public function testConstructor() public function getTests() { $tests = []; - $tests[] = [new Twig_Node_Print(new Twig_Node_Expression_Constant('foo', 1), 1), "// line 1\necho \"foo\";"]; + $tests[] = [new \Twig\Node\PrintNode(new \Twig\Node\Expression\ConstantExpression('foo', 1), 1), "// line 1\necho \"foo\";"]; return $tests; } diff --git a/test/Twig/Tests/Node/SandboxTest.php b/test/Twig/Tests/Node/SandboxTest.php index 24297da1c3..bfb3613913 100644 --- a/test/Twig/Tests/Node/SandboxTest.php +++ b/test/Twig/Tests/Node/SandboxTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_SandboxTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_SandboxTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $body = new Twig_Node_Text('foo', 1); - $node = new Twig_Node_Sandbox($body, 1); + $body = new \Twig\Node\TextNode('foo', 1); + $node = new \Twig\Node\SandboxNode($body, 1); $this->assertEquals($body, $node->getNode('body')); } @@ -23,12 +23,12 @@ public function getTests() { $tests = []; - $body = new Twig_Node_Text('foo', 1); - $node = new Twig_Node_Sandbox($body, 1); + $body = new \Twig\Node\TextNode('foo', 1); + $node = new \Twig\Node\SandboxNode($body, 1); $tests[] = [$node, <<env->getExtension('Twig_Extension_Sandbox'); +\$sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension'); if (!\$alreadySandboxed = \$sandbox->isSandboxed()) { \$sandbox->enableSandbox(); } diff --git a/test/Twig/Tests/Node/SandboxedPrintTest.php b/test/Twig/Tests/Node/SandboxedPrintTest.php index 61b69b279b..be593400fa 100644 --- a/test/Twig/Tests/Node/SandboxedPrintTest.php +++ b/test/Twig/Tests/Node/SandboxedPrintTest.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_SandboxedPrintTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_SandboxedPrintTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $node = new Twig_Node_SandboxedPrint($expr = new Twig_Node_Expression_Constant('foo', 1), 1); + $node = new \Twig\Node\SandboxedPrintNode($expr = new \Twig\Node\Expression\ConstantExpression('foo', 1), 1); $this->assertEquals($expr, $node->getNode('expr')); } @@ -22,9 +22,9 @@ public function getTests() { $tests = []; - $tests[] = [new Twig_Node_SandboxedPrint(new Twig_Node_Expression_Constant('foo', 1), 1), <<env->getExtension('Twig_Extension_Sandbox')->ensureToStringAllowed("foo"); +echo \$this->env->getExtension('\Twig\Extension\SandboxExtension')->ensureToStringAllowed("foo"); EOF ]; diff --git a/test/Twig/Tests/Node/SetTest.php b/test/Twig/Tests/Node/SetTest.php index e09583f8c0..d1b12d620e 100644 --- a/test/Twig/Tests/Node/SetTest.php +++ b/test/Twig/Tests/Node/SetTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_SetTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_SetTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $names = new Twig_Node([new Twig_Node_Expression_AssignName('foo', 1)], [], 1); - $values = new Twig_Node([new Twig_Node_Expression_Constant('foo', 1)], [], 1); - $node = new Twig_Node_Set(false, $names, $values, 1); + $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1); + $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1)], [], 1); + $node = new \Twig\Node\SetNode(false, $names, $values, 1); $this->assertEquals($names, $node->getNode('names')); $this->assertEquals($values, $node->getNode('values')); @@ -26,38 +26,38 @@ public function getTests() { $tests = []; - $names = new Twig_Node([new Twig_Node_Expression_AssignName('foo', 1)], [], 1); - $values = new Twig_Node([new Twig_Node_Expression_Constant('foo', 1)], [], 1); - $node = new Twig_Node_Set(false, $names, $values, 1); + $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1); + $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1)], [], 1); + $node = new \Twig\Node\SetNode(false, $names, $values, 1); $tests[] = [$node, <<env->getCharset()); +\$context["foo"] = ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset()); EOF ]; - $names = new Twig_Node([new Twig_Node_Expression_AssignName('foo', 1)], [], 1); - $values = new Twig_Node_Text('foo', 1); - $node = new Twig_Node_Set(true, $names, $values, 1); + $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1); + $values = new \Twig\Node\TextNode('foo', 1); + $node = new \Twig\Node\SetNode(true, $names, $values, 1); $tests[] = [$node, <<env->getCharset()); +\$context["foo"] = ('' === \$tmp = "foo") ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset()); EOF ]; - $names = new Twig_Node([new Twig_Node_Expression_AssignName('foo', 1), new Twig_Node_Expression_AssignName('bar', 1)], [], 1); - $values = new Twig_Node([new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Name('bar', 1)], [], 1); - $node = new Twig_Node_Set(false, $names, $values, 1); + $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1), new \Twig\Node\Expression\AssignNameExpression('bar', 1)], [], 1); + $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\NameExpression('bar', 1)], [], 1); + $node = new \Twig\Node\SetNode(false, $names, $values, 1); $tests[] = [$node, <<getVariableGetter('bar')}]; diff --git a/test/Twig/Tests/Node/SpacelessTest.php b/test/Twig/Tests/Node/SpacelessTest.php index c7e5fb6565..4cb5f996e7 100644 --- a/test/Twig/Tests/Node/SpacelessTest.php +++ b/test/Twig/Tests/Node/SpacelessTest.php @@ -9,20 +9,20 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_SpacelessTest extends Twig_Test_NodeTestCase +class Twig_Tests_Node_SpacelessTest extends \Twig\Test\NodeTestCase { public function testConstructor() { - $body = new Twig_Node([new Twig_Node_Text('
foo
', 1)]); - $node = new Twig_Node_Spaceless($body, 1); + $body = new \Twig\Node\Node([new \Twig\Node\TextNode('
foo
', 1)]); + $node = new \Twig\Node\SpacelessNode($body, 1); $this->assertEquals($body, $node->getNode('body')); } public function getTests() { - $body = new Twig_Node([new Twig_Node_Text('
foo
', 1)]); - $node = new Twig_Node_Spaceless($body, 1); + $body = new \Twig\Node\Node([new \Twig\Node\TextNode('
foo
', 1)]); + $node = new \Twig\Node\SpacelessNode($body, 1); return [ [$node, <<assertEquals('foo', $node->getAttribute('data')); } @@ -21,7 +21,7 @@ public function testConstructor() public function getTests() { $tests = []; - $tests[] = [new Twig_Node_Text('foo', 1), "// line 1\necho \"foo\";"]; + $tests[] = [new \Twig\Node\TextNode('foo', 1), "// line 1\necho \"foo\";"]; return $tests; } diff --git a/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/test/Twig/Tests/NodeVisitor/OptimizerTest.php index 1f8f9dba1e..0f5d2e347d 100644 --- a/test/Twig/Tests/NodeVisitor/OptimizerTest.php +++ b/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -12,25 +12,25 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase { public function testRenderBlockOptimizer() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $stream = $env->parse($env->tokenize(new Twig_Source('{{ block("foo") }}', 'index'))); + $stream = $env->parse($env->tokenize(new \Twig\Source('{{ block("foo") }}', 'index'))); $node = $stream->getNode('body')->getNode(0); - $this->assertInstanceOf('Twig_Node_Expression_BlockReference', $node); + $this->assertInstanceOf('\Twig\Node\Expression\BlockReferenceExpression', $node); $this->assertTrue($node->getAttribute('output')); } public function testRenderParentBlockOptimizer() { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $stream = $env->parse($env->tokenize(new Twig_Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index'))); + $stream = $env->parse($env->tokenize(new \Twig\Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index'))); $node = $stream->getNode('blocks')->getNode('content')->getNode(0)->getNode('body'); - $this->assertInstanceOf('Twig_Node_Expression_Parent', $node); + $this->assertInstanceOf('\Twig\Node\Expression\ParentExpression', $node); $this->assertTrue($node->getAttribute('output')); } @@ -40,12 +40,12 @@ public function testRenderVariableBlockOptimizer() $this->markTestSkipped('not needed on PHP >= 5.4'); } - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $stream = $env->parse($env->tokenize(new Twig_Source('{{ block(name|lower) }}', 'index'))); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $stream = $env->parse($env->tokenize(new \Twig\Source('{{ block(name|lower) }}', 'index'))); $node = $stream->getNode('body')->getNode(0)->getNode(1); - $this->assertInstanceOf('Twig_Node_Expression_BlockReference', $node); + $this->assertInstanceOf('\Twig\Node\Expression\BlockReferenceExpression', $node); $this->assertTrue($node->getAttribute('output')); } @@ -54,9 +54,9 @@ public function testRenderVariableBlockOptimizer() */ public function testForOptimizer($template, $expected) { - $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false]); + $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false]); - $stream = $env->parse($env->tokenize(new Twig_Source($template, 'index'))); + $stream = $env->parse($env->tokenize(new \Twig\Source($template, 'index'))); foreach ($expected as $target => $withLoop) { $this->assertTrue($this->checkForConfiguration($stream, $target, $withLoop), sprintf('variable %s is %soptimized', $target, $withLoop ? 'not ' : '')); @@ -109,7 +109,7 @@ public function checkForConfiguration(Twig_NodeInterface $node = null, $target, } foreach ($node as $n) { - if ($n instanceof Twig_Node_For) { + if ($n instanceof \Twig\Node\ForNode) { if ($target === $n->getNode('value_target')->getAttribute('name')) { return $withLoop == $n->getAttribute('with_loop'); } diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php index 2180200b70..4f8299eb57 100644 --- a/test/Twig/Tests/ParserTest.php +++ b/test/Twig/Tests/ParserTest.php @@ -11,43 +11,43 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase { /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError */ public function testSetMacroThrowsExceptionOnReservedMethods() { $parser = $this->getParser(); - $parser->setMacro('parent', $this->getMockBuilder('Twig_Node_Macro')->disableOriginalConstructor()->getMock()); + $parser->setMacro('parent', $this->getMockBuilder('\Twig\Node\MacroNode')->disableOriginalConstructor()->getMock()); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown "foo" tag. Did you mean "for" at line 1? */ public function testUnknownTag() { - $stream = new Twig_TokenStream([ - new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), - new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 1), - new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), - new Twig_Token(Twig_Token::EOF_TYPE, '', 1), + $stream = new \Twig\TokenStream([ + new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1), + new \Twig\Token(\Twig\Token::NAME_TYPE, 'foo', 1), + new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1), + new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1), ]); - $parser = new Twig_Parser(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $parser = new \Twig\Parser(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $parser->parse($stream); } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unknown "foobar" tag at line 1. */ public function testUnknownTagWithoutSuggestions() { - $stream = new Twig_TokenStream([ - new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), - new Twig_Token(Twig_Token::NAME_TYPE, 'foobar', 1), - new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), - new Twig_Token(Twig_Token::EOF_TYPE, '', 1), + $stream = new \Twig\TokenStream([ + new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1), + new \Twig\Token(\Twig\Token::NAME_TYPE, 'foobar', 1), + new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1), + new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1), ]); - $parser = new Twig_Parser(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $parser = new \Twig\Parser(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $parser->parse($stream); } @@ -65,15 +65,15 @@ public function getFilterBodyNodesData() { return [ [ - new Twig_Node([new Twig_Node_Text(' ', 1)]), - new Twig_Node([]), + new \Twig\Node\Node([new \Twig\Node\TextNode(' ', 1)]), + new \Twig\Node\Node([]), ], [ - $input = new Twig_Node([new Twig_Node_Set(false, new Twig_Node(), new Twig_Node(), 1)]), + $input = new \Twig\Node\Node([new \Twig\Node\SetNode(false, new \Twig\Node\Node(), new \Twig\Node\Node(), 1)]), $input, ], [ - $input = new Twig_Node([new Twig_Node_Set(true, new Twig_Node(), new Twig_Node([new Twig_Node([new Twig_Node_Text('foo', 1)])]), 1)]), + $input = new \Twig\Node\Node([new \Twig\Node\SetNode(true, new \Twig\Node\Node(), new \Twig\Node\Node([new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)])]), 1)]), $input, ], ]; @@ -81,7 +81,7 @@ public function getFilterBodyNodesData() /** * @dataProvider getFilterBodyNodesDataThrowsException - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError */ public function testFilterBodyNodesThrowsException($input) { @@ -93,8 +93,8 @@ public function testFilterBodyNodesThrowsException($input) public function getFilterBodyNodesDataThrowsException() { return [ - [new Twig_Node_Text('foo', 1)], - [new Twig_Node([new Twig_Node([new Twig_Node_Text('foo', 1)])])], + [new \Twig\Node\TextNode('foo', 1)], + [new \Twig\Node\Node([new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)])])], ]; } @@ -103,7 +103,7 @@ public function getFilterBodyNodesDataThrowsException() */ public function testFilterBodyNodesWithBOM($emptyNode) { - $this->assertNull($this->getParser()->filterBodyNodes(new Twig_Node_Text(\chr(0xEF).\chr(0xBB).\chr(0xBF).$emptyNode, 1))); + $this->assertNull($this->getParser()->filterBodyNodes(new \Twig\Node\TextNode(\chr(0xEF).\chr(0xBB).\chr(0xBF).$emptyNode, 1))); } public function getFilterBodyNodesWithBOMData() @@ -118,22 +118,22 @@ public function getFilterBodyNodesWithBOMData() public function testParseIsReentrant() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), [ + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), [ 'autoescape' => false, 'optimizations' => 0, ]); $twig->addTokenParser(new TestTokenParser()); - $parser = new Twig_Parser($twig); + $parser = new \Twig\Parser($twig); - $parser->parse(new Twig_TokenStream([ - new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), - new Twig_Token(Twig_Token::NAME_TYPE, 'test', 1), - new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), - new Twig_Token(Twig_Token::VAR_START_TYPE, '', 1), - new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 1), - new Twig_Token(Twig_Token::VAR_END_TYPE, '', 1), - new Twig_Token(Twig_Token::EOF_TYPE, '', 1), + $parser->parse(new \Twig\TokenStream([ + new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1), + new \Twig\Token(\Twig\Token::NAME_TYPE, 'test', 1), + new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1), + new \Twig\Token(\Twig\Token::VAR_START_TYPE, '', 1), + new \Twig\Token(\Twig\Token::NAME_TYPE, 'foo', 1), + new \Twig\Token(\Twig\Token::VAR_END_TYPE, '', 1), + new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1), ])); $this->assertNull($parser->getParent()); @@ -141,12 +141,12 @@ public function testParseIsReentrant() public function testGetVarName() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), [ + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), [ 'autoescape' => false, 'optimizations' => 0, ]); - $twig->parse($twig->tokenize(new Twig_Source(<<parse($twig->tokenize(new \Twig\Source(<<getMockBuilder('Twig_LoaderInterface')->getMock())); - $parser->setParent(new Twig_Node()); - $parser->stream = new Twig_TokenStream([]); + $parser = new TestParser(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $parser->setParent(new \Twig\Node\Node()); + $parser->stream = new \Twig\TokenStream([]); return $parser; } } -class TestParser extends Twig_Parser +class TestParser extends \Twig\Parser { public $stream; @@ -181,22 +181,22 @@ public function filterBodyNodes(Twig_NodeInterface $node) } } -class TestTokenParser extends Twig_TokenParser +class TestTokenParser extends \Twig\TokenParser\AbstractTokenParser { - public function parse(Twig_Token $token) + public function parse(\Twig\Token $token) { // simulate the parsing of another template right in the middle of the parsing of the current template - $this->parser->parse(new Twig_TokenStream([ - new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), - new Twig_Token(Twig_Token::NAME_TYPE, 'extends', 1), - new Twig_Token(Twig_Token::STRING_TYPE, 'base', 1), - new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), - new Twig_Token(Twig_Token::EOF_TYPE, '', 1), + $this->parser->parse(new \Twig\TokenStream([ + new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1), + new \Twig\Token(\Twig\Token::NAME_TYPE, 'extends', 1), + new \Twig\Token(\Twig\Token::STRING_TYPE, 'base', 1), + new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1), + new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1), ])); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); - return new Twig_Node([]); + return new \Twig\Node\Node([]); } public function getTag() diff --git a/test/Twig/Tests/Profiler/Dumper/AbstractTest.php b/test/Twig/Tests/Profiler/Dumper/AbstractTest.php index ed3797b48c..62f3821cfe 100644 --- a/test/Twig/Tests/Profiler/Dumper/AbstractTest.php +++ b/test/Twig/Tests/Profiler/Dumper/AbstractTest.php @@ -13,7 +13,7 @@ abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends \PHPUnit\Framewor { protected function getProfile() { - $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock(); + $profile = $this->getMockBuilder('\Twig\Profiler\Profile')->disableOriginalConstructor()->getMock(); $profile->expects($this->any())->method('isRoot')->will($this->returnValue(true)); $profile->expects($this->any())->method('getName')->will($this->returnValue('main')); @@ -79,11 +79,11 @@ private function getMacroProfile(array $subProfiles = []) * @param string $templateName * @param array $subProfiles * - * @return Twig_Profiler_Profile + * @return \Twig\Profiler\Profile */ private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = []) { - $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock(); + $profile = $this->getMockBuilder('\Twig\Profiler\Profile')->disableOriginalConstructor()->getMock(); $profile->expects($this->any())->method('isRoot')->will($this->returnValue(false)); $profile->expects($this->any())->method('getName')->will($this->returnValue($name)); diff --git a/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php b/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php index 1a1b9d299b..23846630e6 100644 --- a/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php +++ b/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php @@ -13,7 +13,7 @@ class Twig_Tests_Profiler_Dumper_BlackfireTest extends Twig_Tests_Profiler_Dumpe { public function testDump() { - $dumper = new Twig_Profiler_Dumper_Blackfire(); + $dumper = new \Twig\Profiler\Dumper\BlackfireDumper(); $this->assertStringMatchesFormat(<<assertStringMatchesFormat(<<main %d.%dms/%d%index.twig %d.%dms/%d% diff --git a/test/Twig/Tests/Profiler/Dumper/TextTest.php b/test/Twig/Tests/Profiler/Dumper/TextTest.php index e2ea165ace..fbd7475c00 100644 --- a/test/Twig/Tests/Profiler/Dumper/TextTest.php +++ b/test/Twig/Tests/Profiler/Dumper/TextTest.php @@ -13,7 +13,7 @@ class Twig_Tests_Profiler_Dumper_TextTest extends Twig_Tests_Profiler_Dumper_Abs { public function testDump() { - $dumper = new Twig_Profiler_Dumper_Text(); + $dumper = new \Twig\Profiler\Dumper\TextDumper(); $this->assertStringMatchesFormat(<<assertEquals('template', $profile->getTemplate()); $this->assertEquals('type', $profile->getType()); @@ -22,45 +22,45 @@ public function testConstructor() public function testIsRoot() { - $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT); + $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT); $this->assertTrue($profile->isRoot()); - $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::TEMPLATE); + $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::TEMPLATE); $this->assertFalse($profile->isRoot()); } public function testIsTemplate() { - $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::TEMPLATE); + $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::TEMPLATE); $this->assertTrue($profile->isTemplate()); - $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT); + $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT); $this->assertFalse($profile->isTemplate()); } public function testIsBlock() { - $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::BLOCK); + $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::BLOCK); $this->assertTrue($profile->isBlock()); - $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT); + $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT); $this->assertFalse($profile->isBlock()); } public function testIsMacro() { - $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::MACRO); + $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::MACRO); $this->assertTrue($profile->isMacro()); - $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT); + $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT); $this->assertFalse($profile->isMacro()); } public function testGetAddProfile() { - $profile = new Twig_Profiler_Profile(); - $profile->addProfile($a = new Twig_Profiler_Profile()); - $profile->addProfile($b = new Twig_Profiler_Profile()); + $profile = new \Twig\Profiler\Profile(); + $profile->addProfile($a = new \Twig\Profiler\Profile()); + $profile->addProfile($b = new \Twig\Profiler\Profile()); $this->assertSame([$a, $b], $profile->getProfiles()); $this->assertSame([$a, $b], iterator_to_array($profile)); @@ -68,7 +68,7 @@ public function testGetAddProfile() public function testGetDuration() { - $profile = new Twig_Profiler_Profile(); + $profile = new \Twig\Profiler\Profile(); usleep(1); $profile->leave(); @@ -77,8 +77,8 @@ public function testGetDuration() public function testSerialize() { - $profile = new Twig_Profiler_Profile('template', 'type', 'name'); - $profile1 = new Twig_Profiler_Profile('template1', 'type1', 'name1'); + $profile = new \Twig\Profiler\Profile('template', 'type', 'name'); + $profile1 = new \Twig\Profiler\Profile('template1', 'type1', 'name1'); $profile->addProfile($profile1); $profile->leave(); $profile1->leave(); @@ -100,7 +100,7 @@ public function testSerialize() public function testReset() { - $profile = new Twig_Profiler_Profile(); + $profile = new \Twig\Profiler\Profile(); usleep(1); $profile->leave(); $profile->reset(); diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 16a01a3573..eb499d4d48 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -15,7 +15,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase */ public function testDisplayBlocksAcceptTemplateOnlyAsBlocks() { - $template = $this->getMockForAbstractClass('Twig_Template', [], '', false); + $template = $this->getMockForAbstractClass('\Twig\Template', [], '', false); $template->displayBlock('foo', [], ['foo' => [new \stdClass(), 'foo']]); } @@ -25,7 +25,7 @@ public function testDisplayBlocksAcceptTemplateOnlyAsBlocks() public function testGetAttributeExceptions($template, $message) { $templates = ['index' => $template]; - $env = new Twig_Environment(new Twig_Loader_Array($templates), ['strict_variables' => true]); + $env = new \Twig\Environment(new \Twig\Loader\ArrayLoader($templates), ['strict_variables' => true]); $template = $env->loadTemplate('index'); $context = [ @@ -41,7 +41,7 @@ public function testGetAttributeExceptions($template, $message) try { $template->render($context); $this->fail('Accessing an invalid attribute should throw an exception.'); - } catch (Twig_Error_Runtime $e) { + } catch (\Twig\Error\RuntimeError $e) { $this->assertSame(sprintf($message, 'index'), $e->getMessage()); } } @@ -74,9 +74,9 @@ public function getAttributeExceptions() */ public function testGetAttributeWithSandbox($object, $item, $allowed) { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $policy = new Twig_Sandbox_SecurityPolicy([], [], [/*method*/], [/*prop*/], []); - $twig->addExtension(new Twig_Extension_Sandbox($policy, !$allowed)); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $policy = new \Twig\Sandbox\SecurityPolicy([], [], [/*method*/], [/*prop*/], []); + $twig->addExtension(new \Twig\Extension\SandboxExtension($policy, !$allowed)); $template = new Twig_TemplateTest($twig); try { @@ -87,7 +87,7 @@ public function testGetAttributeWithSandbox($object, $item, $allowed) } else { $this->addToAssertionCount(1); } - } catch (Twig_Sandbox_SecurityError $e) { + } catch (\Twig\Sandbox\SecurityError $e) { if ($allowed) { $this->fail(); } else { @@ -114,28 +114,28 @@ public function getGetAttributeWithSandbox() public function testGetAttributeWithTemplateAsObject() { // to be removed in 2.0 - $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); - //$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); + //$twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface')->getMock()); $template = new Twig_TemplateTest($twig, 'index.twig'); $template1 = new Twig_TemplateTest($twig, 'index1.twig'); - $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'string')); + $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'string')); $this->assertEquals('some_string', $template->getAttribute($template1, 'string')); - $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'true')); + $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'true')); $this->assertEquals('1', $template->getAttribute($template1, 'true')); - $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'zero')); + $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'zero')); $this->assertEquals('0', $template->getAttribute($template1, 'zero')); - $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty')); + $this->assertNotInstanceof('\Twig\Markup', $template->getAttribute($template1, 'empty')); $this->assertSame('', $template->getAttribute($template1, 'empty')); - $this->assertFalse($template->getAttribute($template1, 'env', [], Twig_Template::ANY_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'environment', [], Twig_Template::ANY_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], Twig_Template::METHOD_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], Twig_Template::METHOD_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'env', [], \Twig\Template::ANY_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'environment', [], \Twig\Template::ANY_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], \Twig\Template::METHOD_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], \Twig\Template::METHOD_CALL, true)); } /** @@ -162,22 +162,22 @@ public function testGetAttributeWithTemplateAsObject() public function testGetAttributeWithTemplateAsObjectForDeprecations() { // to be removed in 2.0 - $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); - //$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); + //$twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface')->getMock()); $template = new Twig_TemplateTest($twig, 'index.twig'); $template1 = new Twig_TemplateTest($twig, 'index1.twig'); - $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'string')); + $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'string')); $this->assertEquals('some_string', $template->getAttribute($template1, 'string')); - $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'true')); + $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'true')); $this->assertEquals('1', $template->getAttribute($template1, 'true')); - $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'zero')); + $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'zero')); $this->assertEquals('0', $template->getAttribute($template1, 'zero')); - $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty')); + $this->assertNotInstanceof('\Twig\Markup', $template->getAttribute($template1, 'empty')); $this->assertSame('', $template->getAttribute($template1, 'empty')); $blocks = ['name' => [$template1, 'block_name']]; @@ -195,10 +195,10 @@ public function testGetAttributeWithTemplateAsObjectForDeprecations() $template->getAttribute($template1, 'render', [[]]); $template->getAttribute($template1, 'display', [[]]); - $this->assertFalse($template->getAttribute($template1, 'env', [], Twig_Template::ANY_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'environment', [], Twig_Template::ANY_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], Twig_Template::METHOD_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], Twig_Template::METHOD_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'env', [], \Twig\Template::ANY_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'environment', [], \Twig\Template::ANY_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], \Twig\Template::METHOD_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], \Twig\Template::METHOD_CALL, true)); } /** @@ -208,7 +208,7 @@ public function testGetAttributeWithTemplateAsObjectForDeprecations() */ public function testRenderBlockWithUndefinedBlock() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); + $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); $template = new Twig_TemplateTest($twig, 'index.twig'); $template->renderBlock('unknown', []); @@ -217,7 +217,7 @@ public function testRenderBlockWithUndefinedBlock() public function testGetAttributeOnArrayWithConfusableKey() { - $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $array = ['Zero', 'One', -1 => 'MinusOne', '' => 'EmptyString', '1.5' => 'FloatButString', '01' => 'IntegerButStringWithLeadingZeros']; @@ -245,7 +245,7 @@ public function testGetAttributeOnArrayWithConfusableKey() */ public function testGetAttribute($defined, $value, $object, $item, $arguments, $type) { - $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type)); } @@ -255,18 +255,18 @@ public function testGetAttribute($defined, $value, $object, $item, $arguments, $ */ public function testGetAttributeStrict($defined, $value, $object, $item, $arguments, $type, $exceptionMessage = null) { - $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => true])); + $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); if ($defined) { $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type)); } else { if (method_exists($this, 'expectException')) { - $this->expectException('Twig_Error_Runtime'); + $this->expectException('\Twig\Error\RuntimeError'); if (null !== $exceptionMessage) { $this->expectExceptionMessage($exceptionMessage); } } else { - $this->setExpectedException('Twig_Error_Runtime', $exceptionMessage); + $this->setExpectedException('\Twig\Error\RuntimeError', $exceptionMessage); } $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type)); } @@ -277,7 +277,7 @@ public function testGetAttributeStrict($defined, $value, $object, $item, $argume */ public function testGetAttributeDefined($defined, $value, $object, $item, $arguments, $type) { - $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true)); } @@ -287,14 +287,14 @@ public function testGetAttributeDefined($defined, $value, $object, $item, $argum */ public function testGetAttributeDefinedStrict($defined, $value, $object, $item, $arguments, $type) { - $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => true])); + $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); $this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true)); } public function testGetAttributeCallExceptions() { - $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $object = new Twig_TemplateMagicMethodExceptionObject(); @@ -325,9 +325,9 @@ public function getGetAttributeTests() $methodObject = new Twig_TemplateMethodObject(); $magicMethodObject = new Twig_TemplateMagicMethodObject(); - $anyType = Twig_Template::ANY_CALL; - $methodType = Twig_Template::METHOD_CALL; - $arrayType = Twig_Template::ARRAY_CALL; + $anyType = \Twig\Template::ANY_CALL; + $methodType = \Twig\Template::METHOD_CALL; + $arrayType = \Twig\Template::ARRAY_CALL; $basicTests = [ // array(defined, value, property to fetch) @@ -434,12 +434,12 @@ public function getGetAttributeTests() } /** - * @expectedException \Twig_Error_Runtime + * @expectedException \Twig\Error\RuntimeError */ public function testGetIsMethods() { $getIsObject = new Twig_TemplateGetIsMethods(); - $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => true])); + $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); // first time should not create a cache for "get" $this->assertNull($template->getAttribute($getIsObject, 'get')); // 0 should be in the method cache now, so this should fail @@ -447,11 +447,11 @@ public function testGetIsMethods() } } -class Twig_TemplateTest extends Twig_Template +class Twig_TemplateTest extends \Twig\Template { private $name; - public function __construct(Twig_Environment $env, $name = 'index.twig') + public function __construct(\Twig\Environment $env, $name = 'index.twig') { parent::__construct($env); self::$cache = []; @@ -497,7 +497,7 @@ protected function doDisplay(array $context, array $blocks = []) { } - public function getAttribute($object, $item, array $arguments = [], $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) + public function getAttribute($object, $item, array $arguments = [], $type = \Twig\Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) { if (\function_exists('twig_template_get_attributes')) { return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); @@ -771,18 +771,18 @@ public function __call($method, $arguments) } } -class CExtDisablingNodeVisitor implements Twig_NodeVisitorInterface +class CExtDisablingNodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface { - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env) { - if ($node instanceof Twig_Node_Expression_GetAttr) { + if ($node instanceof \Twig\Node\Expression\GetAttrExpression) { $node->setAttribute('disable_c_ext', true); } return $node; } - public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env) { return $node; } @@ -794,6 +794,6 @@ public function getPriority() } // to be removed in 2.0 -interface Twig_TemplateTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface +interface Twig_TemplateTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface { } diff --git a/test/Twig/Tests/TemplateWrapperTest.php b/test/Twig/Tests/TemplateWrapperTest.php index 0e7833ed11..68646e80fb 100644 --- a/test/Twig/Tests/TemplateWrapperTest.php +++ b/test/Twig/Tests/TemplateWrapperTest.php @@ -12,7 +12,7 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase { public function testHasGetBlocks() { - $twig = new Twig_Environment(new Twig_Loader_Array([ + $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ 'index' => '{% block foo %}{% endblock %}', 'index_with_use' => '{% use "imported" %}{% block foo %}{% endblock %}', 'index_with_extends' => '{% extends "extended" %}{% block foo %}{% endblock %}', @@ -20,17 +20,17 @@ public function testHasGetBlocks() 'extended' => '{% block extended %}{% endblock %}', ])); - $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index')); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertFalse($wrapper->hasBlock('bar')); $this->assertEquals(['foo'], $wrapper->getBlockNames()); - $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index_with_use')); + $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index_with_use')); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('imported')); $this->assertEquals(['imported', 'foo'], $wrapper->getBlockNames()); - $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index_with_extends')); + $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index_with_extends')); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('extended')); $this->assertEquals(['foo', 'extended'], $wrapper->getBlockNames()); @@ -38,23 +38,23 @@ public function testHasGetBlocks() public function testRenderBlock() { - $twig = new Twig_Environment(new Twig_Loader_Array([ + $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ 'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}', ])); $twig->addGlobal('bar', 'BAR'); - $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index')); $this->assertEquals('FOOBAR', $wrapper->renderBlock('foo', ['foo' => 'FOO'])); } public function testDisplayBlock() { - $twig = new Twig_Environment(new Twig_Loader_Array([ + $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ 'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}', ])); $twig->addGlobal('bar', 'BAR'); - $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index')); ob_start(); $wrapper->displayBlock('foo', ['foo' => 'FOO']); diff --git a/test/Twig/Tests/TokenStreamTest.php b/test/Twig/Tests/TokenStreamTest.php index 1867b42989..a7f4d181c3 100644 --- a/test/Twig/Tests/TokenStreamTest.php +++ b/test/Twig/Tests/TokenStreamTest.php @@ -16,14 +16,14 @@ class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase protected function setUp() { self::$tokens = [ - new Twig_Token(Twig_Token::TEXT_TYPE, 1, 1), - new Twig_Token(Twig_Token::TEXT_TYPE, 2, 1), - new Twig_Token(Twig_Token::TEXT_TYPE, 3, 1), - new Twig_Token(Twig_Token::TEXT_TYPE, 4, 1), - new Twig_Token(Twig_Token::TEXT_TYPE, 5, 1), - new Twig_Token(Twig_Token::TEXT_TYPE, 6, 1), - new Twig_Token(Twig_Token::TEXT_TYPE, 7, 1), - new Twig_Token(Twig_Token::EOF_TYPE, 0, 1), + new \Twig\Token(\Twig\Token::TEXT_TYPE, 1, 1), + new \Twig\Token(\Twig\Token::TEXT_TYPE, 2, 1), + new \Twig\Token(\Twig\Token::TEXT_TYPE, 3, 1), + new \Twig\Token(\Twig\Token::TEXT_TYPE, 4, 1), + new \Twig\Token(\Twig\Token::TEXT_TYPE, 5, 1), + new \Twig\Token(\Twig\Token::TEXT_TYPE, 6, 1), + new \Twig\Token(\Twig\Token::TEXT_TYPE, 7, 1), + new \Twig\Token(\Twig\Token::EOF_TYPE, 0, 1), ]; } @@ -32,7 +32,7 @@ protected function setUp() */ public function testLegacyConstructorSignature() { - $stream = new Twig_TokenStream([], 'foo', '{{ foo }}'); + $stream = new \Twig\TokenStream([], 'foo', '{{ foo }}'); $this->assertEquals('foo', $stream->getFilename()); $this->assertEquals('{{ foo }}', $stream->getSource()); $this->assertEquals('foo', $stream->getSourceContext()->getName()); @@ -41,7 +41,7 @@ public function testLegacyConstructorSignature() public function testNext() { - $stream = new Twig_TokenStream(self::$tokens); + $stream = new \Twig\TokenStream(self::$tokens); $repr = []; while (!$stream->isEOF()) { $token = $stream->next(); @@ -52,13 +52,13 @@ public function testNext() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unexpected end of template */ public function testEndOfTemplateNext() { - $stream = new Twig_TokenStream([ - new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1), + $stream = new \Twig\TokenStream([ + new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, 1, 1), ]); while (!$stream->isEOF()) { $stream->next(); @@ -66,13 +66,13 @@ public function testEndOfTemplateNext() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unexpected end of template */ public function testEndOfTemplateLook() { - $stream = new Twig_TokenStream([ - new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1), + $stream = new \Twig\TokenStream([ + new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, 1, 1), ]); while (!$stream->isEOF()) { $stream->look(); diff --git a/test/Twig/Tests/Util/DeprecationCollectorTest.php b/test/Twig/Tests/Util/DeprecationCollectorTest.php index 1d0ff01760..5d72f94074 100644 --- a/test/Twig/Tests/Util/DeprecationCollectorTest.php +++ b/test/Twig/Tests/Util/DeprecationCollectorTest.php @@ -16,10 +16,10 @@ class Twig_Tests_Util_DeprecationCollectorTest extends \PHPUnit\Framework\TestCa */ public function testCollect() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $twig->addFunction(new Twig_SimpleFunction('deprec', [$this, 'deprec'], ['deprecated' => true])); + $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig->addFunction(new \Twig\TwigFunction('deprec', [$this, 'deprec'], ['deprecated' => true])); - $collector = new Twig_Util_DeprecationCollector($twig); + $collector = new \Twig\Util\DeprecationCollector($twig); $deprecations = $collector->collect(new Twig_Tests_Util_Iterator()); $this->assertEquals(['Twig Function "deprec" is deprecated in deprec.twig at line 1.'], $deprecations); diff --git a/test/Twig/Tests/escapingTest.php b/test/Twig/Tests/escapingTest.php index 7bbd92cfed..6de31a9354 100644 --- a/test/Twig/Tests/escapingTest.php +++ b/test/Twig/Tests/escapingTest.php @@ -151,7 +151,7 @@ class Twig_Test_EscapingTest extends \PHPUnit\Framework\TestCase protected function setUp() { - $this->env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $this->env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); } public function testHtmlEscapingConvertsSpecialChars()