File tree Expand file tree Collapse file tree 3 files changed +67
-13
lines changed
Expand file tree Collapse file tree 3 files changed +67
-13
lines changed Original file line number Diff line number Diff line change 1515use Symfony \Component \DependencyInjection \ContainerBuilder ;
1616use Symfony \Component \DependencyInjection \Reference ;
1717
18- class MissingExtensionSuggestorPass implements CompilerPassInterface
19- {
20- /** @return void */
21- public function process (ContainerBuilder $ container )
18+ if (!method_exists (ContainerBuilder::class, 'getAutoconfiguredAttributes ' )) {
19+ class MissingExtensionSuggestorPass implements CompilerPassInterface
2220 {
23- if ($ container ->getParameter ('kernel.debug ' )) {
21+ public function process (ContainerBuilder $ container ): void
22+ {
23+ if (!$ container ->getParameter ('kernel.debug ' )) {
24+ return ;
25+ }
26+ $ twigDefinition = $ container ->getDefinition ('twig ' );
27+ $ twigDefinition
28+ ->addMethodCall ('registerUndefinedFilterCallback ' , [[new Reference ('twig.missing_extension_suggestor ' ), 'suggestFilter ' ]])
29+ ->addMethodCall ('registerUndefinedFunctionCallback ' , [[new Reference ('twig.missing_extension_suggestor ' ), 'suggestFunction ' ]])
30+ ->addMethodCall ('registerUndefinedTokenParserCallback ' , [[new Reference ('twig.missing_extension_suggestor ' ), 'suggestTag ' ]])
31+ ;
32+ }
33+ }
34+ } else {
35+ class MissingExtensionSuggestorPass implements CompilerPassInterface
36+ {
37+ /** @return void */
38+ public function process (ContainerBuilder $ container )
39+ {
40+ if (!$ container ->getParameter ('kernel.debug ' )) {
41+ return ;
42+ }
2443 $ twigDefinition = $ container ->getDefinition ('twig ' );
2544 $ twigDefinition
2645 ->addMethodCall ('registerUndefinedFilterCallback ' , [[new Reference ('twig.missing_extension_suggestor ' ), 'suggestFilter ' ]])
Original file line number Diff line number Diff line change 1818use Symfony \Component \DependencyInjection \Loader \PhpFileLoader ;
1919use Twig \Extra \TwigExtraBundle \Extensions ;
2020
21+ if (!method_exists (ContainerBuilder::class, 'getAutoconfiguredAttributes ' )) {
22+ /** @internal */
23+ trait TwigExtraExtensionTrait
24+ {
25+ public function load (array $ configs , ContainerBuilder $ container ): void
26+ {
27+ $ this ->doLoad ($ configs , $ container );
28+ }
29+ }
30+ } else {
31+ /** @internal */
32+ trait TwigExtraExtensionTrait
33+ {
34+ /** @return void */
35+ public function load (array $ configs , ContainerBuilder $ container )
36+ {
37+ $ this ->doLoad ($ configs , $ container );
38+ }
39+ }
40+
41+ }
42+
2143/**
2244 * @author Fabien Potencier <[email protected] > 2345 */
2446class TwigExtraExtension extends Extension
2547{
26- /** @return void */
27- public function load (array $ configs , ContainerBuilder $ container )
48+ use TwigExtraExtensionTrait;
49+
50+ private function doLoad (array $ configs , ContainerBuilder $ container ): void
2851 {
2952 $ loader = new PhpFileLoader ($ container , new FileLocator (\dirname (__DIR__ ).'/Resources/config ' ));
3053 $ configuration = $ this ->getConfiguration ($ configs , $ container );
Original file line number Diff line number Diff line change 1515use Symfony \Component \HttpKernel \Bundle \Bundle ;
1616use Twig \Extra \TwigExtraBundle \DependencyInjection \Compiler \MissingExtensionSuggestorPass ;
1717
18- class TwigExtraBundle extends Bundle
19- {
20- /** @return void */
21- public function build (ContainerBuilder $ container )
18+ if (!method_exists (ContainerBuilder::class, 'getAutoconfiguredAttributes ' )) {
19+ class TwigExtraBundle extends Bundle
2220 {
23- parent ::build ($ container );
21+ public function build (ContainerBuilder $ container ): void
22+ {
23+ parent ::build ($ container );
2424
25- $ container ->addCompilerPass (new MissingExtensionSuggestorPass ());
25+ $ container ->addCompilerPass (new MissingExtensionSuggestorPass ());
26+ }
27+ }
28+ } else {
29+ class TwigExtraBundle extends Bundle
30+ {
31+ /** @return void */
32+ public function build (ContainerBuilder $ container )
33+ {
34+ parent ::build ($ container );
35+
36+ $ container ->addCompilerPass (new MissingExtensionSuggestorPass ());
37+ }
2638 }
2739}
You can’t perform that action at this time.
0 commit comments