Skip to content

Commit b3d09fb

Browse files
committed
minor #10025 Add missing RuntimeExtensionInterface (tjamps, javiereguiluz)
This PR was submitted for the 4.1 branch but it was merged into the 3.4 branch instead (closes #10025). Discussion ---------- Add missing RuntimeExtensionInterface If the Twig runtime class does not implement RuntimeExtensionInterface, the autoconfigure feature of the container will not tag it with `twig.runtime`, and an exception will be thrown ("Unable to load the "App\Twig\AppRuntime" runtime.") <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 4e9b044 Added the missing versionadded directive cb102c1 Remove duplicate `use` keyword 0e8d863 Add missing RuntimeExtensionInterface
2 parents a455e7a + 4e9b044 commit b3d09fb

File tree

1 file changed

+8
-45
lines changed

1 file changed

+8
-45
lines changed

templating/twig_extension.rst

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ previous ``priceFilter()`` method::
115115
// src/AppBundle/Twig/AppRuntime.php
116116
namespace AppBundle\Twig;
117117

118-
class AppRuntime
118+
use Twig\Extension\RuntimeExtensionInterface;
119+
120+
class AppRuntime implements RuntimeExtensionInterface
119121
{
120122
public function __construct()
121123
{
@@ -132,51 +134,12 @@ previous ``priceFilter()`` method::
132134
}
133135
}
134136

135-
Register the Lazy-Loaded Extension as a Service
136-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137-
138-
Finally, register your new class as a service and tag it with ``twig.runtime``
139-
(and optionally inject any service needed by the Twig extension runtime):
140-
141-
.. configuration-block::
142-
143-
.. code-block:: yaml
144-
145-
# app/config/services.yml
146-
services:
147-
app.twig_runtime:
148-
class: AppBundle\Twig\AppRuntime
149-
public: false
150-
tags:
151-
- { name: twig.runtime }
152-
153-
.. code-block:: xml
154-
155-
<!-- app/config/services.xml -->
156-
<?xml version="1.0" encoding="UTF-8" ?>
157-
<container xmlns="http://symfony.com/schema/dic/services"
158-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
159-
xsi:schemaLocation="http://symfony.com/schema/dic/services
160-
http://symfony.com/schema/dic/services/services-1.0.xsd">
161-
162-
<services>
163-
<service id="app.twig_runtime"
164-
class="AppBundle\Twig\AppRuntime"
165-
public="false">
166-
<tag name="twig.runtime" />
167-
</service>
168-
</services>
169-
</container>
170-
171-
.. code-block:: php
172-
173-
// app/config/services.php
174-
use AppBundle\Twig\AppExtension;
137+
.. versionadded:: 3.4
138+
The ``RuntimeExtensionInterface`` was introduced in Symfony 3.4.
175139

176-
$container
177-
->register('app.twig_runtime', AppRuntime::class)
178-
->setPublic(false)
179-
->addTag('twig.runtime');
140+
If you're using the default ``services.yaml`` configuration, this will already
141+
work! Otherwise, :ref:`create a service <service-container-creating-service>`
142+
for this class and :doc:`tag your service </service_container/tags>` with ``twig.runtime``.
180143

181144
.. _`Twig extensions documentation`: http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension
182145
.. _`global variables`: http://twig.sensiolabs.org/doc/advanced.html#id1

0 commit comments

Comments
 (0)