Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Commit170b631
committed
minor#60415 [TwigBundle] Improve error when autoconfiguring a class with both
This PR was merged into the 7.3 branch.Discussion----------[TwigBundle] Improve error when autoconfiguring a class with both `ExtensionInterface` and Twig callable attribute| Q | A| ------------- | ---| Branch? | 7.3| Bug fix? | no| New feature? | no| Deprecations? | no| Issues | -| License | MITReported by Javier:> I'm updating Twig extensions to use the `#[AsTwig...]` attributes. I removed the `getFunctions()` method and had this:> ```> class FooExtension extends AbstractExtension> {> #[AsTwigFunction('name_of_function')]> public function foo(): string> {> // ...> }> }> ```> Then I saw this exception: `Unable to register extension "App\Twig\FooExtension" as it is already registered.`> My error is that I forgot to remove extends `AbstractExtension`But I think that Symfony's error exception should be more helpful. A quick example of something that could've helped me: *"When using the AsTwigFunction attribute, your Twig extension cannot extend AbstractExtension"*The ExtensionSet exception is thrown because the same an extension is registered twice:1. It has the `twig.extension` tag autoconfigured because it implements `Twig\Extension\ExtensionInterface`2. An `AttributeExtension` is registered for this class because it as one of the extension attributes (since#52748)Previous exception when `twig` service is instanciated:> LogicException : Unable to register extension "Symfony\Bundle\TwigBundle\Tests\Functional\InvalidExtensionWithAttributes" as it is already registered.New exception during container compilation:> Symfony\Component\DependencyInjection\Exception\LogicException : The class "Symfony\Bundle\TwigBundle\Tests\Functional\InvalidExtensionWithAttributes" cannot both extend "Twig\Extension\AbstractExtension" and use the "#[Twig\Attribute\AsTwigFilter]" attribute on method "funFilter()", choose one or the other.Checking `AbstractExtension` makes the error message more specific to the code, as most extensions extend this class and doesn't implement the interface directly.Commits-------752b41d [TwigBundle] Improve error when autoconfiguring a class with both ExtensionInterface and Twig callable attributeExtensionInterface
and Twig callable attribute (GromNaN)File tree
2 files changed
+72
-15
lines changed- src/Symfony/Bundle/TwigBundle
- DependencyInjection/Compiler
- Tests/Functional
2 files changed
+72
-15
lines changedLines changed: 11 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
14 | 14 |
| |
15 | 15 |
| |
16 | 16 |
| |
| 17 | + | |
17 | 18 |
| |
18 | 19 |
| |
19 | 20 |
| |
| 21 | + | |
20 | 22 |
| |
| 23 | + | |
21 | 24 |
| |
22 | 25 |
| |
23 | 26 |
| |
| |||
33 | 36 |
| |
34 | 37 |
| |
35 | 38 |
| |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
36 | 47 |
| |
37 | 48 |
| |
38 | 49 |
| |
|
Lines changed: 61 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
| 14 | + | |
| 15 | + | |
| 16 | + | |
14 | 17 |
| |
15 | 18 |
| |
16 | 19 |
| |
17 | 20 |
| |
18 | 21 |
| |
| 22 | + | |
19 | 23 |
| |
20 | 24 |
| |
21 | 25 |
| |
22 | 26 |
| |
23 | 27 |
| |
24 | 28 |
| |
25 | 29 |
| |
| 30 | + | |
26 | 31 |
| |
27 | 32 |
| |
28 | 33 |
| |
29 | 34 |
| |
30 |
| - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
31 | 38 |
| |
32 | 39 |
| |
33 | 40 |
| |
34 | 41 |
| |
| 42 | + | |
35 | 43 |
| |
36 |
| - | |
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
41 |
| - | |
42 |
| - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
43 | 47 |
| |
44 | 48 |
| |
45 | 49 |
| |
| |||
53 | 57 |
| |
54 | 58 |
| |
55 | 59 |
| |
56 |
| - | |
57 |
| - | |
58 |
| - | |
59 |
| - | |
60 |
| - | |
61 | 60 |
| |
62 | 61 |
| |
63 | 62 |
| |
| |||
73 | 72 |
| |
74 | 73 |
| |
75 | 74 |
| |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
76 | 94 |
| |
77 | 95 |
| |
78 | 96 |
| |
79 | 97 |
| |
| 98 | + | |
80 | 99 |
| |
81 | 100 |
| |
82 | 101 |
| |
| |||
85 | 104 |
| |
86 | 105 |
| |
87 | 106 |
| |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
88 | 125 |
| |
89 | 126 |
| |
90 | 127 |
| |
| |||
112 | 149 |
| |
113 | 150 |
| |
114 | 151 |
| |
115 |
| - | |
116 |
| - | |
| 152 | + | |
| 153 | + | |
117 | 154 |
| |
118 | 155 |
| |
119 | 156 |
| |
120 | 157 |
| |
121 | 158 |
| |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + |
0 commit comments
Comments
(0)