8000 Fix Twig namespaces and update doc for twig runtime extension · symfony/symfony-docs@57d3ce1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 57d3ce1

Browse files
committed
Fix Twig namespaces and update doc for twig runtime extension
1 parent 4ea4efe commit 57d3ce1

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

components/form.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
178178
use Symfony\Bridge\Twig\Extension\FormExtension;
179179
use Symfony\Component\Form\FormRenderer;
180180
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
181+
use Twig\Environment;
182+
use Twig\Loader\FilesystemLoader;
183+
use Twig\RuntimeLoader\FactoryRuntimeLoader;
181184

182185
// the Twig file that holds all the default markup for rendering forms
183186
// this file comes with TwigBridge
@@ -191,12 +194,12 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
191194
// the path to your other templates
192195
$viewsDirectory = realpath(__DIR__.'/../views');
193196

194-
$twig = new Twig_Environment(new Twig_Loader_Filesystem(array(
197+
$twig = new Environment(new FilesystemLoader(array(
195198
$viewsDirectory,
196199
$vendorTwigBridgeDirectory.'/Resources/views/Form',
197200
)));
198201
$formEngine = new TwigRendererEngine(array($defaultFormTheme), $twig);
199-
$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
202+
$twig->addRuntimeLoader(new FactoryRuntimeLoader(array(
200203
FormRenderer::class => function () use ($formEngine, $csrfManager) {
201204
return new FormRenderer($formEngine, $csrfManager);
202205
},
@@ -213,7 +216,7 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
213216
->getFormFactory();
214217

215218
.. versionadded:: 1.30
216-
The ``Twig_FactoryRuntimeLoader`` was introduced in Twig 1.30.
219+
The ``Twig\\RuntimeLoader\\FactoryRuntimeLoader`` was introduced in Twig 1.30.
217220

218221
The exact details of your `Twig Configuration`_ will vary, but the goal is
219222
always to add the :class:`Symfony\\Bridge\\Twig\\Extension\\FormExtension`
@@ -253,7 +256,7 @@ installed:
253256
$ composer require symfony/translation symfony/config
254257
255258
Next, add the :class:`Symfony\\Bridge\\Twig\\Extension\\TranslationExtension`
256-
to your ``Twig_Environment`` instance::
259+
to your ``Twig\\Environment`` instance::
257260

258261
use Symfony\Component\Form\Forms;
259262
use Symfony\Component\Translation\Translator;

controller/service.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ service and use it directly::
9797
namespace App\Controller;
9898

9999
use Symfony\Component\HttpFoundation\Response;
100+
use Twig\Environment;
100101

101102
class HelloController
102103
{
103104
private $twig;
104105

105-
public function __construct(\Twig_Environment $twig)
106+
public function __construct(Environment $twig)
106107
{
107108
$this->twig = $twig;
108109
}

reference/configuration/twig.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ called to determine the default escaping applied to the template.
8484
base_template_class
8585
~~~~~~~~~~~~~~~~~~~
8686

87-
**type**: ``string`` **default**: ``'Twig_Template'``
87+
**type**: ``string`` **default**: ``'Twig\\Template'``
8888

8989
Twig templates are compiled into PHP classes before using them to render
9090
contents. This option defines the base class from which all the template classes

service_container.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ But, with ``autoconfigure: true``, you don't need the tag. In fact, if you're us
766766
the :ref:`default services.yaml config <service-container-services-load-example>`,
767767
you don't need to do *anything*: the service will be automatically loaded. Then,
768768
``autoconfigure`` will add the ``twig.extension`` tag *for* you, because your class
769-
implements ``Twig_ExtensionInterface``. And thanks to ``autowire``, you can even add
769+
implements ``Twig\\Extension\\ExtensionInterface``. And thanks to ``autowire``, you can even add
770770
constructor arguments without any configuration.
771771

772772
.. _container-public:

service_container/tags.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ Autoconfiguring Tags
6060

6161
If you enable :ref:`autoconfigure <services-autoconfigure>`, then some tags are
6262
automatically applied for you. That's true for the ``twig.extension`` tag: the
63-
container sees that your class extends ``Twig_Extension`` (or more accurately,
64-
that it implements ``Twig_ExtensionInterface``) and adds the tag for you.
63+
container sees that your class extends ``AbstractExtension`` (or more accurately,
64+
that it implements ``ExtensionInterface``) and adds the tag for you.
6565

6666
.. tip::
6767

templating/twig_extension.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@ callable defined in ``getFilters()``::
9898
namespace App\Twig;
9999

100100
use App\Twig\AppRuntime;
101+
use Twig\Extension\AbstractExtension;
102+
use Twig\TwigFilter;
101103

102-
class AppExtension extends \Twig_Extension
104+
class AppExtension extends AbstractExtension
103105
{
104106
public function getFilters()
105107
{
106108
return array(
107109
// the logic of this filter is now implemented in a different class
108-
new \Twig_SimpleFilter('price', array(AppRuntime::class, 'priceFilter')),
110+
new TwigFilter('price', array(AppRuntime::class, 'priceFilter')),
109111
);
110112
}
111113
}

0 commit comments

Comments
 (0)
0