Skip to content

Commit 2d4e09a

Browse files
remove AbstractExtension extends
1 parent 7952544 commit 2d4e09a

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

quick_tour/the_architecture.rst

+5-6
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,16 @@ Twig Extension & Autoconfiguration
158158

159159
Thanks to Symfony's service handling, you can *extend* Symfony in many ways, like
160160
by creating an event subscriber or a security voter for complex authorization
161-
rules. Let's add a new filter to Twig called ``greet``. How? Create a class
162-
that extends ``AbstractExtension``::
161+
rules. Let's add a new filter to Twig called ``greet``. How? Create a simple class
162+
with your logic::
163163

164164
// src/Twig/GreetExtension.php
165165
namespace App\Twig;
166166

167167
use App\GreetingGenerator;
168168
use Twig\Attribute\AsTwigFilter;
169-
use Twig\Extension\AbstractExtension;
170169

171-
class GreetExtension extends AbstractExtension
170+
class GreetExtension
172171
{
173172
public function __construct(
174173
private GreetingGenerator $greetingGenerator,
@@ -191,8 +190,8 @@ After creating just *one* file, you can use this immediately:
191190
{# templates/default/index.html.twig #}
192191
{# Will print something like "Hey Symfony!" #}
193192
<h1>{{ name|greet }}</h1>
194-
195-
How does this work? Symfony notices that your class extends ``AbstractExtension``
193+
194+
How does this work? Symfony notices that your class uses Twig attributes
196195
and so *automatically* registers it as a Twig extension. This is called autoconfiguration,
197196
and it works for *many* many things. Create a class and then extend a base class
198197
(or implement an interface). Symfony takes care of the rest.

templates.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -1555,15 +1555,14 @@ as currency:
15551555
15561556
.. _templates-twig-filter-attribute:
15571557

1558-
Create a class that extends ``AbstractExtension`` and fill in the logic::
1558+
Create a class and fill in the logic::
15591559

15601560
// src/Twig/AppExtension.php
15611561
namespace App\Twig;
15621562

15631563
use Twig\Attribute\AsTwigFilter;
1564-
use Twig\Extension\AbstractExtension;
15651564

1566-
class AppExtension extends AbstractExtension
1565+
class AppExtension
15671566
{
15681567
#[AsTwigFilter('price')]
15691568
public function formatPrice(float $number, int $decimals = 0, string $decPoint = '.', string $thousandsSep = ','): string
@@ -1584,9 +1583,8 @@ If you want to create a function instead of a filter, use the
15841583
namespace App\Twig;
15851584

15861585
use Twig\Attribute\AsTwigFunction;
1587-
use Twig\Extension\AbstractExtension;
15881586

1589-
class AppExtension extends AbstractExtension
1587+
class AppExtension
15901588
{
15911589
#[AsTwigFunction('area')]
15921590
public function calculateArea(int $width, int $length): int

0 commit comments

Comments
 (0)