Browse code

moved to namespaced classes by default

Fabien Potencier authored on 15/02/2019 05:44:44
Showing 276 changed files
... ...
@@ -114,7 +114,7 @@ Globals
114 114
 A global variable is like any other template variable, except that it's
115 115
 available in all templates and macros::
116 116
 
117
-    $twig = new Twig_Environment($loader);
117
+    $twig = new \Twig\Environment($loader);
118 118
     $twig->addGlobal('text', new Text());
119 119
 
120 120
 You can then use the ``text`` variable anywhere in a template:
... ...
@@ -129,29 +129,29 @@ Filters
129 129
 Creating a filter is as simple as associating a name with a PHP callable::
130 130
 
131 131
     // an anonymous function
132
-    $filter = new Twig_SimpleFilter('rot13', function ($string) {
132
+    $filter = new \Twig\TwigFilter('rot13', function ($string) {
133 133
         return str_rot13($string);
134 134
     });
135 135
 
136 136
     // or a simple PHP function
137
-    $filter = new Twig_SimpleFilter('rot13', 'str_rot13');
137
+    $filter = new \Twig\TwigFilter('rot13', 'str_rot13');
138 138
 
139 139
     // or a class static method
140
-    $filter = new Twig_SimpleFilter('rot13', ['SomeClass', 'rot13Filter']);
141
-    $filter = new Twig_SimpleFilter('rot13', 'SomeClass::rot13Filter');
140
+    $filter = new \Twig\TwigFilter('rot13', ['SomeClass', 'rot13Filter']);
141
+    $filter = new \Twig\TwigFilter('rot13', 'SomeClass::rot13Filter');
142 142
 
143 143
     // or a class method
144
-    $filter = new Twig_SimpleFilter('rot13', [$this, 'rot13Filter']);
144
+    $filter = new \Twig\TwigFilter('rot13', [$this, 'rot13Filter']);
145 145
     // the one below needs a runtime implementation (see below for more information)
146
-    $filter = new Twig_SimpleFilter('rot13', ['SomeClass', 'rot13Filter']);
146
+    $filter = new \Twig\TwigFilter('rot13', ['SomeClass', 'rot13Filter']);
147 147
 
148
-The first argument passed to the ``Twig_SimpleFilter`` constructor is the name
148
+The first argument passed to the ``\Twig\TwigFilter`` constructor is the name
149 149
 of the filter you will use in templates and the second one is the PHP callable
150 150
 to associate with it.
151 151
 
152 152
 Then, add the filter to your Twig environment::
153 153
 
154
-    $twig = new Twig_Environment($loader);
154
+    $twig = new \Twig\Environment($loader);
155 155
     $twig->addFilter($filter);
156 156
 
157 157
 And here is how to use it in a template:
... ...
@@ -178,10 +178,10 @@ is compiled to something like the following::
178 178
     <?php echo strtolower('TWIG') ?>
179 179
     <?php echo twig_date_format_filter($now, 'd/m/Y') ?>
180 180
 
181
-The ``Twig_SimpleFilter`` class takes an array of options as its last
181
+The ``\Twig\TwigFilter`` class takes an array of options as its last
182 182
 argument::
183 183
 
184
-    $filter = new Twig_SimpleFilter('rot13', 'str_rot13', $options);
184
+    $filter = new \Twig\TwigFilter('rot13', 'str_rot13', $options);
185 185
 
186 186
 Environment-aware Filters
187 187
 ~~~~~~~~~~~~~~~~~~~~~~~~~
... ...
@@ -190,7 +190,7 @@ If you want to access the current environment instance in your filter, set the
190 190
 ``needs_environment`` option to ``true``; Twig will pass the current
191 191
 environment as the first argument to the filter call::
192 192
 
193
-    $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $string) {
193
+    $filter = new \Twig\TwigFilter('rot13', function (Twig_Environment $env, $string) {
194 194
         // get the current charset for instance
195 195
         $charset = $env->getCharset();
196 196
 
... ...
@@ -205,11 +205,11 @@ If you want to access the current context in your filter, set the
205 205
 the first argument to the filter call (or the second one if
206 206
 ``needs_environment`` is also set to ``true``)::
207 207
 
208
-    $filter = new Twig_SimpleFilter('rot13', function ($context, $string) {
208
+    $filter = new \Twig\TwigFilter('rot13', function ($context, $string) {
209 209
         // ...
210 210
     }, ['needs_context' => true]);
211 211
 
212
-    $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $context, $string) {
212
+    $filter = new \Twig\TwigFilter('rot13', function (Twig_Environment $env, $context, $string) {
213 213
         // ...
214 214
     }, ['needs_context' => true, 'needs_environment' => true]);
215 215
 
... ...
@@ -221,14 +221,14 @@ before printing. If your filter acts as an escaper (or explicitly outputs HTML
221 221
 or JavaScript code), you will want the raw output to be printed. In such a
222 222
 case, set the ``is_safe`` option::
223 223
 
224
-    $filter = new Twig_SimpleFilter('nl2br', 'nl2br', ['is_safe' => ['html']]);
224
+    $filter = new \Twig\TwigFilter('nl2br', 'nl2br', ['is_safe' => ['html']]);
225 225
 
226 226
 Some filters may need to work on input that is already escaped or safe, for
227 227
 example when adding (safe) HTML tags to originally unsafe output. In such a
228 228
 case, set the ``pre_escape`` option to escape the input data before it is run
229 229
 through your filter::
230 230
 
231
-    $filter = new Twig_SimpleFilter('somefilter', 'somefilter', ['pre_escape' => 'html', 'is_safe' => ['html']]);
231
+    $filter = new \Twig\TwigFilter('somefilter', 'somefilter', ['pre_escape' => 'html', 'is_safe' => ['html']]);
232 232
 
233 233
 Variadic Filters
234 234
 ~~~~~~~~~~~~~~~~
... ...
@@ -240,7 +240,7 @@ When a filter should accept an arbitrary number of arguments, set the
240 240
 ``is_variadic`` option to ``true``; Twig will pass the extra arguments as the
241 241
 last argument to the filter call as an array::
242 242
 
243
-    $filter = new Twig_SimpleFilter('thumbnail', function ($file, array $options = []) {
243
+    $filter = new \Twig\TwigFilter('thumbnail', function ($file, array $options = []) {
244 244
         // ...
245 245
     }, ['is_variadic' => true]);
246 246
 
... ...
@@ -254,7 +254,7 @@ Dynamic Filters
254 254
 A filter name containing the special ``*`` character is a dynamic filter as
255 255
 the ``*`` can be any string::
256 256
 
257
-    $filter = new Twig_SimpleFilter('*_path', function ($name, $arguments) {
257
+    $filter = new \Twig\TwigFilter('*_path', function ($name, $arguments) {
258 258
         // ...
259 259
     });
260 260
 
... ...
@@ -265,7 +265,7 @@ The following filters will be matched by the above defined dynamic filter:
265 265
 
266 266
 A dynamic filter can define more than one dynamic parts::
267 267
 
268
-    $filter = new Twig_SimpleFilter('*_path_*', function ($name, $suffix, $arguments) {
268
+    $filter = new \Twig\TwigFilter('*_path_*', function ($name, $suffix, $arguments) {
269 269
         // ...
270 270
     });
271 271
 
... ...
@@ -284,7 +284,7 @@ You can mark a filter as being deprecated by setting the ``deprecated`` option
284 284
 to ``true``. You can also give an alternative filter that replaces the
285 285
 deprecated one when that makes sense::
286 286
 
287
-    $filter = new Twig_SimpleFilter('obsolete', function () {
287
+    $filter = new \Twig\TwigFilter('obsolete', function () {
288 288
         // ...
289 289
     }, ['deprecated' => true, 'alternative' => 'new_one']);
290 290
 
... ...
@@ -295,10 +295,10 @@ Functions
295 295
 ---------
296 296
 
297 297
 Functions are defined in the exact same way as filters, but you need to create
298
-an instance of ``Twig_SimpleFunction``::
298
+an instance of ``\Twig\TwigFunction``::
299 299
 
300
-    $twig = new Twig_Environment($loader);
301
-    $function = new Twig_SimpleFunction('function_name', function () {
300
+    $twig = new \Twig\Environment($loader);
301
+    $function = new \Twig\TwigFunction('function_name', function () {
302 302
         // ...
303 303
     });
304 304
     $twig->addFunction($function);
... ...
@@ -310,10 +310,10 @@ Tests
310 310
 -----
311 311
 
312 312
 Tests are defined in the exact same way as filters and functions, but you need
313
-to create an instance of ``Twig_SimpleTest``::
313
+to create an instance of ``\Twig\TwigTest``::
314 314
 
315
-    $twig = new Twig_Environment($loader);
316
-    $test = new Twig_SimpleTest('test_name', function () {
315
+    $twig = new \Twig\Environment($loader);
316
+    $test = new \Twig\TwigTest('test_name', function () {
317 317
         // ...
318 318
     });
319 319
     $twig->addTest($test);
... ...
@@ -322,8 +322,8 @@ Tests allow you to create custom application specific logic for evaluating
322 322
 boolean conditions. As a simple example, let's create a Twig test that checks if
323 323
 objects are 'red'::
324 324
 
325
-    $twig = new Twig_Environment($loader);
326
-    $test = new Twig_SimpleTest('red', function ($value) {
325
+    $twig = new \Twig\Environment($loader);
326
+    $test = new \Twig\TwigTest('red', function ($value) {
327 327
         if (isset($value->color) && $value->color == 'red') {
328 328
             return true;
329 329
         }
... ...
@@ -340,16 +340,16 @@ When creating tests you can use the ``node_class`` option to provide custom test
340 340
 compilation. This is useful if your test can be compiled into PHP primitives.
341 341
 This is used by many of the tests built into Twig::
342 342
 
343
-    $twig = new Twig_Environment($loader);
344
-    $test = new Twig_SimpleTest(
343
+    $twig = new \Twig\Environment($loader);
344
+    $test = new \Twig\TwigTest(
345 345
         'odd',
346 346
         null,
347
-        ['node_class' => 'Twig_Node_Expression_Test_Odd']);
347
+        ['node_class' => '\Twig\Node\Expression\Test\OddTest']);
348 348
     $twig->addTest($test);
349 349
 
350
-    class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test
350
+    class Twig_Node_Expression_Test_Odd extends \Twig\Node\Expression\TestExpression
351 351
     {
352
-        public function compile(Twig_Compiler $compiler)
352
+        public function compile(\Twig\Compiler $compiler)
353 353
         {
354 354
             $compiler
355 355
                 ->raw('(')
... ...
@@ -416,9 +416,9 @@ Registering a new tag
416 416
 ~~~~~~~~~~~~~~~~~~~~~
417 417
 
418 418
 Adding a tag is as simple as calling the ``addTokenParser`` method on the
419
-``Twig_Environment`` instance::
419
+``\Twig\Environment`` instance::
420 420
 
421
-    $twig = new Twig_Environment($loader);
421
+    $twig = new \Twig\Environment($loader);
422 422
     $twig->addTokenParser(new Project_Set_TokenParser());
423 423
 
424 424
 Defining a Token Parser
... ...
@@ -426,17 +426,17 @@ Defining a Token Parser
426 426
 
427 427
 Now, let's see the actual code of this class::
428 428
 
429
-    class Project_Set_TokenParser extends Twig_TokenParser
429
+    class Project_Set_TokenParser extends \Twig\TokenParser\AbstractTokenParser
430 430
     {
431
-        public function parse(Twig_Token $token)
431
+        public function parse(\Twig\Token $token)
432 432
         {
433 433
             $parser = $this->parser;
434 434
             $stream = $parser->getStream();
435 435
 
436
-            $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
437
-            $stream->expect(Twig_Token::OPERATOR_TYPE, '=');
436
+            $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue();
437
+            $stream->expect(\Twig\Token::OPERATOR_TYPE, '=');
438 438
             $value = $parser->getExpressionParser()->parseExpression();
439
-            $stream->expect(Twig_Token::BLOCK_END_TYPE);
439
+            $stream->expect(\Twig\Token::BLOCK_END_TYPE);
440 440
 
441 441
             return new Project_Set_Node($name, $value, $token->getLine(), $this->getTag());
442 442
         }
... ...
@@ -450,7 +450,7 @@ Now, let's see the actual code of this class::
450 450
 The ``getTag()`` method must return the tag we want to parse, here ``set``.
451 451
 
452 452
 The ``parse()`` method is invoked whenever the parser encounters a ``set``
453
-tag. It should return a ``Twig_Node`` instance that represents the node (the
453
+tag. It should return a ``\Twig\Node\Node`` instance that represents the node (the
454 454
 ``Project_Set_Node`` calls creating is explained in the next section).
455 455
 
456 456
 The parsing process is simplified thanks to a bunch of methods you can call
... ...
@@ -483,14 +483,14 @@ Defining a Node
483 483
 
484 484
 The ``Project_Set_Node`` class itself is rather simple::
485 485
 
486
-    class Project_Set_Node extends Twig_Node
486
+    class Project_Set_Node extends \Twig\Node\Node
487 487
     {
488
-        public function __construct($name, Twig_Node_Expression $value, $line, $tag = null)
488
+        public function __construct($name, \Twig\Node\Expression\AbstractExpression $value, $line, $tag = null)
489 489
         {
490 490
             parent::__construct(['value' => $value], ['name' => $name], $line, $tag);
491 491
         }
492 492
 
493
-        public function compile(Twig_Compiler $compiler)
493
+        public function compile(\Twig\Compiler $compiler)
494 494
         {
495 495
             $compiler
496 496
                 ->addDebugInfo($this)
... ...
@@ -514,15 +514,15 @@ developer generate beautiful and readable PHP code:
514 514
 * ``string()``: Writes a quoted string.
515 515
 
516 516
 * ``repr()``: Writes a PHP representation of a given value (see
517
-  ``Twig_Node_For`` for a usage example).
517
+  ``\Twig\Node\ForNode`` for a usage example).
518 518
 
519 519
 * ``addDebugInfo()``: Adds the line of the original template file related to
520 520
   the current node as a comment.
521 521
 
522
-* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a
522
+* ``indent()``: Indents the generated code (see ``\Twig\Node\BlockNode`` for a
523 523
   usage example).
524 524
 
525
-* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a
525
+* ``outdent()``: Outdents the generated code (see ``\Twig\Node\BlockNode`` for a
526 526
   usage example).
527 527
 
528 528
 .. _creating_extensions:
... ...
@@ -560,7 +560,7 @@ An extension is a class that implements the following interface::
560 560
          *
561 561
          * @deprecated since 1.23 (to be removed in 2.0), implement \Twig\Extension\InitRuntimeInterface instead
562 562
          */
563
-        function initRuntime(Twig_Environment $environment);
563
+        function initRuntime(\Twig\Environment $environment);
564 564
 
565 565
         /**
566 566
          * 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::
572 572
         /**
573 573
          * Returns the node visitor instances to add to the existing list.
574 574
          *
575
-         * @return Twig_NodeVisitorInterface[]
575
+         * @return \Twig\NodeVisitor\NodeVisitorInterface[]
576 576
          */
577 577
         function getNodeVisitors();
578 578
 
579 579
         /**
580 580
          * Returns a list of filters to add to the existing list.
581 581
          *
582
-         * @return Twig_SimpleFilter[]
582
+         * @return \Twig\TwigFilter[]
583 583
          */
584 584
         function getFilters();
585 585
 
586 586
         /**
587 587
          * Returns a list of tests to add to the existing list.
588 588
          *
589
-         * @return Twig_SimpleTest[]
589
+         * @return \Twig\TwigTest[]
590 590
          */
591 591
         function getTests();
592 592
 
593 593
         /**
594 594
          * Returns a list of functions to add to the existing list.
595 595
          *
596
-         * @return Twig_SimpleFunction[]
596
+         * @return \Twig\TwigFunction[]
597 597
          */
598 598
         function getFunctions();
599 599
 
... ...
@@ -624,10 +624,10 @@ An extension is a class that implements the following interface::
624 624
     }
625 625
 
626 626
 To keep your extension class clean and lean, inherit from the built-in
627
-``Twig_Extension`` class instead of implementing the interface as it provides
627
+``\Twig\Extension\AbstractExtension`` class instead of implementing the interface as it provides
628 628
 empty implementations for all methods:
629 629
 
630
-    class Project_Twig_Extension extends Twig_Extension
630
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
631 631
     {
632 632
     }
633 633
 
... ...
@@ -645,7 +645,7 @@ extensions must be registered explicitly to be available in your templates.
645 645
 You can register an extension by using the ``addExtension()`` method on your
646 646
 main ``Environment`` object::
647 647
 
648
-    $twig = new Twig_Environment($loader);
648
+    $twig = new \Twig\Environment($loader);
649 649
     $twig->addExtension(new Project_Twig_Extension());
650 650
 
651 651
 .. tip::
... ...
@@ -658,7 +658,7 @@ Globals
658 658
 Global variables can be registered in an extension via the ``getGlobals()``
659 659
 method::
660 660
 
661
-    class Project_Twig_Extension extends Twig_Extension implements Twig_Extension_GlobalsInterface
661
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension implements \Twig\Extension\GlobalsInterface
662 662
     {
663 663
         public function getGlobals()
664 664
         {
... ...
@@ -676,12 +676,12 @@ Functions
676 676
 Functions can be registered in an extension via the ``getFunctions()``
677 677
 method::
678 678
 
679
-    class Project_Twig_Extension extends Twig_Extension
679
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
680 680
     {
681 681
         public function getFunctions()
682 682
         {
683 683
             return [
684
-                new Twig_SimpleFunction('lipsum', 'generate_lipsum'),
684
+                new \Twig\TwigFunction('lipsum', 'generate_lipsum'),
685 685
             ];
686 686
         }
687 687
 
... ...
@@ -695,12 +695,12 @@ To add a filter to an extension, you need to override the ``getFilters()``
695 695
 method. This method must return an array of filters to add to the Twig
696 696
 environment::
697 697
 
698
-    class Project_Twig_Extension extends Twig_Extension
698
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
699 699
     {
700 700
         public function getFilters()
701 701
         {
702 702
             return [
703
-                new Twig_SimpleFilter('rot13', 'str_rot13'),
703
+                new \Twig\TwigFilter('rot13', 'str_rot13'),
704 704
             ];
705 705
         }
706 706
 
... ...
@@ -714,7 +714,7 @@ Adding a tag in an extension can be done by overriding the
714 714
 ``getTokenParsers()`` method. This method must return an array of tags to add
715 715
 to the Twig environment::
716 716
 
717
-    class Project_Twig_Extension extends Twig_Extension
717
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
718 718
     {
719 719
         public function getTokenParsers()
720 720
         {
... ...
@@ -734,17 +734,17 @@ Operators
734 734
 The ``getOperators()`` methods lets you add new operators. Here is how to add
735 735
 ``!``, ``||``, and ``&&`` operators::
736 736
 
737
-    class Project_Twig_Extension extends Twig_Extension
737
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
738 738
     {
739 739
         public function getOperators()
740 740
         {
741 741
             return [
742 742
                 [
743
-                    '!' => ['precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'],
743
+                    '!' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'],
744 744
                 ],
745 745
                 [
746
-                    '||' => ['precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT],
747
-                    '&&' => ['precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT],
746
+                    '||' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT],
747
+                    '&&' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT],
748 748
                 ],
749 749
             ];
750 750
         }
... ...
@@ -757,12 +757,12 @@ Tests
757 757
 
758 758
 The ``getTests()`` method lets you add new test functions::
759 759
 
760
-    class Project_Twig_Extension extends Twig_Extension
760
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
761 761
     {
762 762
         public function getTests()
763 763
         {
764 764
             return [
765
-                new Twig_SimpleTest('even', 'twig_test_even'),
765
+                new \Twig\TwigTest('even', 'twig_test_even'),
766 766
             ];
767 767
         }
768 768
 
... ...
@@ -786,7 +786,7 @@ any valid PHP callable:
786 786
 
787 787
 The simplest way to use methods is to define them on the extension itself::
788 788
 
789
-    class Project_Twig_Extension extends Twig_Extension
789
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
790 790
     {
791 791
         private $rot13Provider;
792 792
 
... ...
@@ -798,7 +798,7 @@ The simplest way to use methods is to define them on the extension itself::
798 798
         public function getFunctions()
799 799
         {
800 800
             return [
801
-                new Twig_SimpleFunction('rot13', [$this, 'rot13']),
801
+                new \Twig\TwigFunction('rot13', [$this, 'rot13']),
802 802
             ];
803 803
         }
804 804
 
... ...
@@ -813,11 +813,11 @@ depend on runtime dependencies even if they are not needed (think for instance
813 813
 as a dependency that connects to a database engine).
814 814
 
815 815
 As of Twig 1.26, you can easily decouple the extension definitions from their
816
-runtime implementations by registering a ``Twig_RuntimeLoaderInterface``
816
+runtime implementations by registering a ``\Twig\RuntimeLoader\RuntimeLoaderInterface``
817 817
 instance on the environment that knows how to instantiate such runtime classes
818 818
 (runtime classes must be autoload-able)::
819 819
 
820
-    class RuntimeLoader implements Twig_RuntimeLoaderInterface
820
+    class RuntimeLoader implements \Twig\RuntimeLoader\RuntimeLoaderInterface
821 821
     {
822 822
         public function load($class)
823 823
         {
... ...
@@ -837,7 +837,7 @@ instance on the environment that knows how to instantiate such runtime classes
837 837
 .. note::
838 838
 
839 839
     As of Twig 1.32, Twig comes with a PSR-11 compatible runtime loader
840
-    (``Twig_ContainerRuntimeLoader``) that works on PHP 5.3+.
840
+    (``\Twig\RuntimeLoader\ContainerRuntimeLoader``) that works on PHP 5.3+.
841 841
 
842 842
 It is now possible to move the runtime logic to a new
843 843
 ``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
857 857
         }
858 858
     }
859 859
 
860
-    class Project_Twig_Extension extends Twig_Extension
860
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
861 861
     {
862 862
         public function getFunctions()
863 863
         {
864 864
             return [
865
-                new Twig_SimpleFunction('rot13', ['Project_Twig_RuntimeExtension', 'rot13']),
865
+                new \Twig\TwigFunction('rot13', ['Project_Twig_RuntimeExtension', 'rot13']),
866 866
                 // or
867
-                new Twig_SimpleFunction('rot13', 'Project_Twig_RuntimeExtension::rot13'),
867
+                new \Twig\TwigFunction('rot13', 'Project_Twig_RuntimeExtension::rot13'),
868 868
             ];
869 869
         }
870 870
     }
... ...
@@ -876,12 +876,12 @@ To overload an already defined filter, test, operator, global variable, or
876 876
 function, re-define it in an extension and register it **as late as
877 877
 possible** (order matters)::
878 878
 
879
-    class MyCoreExtension extends Twig_Extension
879
+    class MyCoreExtension extends \Twig\Extension\AbstractExtension
880 880
     {
881 881
         public function getFilters()
882 882
         {
883 883
             return [
884
-                new Twig_SimpleFilter('date', [$this, 'dateFilter']),
884
+                new \Twig\TwigFilter('date', [$this, 'dateFilter']),
885 885
             ];
886 886
         }
887 887
 
... ...
@@ -891,16 +891,16 @@ possible** (order matters)::
891 891
         }
892 892
     }
893 893
 
894
-    $twig = new Twig_Environment($loader);
894
+    $twig = new \Twig\Environment($loader);
895 895
     $twig->addExtension(new MyCoreExtension());
896 896
 
897 897
 Here, we have overloaded the built-in ``date`` filter with a custom one.
898 898
 
899
-If you do the same on the ``Twig_Environment`` itself, beware that it takes
899
+If you do the same on the ``\Twig\Environment`` itself, beware that it takes
900 900
 precedence over any other registered extensions::
901 901
 
902
-    $twig = new Twig_Environment($loader);
903
-    $twig->addFilter(new Twig_SimpleFilter('date', function ($timestamp, $format = 'F j, Y H:i') {
902
+    $twig = new \Twig\Environment($loader);
903
+    $twig->addFilter(new \Twig\TwigFilter('date', function ($timestamp, $format = 'F j, Y H:i') {
904 904
         // do something different from the built-in date filter
905 905
     }));
906 906
     // the date filter will come from the above registration, not
... ...
@@ -935,7 +935,7 @@ following file structure in your test directory::
935 935
 
936 936
 The ``IntegrationTest.php`` file should look like this::
937 937
 
938
-    class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase
938
+    class Project_Tests_IntegrationTest extends \Twig\Test\IntegrationTestCase
939 939
     {
940 940
         public function getExtensions()
941 941
         {
... ...
@@ -958,7 +958,7 @@ Node Tests
958 958
 ~~~~~~~~~~
959 959
 
960 960
 Testing the node visitors can be complex, so extend your test cases from
961
-``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository
961
+``\Twig\Test\NodeTestCase``. Examples can be found in the Twig repository
962 962
 `tests/Twig/Node`_ directory.
963 963
 
964 964
 .. _`rot13`:                   https://secure.php.net/manual/en/function.str-rot13.php
... ...
@@ -115,7 +115,7 @@ Globals
115 115
 A global variable is like any other template variable, except that it's
116 116
 available in all templates and macros::
117 117
 
118
-    $twig = new Twig_Environment($loader);
118
+    $twig = new \Twig\Environment($loader);
119 119
     $twig->addGlobal('text', new Text());
120 120
 
121 121
 You can then use the ``text`` variable anywhere in a template:
... ...
@@ -176,9 +176,9 @@ expected output:
176 176
     {# should displays Gjvt #}
177 177
 
178 178
 Adding a filter is as simple as calling the ``addFilter()`` method on the
179
-``Twig_Environment`` instance::
179
+``\Twig\Environment`` instance::
180 180
 
181
-    $twig = new Twig_Environment($loader);
181
+    $twig = new \Twig\Environment($loader);
182 182
     $twig->addFilter('rot13', new Twig_Filter_Function('str_rot13'));
183 183
 
184 184
 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
232 232
 Twig will then pass the current environment as the first argument to the
233 233
 filter call::
234 234
 
235
-    function twig_compute_rot13(Twig_Environment $env, $string)
235
+    function twig_compute_rot13(\Twig\Environment $env, $string)
236 236
     {
237 237
         // get the current charset for instance
238 238
         $charset = $env->getCharset();
... ...
@@ -311,15 +311,15 @@ compilation, the generated PHP code is roughly equivalent to:
311 311
     <?php echo constant('DATE_W3C') ?>
312 312
 
313 313
 Adding a function is similar to adding a filter. This can be done by calling the
314
-``addFunction()`` method on the ``Twig_Environment`` instance::
314
+``addFunction()`` method on the ``\Twig\Environment`` instance::
315 315
 
316
-    $twig = new Twig_Environment($loader);
316
+    $twig = new \Twig\Environment($loader);
317 317
     $twig->addFunction('functionName', new Twig_Function_Function('someFunction'));
318 318
 
319 319
 You can also expose extension methods as functions in your templates::
320 320
 
321
-    // $this is an object that implements Twig_ExtensionInterface.
322
-    $twig = new Twig_Environment($loader);
321
+    // $this is an object that implements \Twig\Extension\ExtensionInterface.
322
+    $twig = new \Twig\Environment($loader);
323 323
     $twig->addFunction('otherFunction', new Twig_Function_Method($this, 'someMethod'));
324 324
 
325 325
 Functions also support ``needs_environment`` and ``is_safe`` parameters.
... ...
@@ -395,9 +395,9 @@ Registering a new tag
395 395
 ~~~~~~~~~~~~~~~~~~~~~
396 396
 
397 397
 Adding a tag is as simple as calling the ``addTokenParser`` method on the
398
-``Twig_Environment`` instance::
398
+``\Twig\Environment`` instance::
399 399
 
400
-    $twig = new Twig_Environment($loader);
400
+    $twig = new \Twig\Environment($loader);
401 401
     $twig->addTokenParser(new Project_Set_TokenParser());
402 402
 
403 403
 Defining a Token Parser
... ...
@@ -405,16 +405,16 @@ Defining a Token Parser
405 405
 
406 406
 Now, let's see the actual code of this class::
407 407
 
408
-    class Project_Set_TokenParser extends Twig_TokenParser
408
+    class Project_Set_TokenParser extends \Twig\TokenParser\AbstractTokenParser
409 409
     {
410
-        public function parse(Twig_Token $token)
410
+        public function parse(\Twig\Token $token)
411 411
         {
412 412
             $lineno = $token->getLine();
413
-            $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
414
-            $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, '=');
413
+            $name = $this->parser->getStream()->expect(\Twig\Token::NAME_TYPE)->getValue();
414
+            $this->parser->getStream()->expect(\Twig\Token::OPERATOR_TYPE, '=');
415 415
             $value = $this->parser->getExpressionParser()->parseExpression();
416 416
 
417
-            $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
417
+            $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
418 418
 
419 419
             return new Project_Set_Node($name, $value, $lineno, $this->getTag());
420 420
         }
... ...
@@ -428,7 +428,7 @@ Now, let's see the actual code of this class::
428 428
 The ``getTag()`` method must return the tag we want to parse, here ``set``.
429 429
 
430 430
 The ``parse()`` method is invoked whenever the parser encounters a ``set``
431
-tag. It should return a ``Twig_Node`` instance that represents the node (the
431
+tag. It should return a ``\Twig\Node\Node`` instance that represents the node (the
432 432
 ``Project_Set_Node`` calls creating is explained in the next section).
433 433
 
434 434
 The parsing process is simplified thanks to a bunch of methods you can call
... ...
@@ -461,14 +461,14 @@ Defining a Node
461 461
 
462 462
 The ``Project_Set_Node`` class itself is rather simple::
463 463
 
464
-    class Project_Set_Node extends Twig_Node
464
+    class Project_Set_Node extends \Twig\Node\Node
465 465
     {
466
-        public function __construct($name, Twig_Node_Expression $value, $lineno, $tag = null)
466
+        public function __construct($name, \Twig\Node\Expression\AbstractExpression $value, $lineno, $tag = null)
467 467
         {
468 468
             parent::__construct(['value' => $value], ['name' => $name], $lineno, $tag);
469 469
         }
470 470
 
471
-        public function compile(Twig_Compiler $compiler)
471
+        public function compile(\Twig\Compiler $compiler)
472 472
         {
473 473
             $compiler
474 474
                 ->addDebugInfo($this)
... ...
@@ -492,15 +492,15 @@ developer generate beautiful and readable PHP code:
492 492
 * ``string()``: Writes a quoted string.
493 493
 
494 494
 * ``repr()``: Writes a PHP representation of a given value (see
495
-  ``Twig_Node_For`` for a usage example).
495
+  ``\Twig\Node\ForNode`` for a usage example).
496 496
 
497 497
 * ``addDebugInfo()``: Adds the line of the original template file related to
498 498
   the current node as a comment.
499 499
 
500
-* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a
500
+* ``indent()``: Indents the generated code (see ``\Twig\Node\BlockNode`` for a
501 501
   usage example).
502 502
 
503
-* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a
503
+* ``outdent()``: Outdents the generated code (see ``\Twig\Node\BlockNode`` for a
504 504
   usage example).
505 505
 
506 506
 .. _creating_extensions:
... ...
@@ -540,7 +540,7 @@ An extension is a class that implements the following interface::
540 540
          *
541 541
          * This is where you can load some file that contains filter functions for instance.
542 542
          */
543
-        function initRuntime(Twig_Environment $environment);
543
+        function initRuntime(\Twig\Environment $environment);
544 544
 
545 545
         /**
546 546
          * 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::
552 552
         /**
553 553
          * Returns the node visitor instances to add to the existing list.
554 554
          *
555
-         * @return Twig_NodeVisitorInterface[]
555
+         * @return \Twig\NodeVisitor\NodeVisitorInterface[]
556 556
          */
557 557
         function getNodeVisitors();
558 558
 
559 559
         /**
560 560
          * Returns a list of filters to add to the existing list.
561 561
          *
562
-         * @return Twig_SimpleFilter[]
562
+         * @return \Twig\TwigFilter[]
563 563
          */
564 564
         function getFilters();
565 565
 
566 566
         /**
567 567
          * Returns a list of tests to add to the existing list.
568 568
          *
569
-         * @return Twig_SimpleTest[]
569
+         * @return \Twig\TwigTest[]
570 570
          */
571 571
         function getTests();
572 572
 
573 573
         /**
574 574
          * Returns a list of functions to add to the existing list.
575 575
          *
576
-         * @return Twig_SimpleFunction[]
576
+         * @return \Twig\TwigFunction[]
577 577
          */
578 578
         function getFunctions();
579 579
 
... ...
@@ -600,16 +600,16 @@ An extension is a class that implements the following interface::
600 600
     }
601 601
 
602 602
 To keep your extension class clean and lean, it can inherit from the built-in
603
-``Twig_Extension`` class instead of implementing the whole interface. That
603
+``\Twig\Extension\AbstractExtension`` class instead of implementing the whole interface. That
604 604
 way, you just need to implement the ``getName()`` method as the
605
-``Twig_Extension`` provides empty implementations for all other methods.
605
+``\Twig\Extension\AbstractExtension`` provides empty implementations for all other methods.
606 606
 
607 607
 The ``getName()`` method must return a unique identifier for your extension.
608 608
 
609 609
 Now, with this information in mind, let's create the most basic extension
610 610
 possible::
611 611
 
612
-    class Project_Twig_Extension extends Twig_Extension
612
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
613 613
     {
614 614
         public function getName()
615 615
         {
... ...
@@ -628,7 +628,7 @@ extensions must be registered explicitly to be available in your templates.
628 628
 You can register an extension by using the ``addExtension()`` method on your
629 629
 main ``Environment`` object::
630 630
 
631
-    $twig = new Twig_Environment($loader);
631
+    $twig = new \Twig\Environment($loader);
632 632
     $twig->addExtension(new Project_Twig_Extension());
633 633
 
634 634
 Of course, you need to first load the extension file by either using
... ...
@@ -644,7 +644,7 @@ Globals
644 644
 Global variables can be registered in an extension via the ``getGlobals()``
645 645
 method::
646 646
 
647
-    class Project_Twig_Extension extends Twig_Extension
647
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
648 648
     {
649 649
         public function getGlobals()
650 650
         {
... ...
@@ -662,7 +662,7 @@ Functions
662 662
 Functions can be registered in an extension via the ``getFunctions()``
663 663
 method::
664 664
 
665
-    class Project_Twig_Extension extends Twig_Extension
665
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
666 666
     {
667 667
         public function getFunctions()
668 668
         {
... ...
@@ -681,7 +681,7 @@ To add a filter to an extension, you need to override the ``getFilters()``
681 681
 method. This method must return an array of filters to add to the Twig
682 682
 environment::
683 683
 
684
-    class Project_Twig_Extension extends Twig_Extension
684
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
685 685
     {
686 686
         public function getFilters()
687 687
         {
... ...
@@ -705,7 +705,7 @@ $twig->addFilter('rot13', new Twig_Filter_Function('Project_Twig_Extension::rot1
705 705
 You can also use ``Twig_Filter_Method`` instead of ``Twig_Filter_Function``
706 706
 when defining a filter to use a method::
707 707
 
708
-    class Project_Twig_Extension extends Twig_Extension
708
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
709 709
     {
710 710
         public function getFilters()
711 711
         {
... ...
@@ -737,7 +737,7 @@ If some default core filters do not suit your needs, you can easily override
737 737
 them by creating your own extension. Just use the same names as the one you
738 738
 want to override::
739 739
 
740
-    class MyCoreExtension extends Twig_Extension
740
+    class MyCoreExtension extends \Twig\Extension\AbstractExtension
741 741
     {
742 742
         public function getFilters()
743 743
         {
... ...
@@ -762,7 +762,7 @@ Here, we override the ``date`` filter with a custom one. Using this extension
762 762
 is as simple as registering the ``MyCoreExtension`` extension by calling the
763 763
 ``addExtension()`` method on the environment instance::
764 764
 
765
-    $twig = new Twig_Environment($loader);
765
+    $twig = new \Twig\Environment($loader);
766 766
     $twig->addExtension(new MyCoreExtension());
767 767
 
768 768
 Tags
... ...
@@ -772,7 +772,7 @@ Adding a tag in an extension can be done by overriding the
772 772
 ``getTokenParsers()`` method. This method must return an array of tags to add
773 773
 to the Twig environment::
774 774
 
775
-    class Project_Twig_Extension extends Twig_Extension
775
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
776 776
     {
777 777
         public function getTokenParsers()
778 778
         {
... ...
@@ -792,17 +792,17 @@ Operators
792 792
 The ``getOperators()`` methods allows to add new operators. Here is how to add
793 793
 ``!``, ``||``, and ``&&`` operators::
794 794
 
795
-    class Project_Twig_Extension extends Twig_Extension
795
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
796 796
     {
797 797
         public function getOperators()
798 798
         {
799 799
             return [
800 800
                 [
801
-                    '!' => ['precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'],
801
+                    '!' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'],
802 802
                 ),
803 803
                 [
804
-                    '||' => ['precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT],
805
-                    '&&' => ['precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT],
804
+                    '||' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT],
805
+                    '&&' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT],
806 806
                 ],
807 807
             ];
808 808
         }
... ...
@@ -815,7 +815,7 @@ Tests
815 815
 
816 816
 The ``getTests()`` methods allows to add new test functions::
817 817
 
818
-    class Project_Twig_Extension extends Twig_Extension
818
+    class Project_Twig_Extension extends \Twig\Extension\AbstractExtension
819 819
     {
820 820
         public function getTests()
821 821
         {
... ...
@@ -853,7 +853,7 @@ following file structure in your test directory::
853 853
 
854 854
 The ``IntegrationTest.php`` file should look like this::
855 855
 
856
-    class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase
856
+    class Project_Tests_IntegrationTest extends \Twig\Test\IntegrationTestCase
857 857
     {
858 858
         public function getExtensions()
859 859
         {
... ...
@@ -876,7 +876,7 @@ Node Tests
876 876
 ~~~~~~~~~~
877 877
 
878 878
 Testing the node visitors can be complex, so extend your test cases from
879
-``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository
879
+``\Twig\Test\NodeTestCase``. Examples can be found in the Twig repository
880 880
 `tests/Twig/Node`_ directory.
881 881
 
882 882
 .. _`spl_autoload_register()`: https://secure.php.net/spl_autoload_register
... ...
@@ -9,11 +9,11 @@ Basics
9 9
 ------
10 10
 
11 11
 Twig uses a central object called the **environment** (of class
12
-``Twig_Environment``). Instances of this class are used to store the
12
+``\Twig\Environment``). Instances of this class are used to store the
13 13
 configuration and extensions, and are used to load templates from the file
14 14
 system or other locations.
15 15
 
16
-Most applications will create one ``Twig_Environment`` object on application
16
+Most applications will create one ``\Twig\Environment`` object on application
17 17
 initialization and use that to load templates. In some cases it's however
18 18
 useful to have multiple environments side by side, if different configurations
19 19
 are in use.
... ...
@@ -24,8 +24,8 @@ looks roughly like this::
24 24
     require_once '/path/to/lib/Twig/Autoloader.php';
25 25
     Twig_Autoloader::register();
26 26
 
27
-    $loader = new Twig_Loader_Filesystem('/path/to/templates');
28
-    $twig = new Twig_Environment($loader, [
27
+    $loader = new \Twig\Loader\FilesystemLoader('/path/to/templates');
28
+    $twig = new \Twig\Environment($loader, [
29 29
         'cache' => '/path/to/compilation_cache',
30 30
     ]);
31 31
 
... ...
@@ -47,14 +47,14 @@ Rendering Templates
47 47
 -------------------
48 48
 
49 49
 To load a template from a Twig environment, call the ``load()`` method which
50
-returns a ``Twig_TemplateWrapper`` instance::
50
+returns a ``\Twig\TemplateWrapper`` instance::
51 51
 
52 52
     $template = $twig->load('index.html');
53 53
 
54 54
 .. note::
55 55
 
56 56
     Before Twig 1.28, you should use ``loadTemplate()`` instead which returns a
57
-    ``Twig_Template`` instance.
57
+    ``\Twig\Template`` instance.
58 58
 
59 59
 To render the template with some variables, call the ``render()`` method::
60 60
 
... ...
@@ -81,10 +81,10 @@ If a template defines blocks, they can be rendered individually via the
81 81
 Environment Options
82 82
 -------------------
83 83
 
84
-When creating a new ``Twig_Environment`` instance, you can pass an array of
84
+When creating a new ``\Twig\Environment`` instance, you can pass an array of
85 85
 options as the constructor second argument::
86 86
 
87
-    $twig = new Twig_Environment($loader, ['debug' => true]);
87
+    $twig = new \Twig\Environment($loader, ['debug' => true]);
88 88
 
89 89
 The following options are available:
90 90
 
... ...
@@ -98,7 +98,7 @@ The following options are available:
98 98
 
99 99
   The charset used by the templates.
100 100
 
101
-* ``base_template_class`` *string* (defaults to ``Twig_Template``)
101
+* ``base_template_class`` *string* (defaults to ``\Twig\Template``)
102 102
 
103 103
   The base template class to use for generated
104 104
   templates.
... ...
@@ -158,7 +158,7 @@ Compilation Cache
158 158
 All template loaders can cache the compiled templates on the filesystem for
159 159
 future reuse. It speeds up Twig a lot as templates are only compiled once; and
160 160
 the performance boost is even larger if you use a PHP accelerator such as APC.
161
-See the ``cache`` and ``auto_reload`` options of ``Twig_Environment`` above
161
+See the ``cache`` and ``auto_reload`` options of ``\Twig\Environment`` above
162 162
 for more information.
163 163
 
164 164
 Built-in Loaders
... ...
@@ -166,7 +166,7 @@ Built-in Loaders
166 166
 
167 167
 Here is a list of the built-in loaders Twig provides:
168 168
 
169
-``Twig_Loader_Filesystem``
169
+``\Twig\Loader\FilesystemLoader``
170 170
 ..........................
171 171
 
172 172
 .. versionadded:: 1.10
... ...
@@ -175,15 +175,15 @@ Here is a list of the built-in loaders Twig provides:
175 175
 .. versionadded:: 1.27
176 176
     Relative paths support was added in Twig 1.27.
177 177
 
178
-``Twig_Loader_Filesystem`` loads templates from the file system. This loader
178
+``\Twig\Loader\FilesystemLoader`` loads templates from the file system. This loader
179 179
 can find templates in folders on the file system and is the preferred way to
180 180
 load them::
181 181
 
182
-    $loader = new Twig_Loader_Filesystem($templateDir);
182
+    $loader = new \Twig\Loader\FilesystemLoader($templateDir);
183 183
 
184 184
 It can also look for templates in an array of directories::
185 185
 
186
-    $loader = new Twig_Loader_Filesystem([$templateDir1, $templateDir2]);
186
+    $loader = new \Twig\Loader\FilesystemLoader([$templateDir1, $templateDir2]);
187 187
 
188 188
 With such a configuration, Twig will first look for templates in
189 189
 ``$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
209 209
 
210 210
     $twig->render('@admin/index.html', []);
211 211
 
212
-``Twig_Loader_Filesystem`` support absolute and relative paths. Using relative
212
+``\Twig\Loader\FilesystemLoader`` support absolute and relative paths. Using relative
213 213
 paths is preferred as it makes the cache keys independent of the project root
214 214
 directory (for instance, it allows warming the cache from a build server where
215 215
 the directory might be different from the one used on production servers)::
216 216
 
217
-    $loader = new Twig_Loader_Filesystem('templates', getcwd().'/..');
217
+    $loader = new \Twig\Loader\FilesystemLoader('templates', getcwd().'/..');
218 218
 
219 219
 .. note::
220 220
 
221 221
     When not passing the root path as a second argument, Twig uses ``getcwd()``
222 222
     for relative paths.
223 223
 
224
-``Twig_Loader_Array``
224
+``\Twig\Loader\ArrayLoader``
225 225
 .....................
226 226
 
227
-``Twig_Loader_Array`` loads a template from a PHP array. It's passed an array
227
+``\Twig\Loader\ArrayLoader`` loads a template from a PHP array. It's passed an array
228 228
 of strings bound to template names::
229 229
 
230
-    $loader = new Twig_Loader_Array([
230
+    $loader = new \Twig\Loader\ArrayLoader([
231 231
         'index.html' => 'Hello {{ name }}!',
232 232
     ]);
233
-    $twig = new Twig_Environment($loader);
233
+    $twig = new \Twig\Environment($loader);
234 234
 
235 235
     echo $twig->render('index.html', ['name' => 'Fabien']);
236 236
 
... ...
@@ -245,30 +245,30 @@ projects where storing all templates in a single PHP file might make sense.
245 245
     don't want to see your cache grows out of control, you need to take care
246 246
     of clearing the old cache file by yourself.
247 247
 
248
-``Twig_Loader_Chain``
248
+``\Twig\Loader\ChainLoader``
249 249
 .....................
250 250
 
251
-``Twig_Loader_Chain`` delegates the loading of templates to other loaders::
251
+``\Twig\Loader\ChainLoader`` delegates the loading of templates to other loaders::
252 252
 
253
-    $loader1 = new Twig_Loader_Array([
253
+    $loader1 = new \Twig\Loader\ArrayLoader([
254 254
         'base.html' => '{% block content %}{% endblock %}',
255 255
     ]);
256
-    $loader2 = new Twig_Loader_Array([
256
+    $loader2 = new \Twig\Loader\ArrayLoader([
257 257
         'index.html' => '{% extends "base.html" %}{% block content %}Hello {{ name }}{% endblock %}',
258 258
         'base.html'  => 'Will never be loaded',
259 259
     ]);
260 260
 
261
-    $loader = new Twig_Loader_Chain([$loader1, $loader2]);
261
+    $loader = new \Twig\Loader\ChainLoader([$loader1, $loader2]);
262 262
 
263
-    $twig = new Twig_Environment($loader);
263
+    $twig = new \Twig\Environment($loader);
264 264
 
265 265
 When looking for a template, Twig will try each loader in turn and it will
266 266
 return as soon as the template is found. When rendering the ``index.html``
267 267
 template from the above example, Twig will load it with ``$loader2`` but the
268 268
 ``base.html`` template will be loaded from ``$loader1``.
269 269
 
270
-``Twig_Loader_Chain`` accepts any loader that implements
271
-``Twig_LoaderInterface``.
270
+``\Twig\Loader\ChainLoader`` accepts any loader that implements
271
+``\Twig\Loader\LoaderInterface``.
272 272
 
273 273
 .. note::
274 274
 
... ...
@@ -277,7 +277,7 @@ template from the above example, Twig will load it with ``$loader2`` but the
277 277
 Create your own Loader
278 278
 ~~~~~~~~~~~~~~~~~~~~~~
279 279
 
280
-All loaders implement the ``Twig_LoaderInterface``::
280
+All loaders implement the ``\Twig\Loader\LoaderInterface``::
281 281
 
282 282
     interface Twig_LoaderInterface
283 283
     {
... ...
@@ -316,11 +316,11 @@ is still fresh, given the last modification time, or ``false`` otherwise.
316 316
 .. note::
317 317
 
318 318
     As of Twig 1.27, you should also implement
319
-    ``Twig_SourceContextLoaderInterface`` to avoid deprecation notices.
319
+    ``\Twig\Loader\SourceContextLoaderInterface`` to avoid deprecation notices.
320 320
 
321 321
 .. tip::
322 322
 
323
-    As of Twig 1.11.0, you can also implement ``Twig_ExistsLoaderInterface``
323
+    As of Twig 1.11.0, you can also implement ``\Twig\Loader\ExistsLoaderInterface``
324 324
     to make your loader faster when used with the chain loader.
325 325
 
326 326
 Using Extensions
... ...
@@ -329,7 +329,7 @@ Using Extensions
329 329
 Twig extensions are packages that add new features to Twig. Using an
330 330
 extension is as simple as using the ``addExtension()`` method::
331 331
 
332
-    $twig->addExtension(new Twig_Extension_Sandbox());
332
+    $twig->addExtension(new \Twig\Extension\SandboxExtension());
333 333
 
334 334
 Twig comes bundled with the following extensions:
335 335
 
... ...
@@ -378,7 +378,7 @@ tag, ``autoescape``, and a filter, ``raw``.
378 378
 When creating the escaper extension, you can switch on or off the global
379 379
 output escaping strategy::
380 380
 
381
-    $escaper = new Twig_Extension_Escaper('html');
381
+    $escaper = new \Twig\Extension\EscaperExtension('html');
382 382
     $twig->addExtension($escaper);
383 383
 
384 384
 If set to ``html``, all variables in templates are escaped (using the ``html``
... ...
@@ -473,7 +473,7 @@ Sandbox Extension
473 473
 The ``sandbox`` extension can be used to evaluate untrusted code. Access to
474 474
 unsafe attributes and methods is prohibited. The sandbox security is managed
475 475
 by a policy instance. By default, Twig comes with one policy class:
476
-``Twig_Sandbox_SecurityPolicy``. This class allows you to white-list some
476
+``\Twig\Sandbox\SecurityPolicy``. This class allows you to white-list some
477 477
 tags, filters, properties, and methods::
478 478
 
479 479
     $tags = ['if'];
... ...
@@ -485,17 +485,17 @@ tags, filters, properties, and methods::
485 485
         'Article' => ['title', 'body'],
486 486
     ];
487 487
     $functions = ['range'];
488
-    $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions);
488
+    $policy = new \Twig\Sandbox\SecurityPolicy($tags, $filters, $methods, $properties, $functions);
489 489
 
490 490
 With the previous configuration, the security policy will only allow usage of
491 491
 the ``if`` tag, and the ``upper`` filter. Moreover, the templates will only be
492 492
 able to call the ``getTitle()`` and ``getBody()`` methods on ``Article``
493 493
 objects, and the ``title`` and ``body`` public properties. Everything else
494
-won't be allowed and will generate a ``Twig_Sandbox_SecurityError`` exception.
494
+won't be allowed and will generate a ``\Twig\Sandbox\SecurityError`` exception.
495 495
 
496 496
 The policy object is the first argument of the sandbox constructor::
497 497
 
498
-    $sandbox = new Twig_Extension_Sandbox($policy);
498
+    $sandbox = new \Twig\Extension\SandboxExtension($policy);
499 499
     $twig->addExtension($sandbox);
500 500
 
501 501
 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:
510 510
 You can sandbox all templates by passing ``true`` as the second argument of
511 511
 the extension constructor::
512 512
 
513
-    $sandbox = new Twig_Extension_Sandbox($policy, true);
513
+    $sandbox = new \Twig\Extension\SandboxExtension($policy, true);
514 514
 
515 515
 Profiler Extension
516 516
 ~~~~~~~~~~~~~~~~~~
... ...
@@ -521,10 +521,10 @@ Profiler Extension
521 521
 The ``profiler`` extension enables a profiler for Twig templates; it should
522 522
 only be used on your development machines as it adds some overhead::
523 523
 
524
-    $profile = new Twig_Profiler_Profile();
525
-    $twig->addExtension(new Twig_Extension_Profiler($profile));
524
+    $profile = new \Twig\Profiler\Profile();
525
+    $twig->addExtension(new \Twig\Extension\ProfilerExtension($profile));
526 526
 
527
-    $dumper = new Twig_Profiler_Dumper_Text();
527
+    $dumper = new \Twig\Profiler\Dumper\TextDumper();
528 528
     echo $dumper->dump($profile);
529 529
 
530 530
 A profile contains information about time and memory consumption for template,
... ...
@@ -533,7 +533,7 @@ block, and macro executions.
533 533
 You can also dump the data in a `Blackfire.io <https://blackfire.io/>`_
534 534
 compatible format::
535 535
 
536
-    $dumper = new Twig_Profiler_Dumper_Blackfire();
536
+    $dumper = new \Twig\Profiler\Dumper\BlackfireDumper();
537 537
     file_put_contents('/path/to/profile.prof', $dumper->dump($profile));
538 538
 
539 539
 Upload the profile to visualize it (create a `free account
... ...
@@ -548,27 +548,27 @@ Optimizer Extension
548 548
 
549 549
 The ``optimizer`` extension optimizes the node tree before compilation::
550 550
 
551
-    $twig->addExtension(new Twig_Extension_Optimizer());
551
+    $twig->addExtension(new \Twig\Extension\OptimizerExtension());
552 552
 
553 553
 By default, all optimizations are turned on. You can select the ones you want
554 554
 to enable by passing them to the constructor::
555 555
 
556
-    $optimizer = new Twig_Extension_Optimizer(Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR);
556
+    $optimizer = new \Twig\Extension\OptimizerExtension(\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_FOR);
557 557
 
558 558
     $twig->addExtension($optimizer);
559 559
 
560 560
 Twig supports the following optimizations:
561 561
 
562
-* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_ALL``, enables all optimizations
562
+* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_ALL``, enables all optimizations
563 563
   (this is the default value).
564
-* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_NONE``, disables all optimizations.
564
+* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_NONE``, disables all optimizations.
565 565
   This reduces the compilation time, but it can increase the execution time
566 566
   and the consumed memory.
567
-* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR``, optimizes the ``for`` tag by
567
+* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_FOR``, optimizes the ``for`` tag by
568 568
   removing the ``loop`` variable creation whenever possible.
569
-* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_RAW_FILTER``, removes the ``raw``
569
+* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_RAW_FILTER``, removes the ``raw``
570 570
   filter whenever possible.
571
-* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_VAR_ACCESS``, simplifies the creation
571
+* ``\Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_VAR_ACCESS``, simplifies the creation
572 572
   and access of variables in the compiled templates whenever possible.
573 573
 
574 574
 Exceptions
... ...
@@ -576,15 +576,15 @@ Exceptions
576 576
 
577 577
 Twig can throw exceptions:
578 578
 
579
-* ``Twig_Error``: The base exception for all errors.
579
+* ``\Twig\Error\Error``: The base exception for all errors.
580 580
 
581
-* ``Twig_Error_Syntax``: Thrown to tell the user that there is a problem with
581
+* ``\Twig\Error\SyntaxError``: Thrown to tell the user that there is a problem with
582 582
   the template syntax.
583 583
 
584
-* ``Twig_Error_Runtime``: Thrown when an error occurs at runtime (when a filter
584
+* ``\Twig\Error\RuntimeError``: Thrown when an error occurs at runtime (when a filter
585 585
   does not exist for instance).
586 586
 
587
-* ``Twig_Error_Loader``: Thrown when an error occurs during template loading.
587
+* ``\Twig\Error\LoaderError``: Thrown when an error occurs during template loading.
588 588
 
589
-* ``Twig_Sandbox_SecurityError``: Thrown when an unallowed tag, filter, or
589
+* ``\Twig\Sandbox\SecurityError``: Thrown when an unallowed tag, filter, or
590 590
   method is called in a sandboxed template.
... ...
@@ -27,29 +27,29 @@ Token Parsers
27 27
   * ``Twig_TokenParserBrokerInterface``
28 28
   * ``Twig_TokenParserBroker``
29 29
 
30
-* As of Twig 1.27, ``Twig_Parser::getFilename()`` is deprecated. From a token
30
+* As of Twig 1.27, ``\Twig\Parser::getFilename()`` is deprecated. From a token
31 31
   parser, use ``$this->parser->getStream()->getSourceContext()->getPath()`` instead.
32 32
 
33
-* As of Twig 1.27, ``Twig_Parser::getEnvironment()`` is deprecated.
33
+* As of Twig 1.27, ``\Twig\Parser::getEnvironment()`` is deprecated.
34 34
 
35 35
 Extensions
36 36
 ----------
37 37
 
38 38
 * As of Twig 1.x, the ability to remove an extension is deprecated and the
39
-  ``Twig_Environment::removeExtension()`` method will be removed in 2.0.
39
+  ``\Twig\Environment::removeExtension()`` method will be removed in 2.0.
40 40
 
41
-* As of Twig 1.23, the ``Twig_ExtensionInterface::initRuntime()`` method is
41
+* As of Twig 1.23, the ``\Twig\Extension\ExtensionInterface::initRuntime()`` method is
42 42
   deprecated. You have two options to avoid the deprecation notice: if you
43 43
   implement this method to store the environment for your custom filters,
44 44
   functions, or tests, use the ``needs_environment`` option instead; if you
45 45
   have more complex needs, explicitly implement
46
-  ``Twig_Extension_InitRuntimeInterface`` (not recommended).
46
+  ``\Twig\Extension\InitRuntimeInterface`` (not recommended).
47 47
 
48
-* As of Twig 1.23, the ``Twig_ExtensionInterface::getGlobals()`` method is
49
-  deprecated. Implement ``Twig_Extension_GlobalsInterface`` to avoid
48
+* As of Twig 1.23, the ``\Twig\Extension\ExtensionInterface::getGlobals()`` method is
49
+  deprecated. Implement ``\Twig\Extension\GlobalsInterface`` to avoid
50 50
   deprecation notices.
51 51
 
52
-* As of Twig 1.26, the ``Twig_ExtensionInterface::getName()`` method is
52
+* As of Twig 1.26, the ``\Twig\Extension\ExtensionInterface::getName()`` method is
53 53
   deprecated and it is not used internally anymore.
54 54
 
55 55
 PEAR
... ...
@@ -61,7 +61,7 @@ provided anymore. Use Composer instead.
61 61
 Filters
62 62
 -------
63 63
 
64
-* As of Twig 1.x, use ``Twig_SimpleFilter`` to add a filter. The following
64
+* As of Twig 1.x, use ``\Twig\TwigFilter`` to add a filter. The following
65 65
   classes and interfaces will be removed in 2.0:
66 66
 
67 67
   * ``Twig_FilterInterface``
... ...
@@ -71,14 +71,14 @@ Filters
71 71
   * ``Twig_Filter_Method``
72 72
   * ``Twig_Filter_Node``
73 73
 
74
-* As of Twig 2.x, the ``Twig_SimpleFilter`` class is deprecated and will be
74
+* As of Twig 2.x, the ``\Twig\TwigFilter`` class is deprecated and will be
75 75
   removed in Twig 3.x (use ``Twig_Filter`` instead). In Twig 2.x,
76
-  ``Twig_SimpleFilter`` is just an alias for ``Twig_Filter``.
76
+  ``\Twig\TwigFilter`` is just an alias for ``Twig_Filter``.
77 77
 
78 78
 Functions
79 79
 ---------
80 80
 
81
-* As of Twig 1.x, use ``Twig_SimpleFunction`` to add a function. The following
81
+* As of Twig 1.x, use ``\Twig\TwigFunction`` to add a function. The following
82 82
   classes and interfaces will be removed in 2.0:
83 83
 
84 84
   * ``Twig_FunctionInterface``
... ...
@@ -88,14 +88,14 @@ Functions
88 88
   * ``Twig_Function_Method``
89 89
   * ``Twig_Function_Node``
90 90
 
91
-* As of Twig 2.x, the ``Twig_SimpleFunction`` class is deprecated and will be
91
+* As of Twig 2.x, the ``\Twig\TwigFunction`` class is deprecated and will be
92 92
   removed in Twig 3.x (use ``Twig_Function`` instead). In Twig 2.x,
93
-  ``Twig_SimpleFunction`` is just an alias for ``Twig_Function``.
93
+  ``\Twig\TwigFunction`` is just an alias for ``Twig_Function``.
94 94
 
95 95
 Tests
96 96
 -----
97 97
 
98
-* As of Twig 1.x, use ``Twig_SimpleTest`` to add a test. The following classes
98
+* As of Twig 1.x, use ``\Twig\TwigTest`` to add a test. The following classes
99 99
   and interfaces will be removed in 2.0:
100 100
 
101 101
   * ``Twig_TestInterface``
... ...
@@ -105,9 +105,9 @@ Tests
105 105
   * ``Twig_Test_Method``
106 106
   * ``Twig_Test_Node``
107 107
 
108
-* As of Twig 2.x, the ``Twig_SimpleTest`` class is deprecated and will be
108
+* As of Twig 2.x, the ``\Twig\TwigTest`` class is deprecated and will be
109 109
   removed in Twig 3.x (use ``Twig_Test`` instead). In Twig 2.x,
110
-  ``Twig_SimpleTest`` is just an alias for ``Twig_Test``.
110
+  ``\Twig\TwigTest`` is just an alias for ``Twig_Test``.
111 111
 
112 112
 * The ``sameas`` and ``divisibleby`` tests are deprecated in favor of ``same
113 113
   as`` and ``divisible by`` respectively.
... ...
@@ -124,16 +124,16 @@ Nodes
124 124
 * As of Twig 1.x, ``Node::toXml()`` is deprecated and will be removed in Twig
125 125
   2.0.
126 126
 
127
-* As of Twig 1.26, ``Node::$nodes`` should only contains ``Twig_Node``
127
+* As of Twig 1.26, ``Node::$nodes`` should only contains ``\Twig\Node\Node``
128 128
   instances, storing a ``null`` value is deprecated and won't be possible in
129 129
   Twig 2.x.
130 130
 
131
-* As of Twig 1.27, the ``filename`` attribute on ``Twig_Node_Module`` is
131
+* As of Twig 1.27, the ``filename`` attribute on ``\Twig\Node\ModuleNode`` is
132 132
   deprecated. Use ``getName()`` instead.
133 133
 
134
-* As of Twig 1.27, the ``Twig_Node::getFilename()/Twig_Node::getLine()``
134
+* As of Twig 1.27, the ``\Twig\Node\Node::getFilename()/\Twig\Node\Node::getLine()``
135 135
   methods are deprecated, use
136
-  ``Twig_Node::getTemplateName()/Twig_Node::getTemplateLine()`` instead.
136
+  ``\Twig\Node\Node::getTemplateName()/\Twig\Node\Node::getTemplateLine()`` instead.
137 137
 
138 138
 Interfaces
139 139
 ----------
... ...
@@ -141,40 +141,40 @@ Interfaces
141 141
 * As of Twig 2.x, the following interfaces are deprecated and empty (they will
142 142
   be removed in Twig 3.0):
143 143
 
144
-* ``Twig_CompilerInterface``     (use ``Twig_Compiler`` instead)
145
-* ``Twig_LexerInterface``        (use ``Twig_Lexer`` instead)
146
-* ``Twig_NodeInterface``         (use ``Twig_Node`` instead)
147
-* ``Twig_ParserInterface``       (use ``Twig_Parser`` instead)
148
-* ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``)
149
-* ``Twig_SourceContextLoaderInterface`` (merged with ``Twig_LoaderInterface``)
150
-* ``Twig_TemplateInterface``     (use ``Twig_Template`` instead, and use
151
-  those constants Twig_Template::ANY_CALL, Twig_Template::ARRAY_CALL,
152
-  Twig_Template::METHOD_CALL)
144
+* ``Twig_CompilerInterface``     (use ``\Twig\Compiler`` instead)
145
+* ``Twig_LexerInterface``        (use ``\Twig\Lexer`` instead)
146
+* ``Twig_NodeInterface``         (use ``\Twig\Node\Node`` instead)
147
+* ``Twig_ParserInterface``       (use ``\Twig\Parser`` instead)
148
+* ``\Twig\Loader\ExistsLoaderInterface`` (merged with ``\Twig\Loader\LoaderInterface``)
149
+* ``\Twig\Loader\SourceContextLoaderInterface`` (merged with ``\Twig\Loader\LoaderInterface``)
150
+* ``Twig_TemplateInterface``     (use ``\Twig\Template`` instead, and use
151
+  those constants \Twig\Template::ANY_CALL, \Twig\Template::ARRAY_CALL,
152
+  \Twig\Template::METHOD_CALL)
153 153
 
154 154
 Compiler
155 155
 --------
156 156
 
157
-* As of Twig 1.26, the ``Twig_Compiler::getFilename()`` has been deprecated.
157
+* As of Twig 1.26, the ``\Twig\Compiler::getFilename()`` has been deprecated.
158 158
   You should not use it anyway as its values is not reliable.
159 159
 
160
-* As of Twig 1.27, the ``Twig_Compiler::addIndentation()`` has been deprecated.
161
-  Use ``Twig_Compiler::write('')`` instead.
160
+* As of Twig 1.27, the ``\Twig\Compiler::addIndentation()`` has been deprecated.
161
+  Use ``\Twig\Compiler::write('')`` instead.
162 162
 
163 163
 Loaders
164 164
 -------
165 165
 
166 166
 * As of Twig 1.x, ``Twig_Loader_String`` is deprecated and will be removed in
167
-  2.0. You can render a string via ``Twig_Environment::createTemplate()``.
167
+  2.0. You can render a string via ``\Twig\Environment::createTemplate()``.
168 168
 
169
-* As of Twig 1.27, ``Twig_LoaderInterface::getSource()`` is deprecated.
170
-  Implement ``Twig_SourceContextLoaderInterface`` instead and use
169
+* As of Twig 1.27, ``\Twig\Loader\LoaderInterface::getSource()`` is deprecated.
170
+  Implement ``\Twig\Loader\SourceContextLoaderInterface`` instead and use
171 171
   ``getSourceContext()``.
172 172
 
173 173
 Node Visitors
174 174
 -------------
175 175
 
176 176
 * Because of the removal of ``Twig_NodeInterface`` in 2.0, you need to extend
177
-  ``Twig_BaseNodeVisitor`` instead of implementing ``Twig_NodeVisitorInterface``
177
+  ``\Twig\NodeVisitor\AbstractNodeVisitor`` instead of implementing ``\Twig\NodeVisitor\NodeVisitorInterface``
178 178
   directly to make your node visitors compatible with both Twig 1.x and 2.x.
179 179
 
180 180
 Globals
... ...
@@ -185,40 +185,40 @@ Globals
185 185
   changing the value of an already registered global is possible).