13
13
14
14
use Symfony \Bundle \FullStack ;
15
15
use Twig \Error \SyntaxError ;
16
+ use Twig \TwigFilter ;
17
+ use Twig \TwigFunction ;
16
18
17
19
/**
18
20
* @internal
@@ -30,6 +32,8 @@ class UndefinedCallableHandler
30
32
'asset ' => 'asset ' ,
31
33
'asset_version ' => 'asset ' ,
32
34
'dump ' => 'debug-bundle ' ,
35
+ 'encore_entry_link_tags ' => 'webpack-encore-bundle ' ,
36
+ 'encore_entry_script_tags ' => 'webpack-encore-bundle ' ,
33
37
'expression ' => 'expression-language ' ,
34
38
'form_widget ' => 'form ' ,
35
39
'form_errors ' => 'form ' ,
@@ -64,34 +68,40 @@ class UndefinedCallableHandler
64
68
'workflow ' => 'enable "framework.workflows" ' ,
65
69
];
66
70
67
- public static function onUndefinedFilter (string $ name ): bool
71
+ /**
72
+ * @return TwigFilter|false
73
+ */
74
+ public static function onUndefinedFilter (string $ name )
68
75
{
69
76
if (!isset (self ::FILTER_COMPONENTS [$ name ])) {
70
77
return false ;
71
78
}
72
79
73
- self ::onUndefined ($ name , 'filter ' , self ::FILTER_COMPONENTS [$ name ]);
74
-
75
- return true ;
80
+ throw new SyntaxError (self ::onUndefined ($ name , 'filter ' , self ::FILTER_COMPONENTS [$ name ]));
76
81
}
77
82
78
- public static function onUndefinedFunction (string $ name ): bool
83
+ /**
84
+ * @return TwigFunction|false
85
+ */
86
+ public static function onUndefinedFunction (string $ name )
79
87
{
80
88
if (!isset (self ::FUNCTION_COMPONENTS [$ name ])) {
81
89
return false ;
82
90
}
83
91
84
- self ::onUndefined ($ name , 'function ' , self ::FUNCTION_COMPONENTS [$ name ]);
92
+ if ('webpack-encore-bundle ' === self ::FUNCTION_COMPONENTS [$ name ]) {
93
+ return new TwigFunction ($ name , static function () { return '' ; });
94
+ }
85
95
86
- return true ;
96
+ throw new SyntaxError ( self :: onUndefined ( $ name , ' function ' , self :: FUNCTION_COMPONENTS [ $ name ])) ;
87
97
}
88
98
89
- private static function onUndefined (string $ name , string $ type , string $ component )
99
+ private static function onUndefined (string $ name , string $ type , string $ component ): string
90
100
{
91
101
if (class_exists (FullStack::class) && isset (self ::FULL_STACK_ENABLE [$ component ])) {
92
- throw new SyntaxError ( sprintf ('Did you forget to %s? Unknown %s "%s". ' , self ::FULL_STACK_ENABLE [$ component ], $ type , $ name) );
102
+ return sprintf ('Did you forget to %s? Unknown %s "%s". ' , self ::FULL_STACK_ENABLE [$ component ], $ type , $ name );
93
103
}
94
104
95
- throw new SyntaxError ( sprintf ('Did you forget to run "composer require symfony/%s"? Unknown %s "%s". ' , $ component , $ type , $ name) );
105
+ return sprintf ('Did you forget to run "composer require symfony/%s"? Unknown %s "%s". ' , $ component , $ type , $ name );
96
106
}
97
107
}
0 commit comments