@@ -230,25 +230,25 @@ public function setLexerOptions($options)
230
230
*/
231
231
private function _addCustom ($ classType , $ elements )
232
232
{
233
- $ classFunction = 'Twig_ ' . $ classType . ' _Function ' ;
233
+ $ classFunction = 'Twig_ ' . $ classType ;
234
234
235
235
foreach ($ elements as $ name => $ func ) {
236
236
$ twigElement = null ;
237
237
238
238
switch ($ func ) {
239
- // Just a name of function
240
- case is_string ($ func ):
241
- $ twigElement = new $ classFunction ($ func );
239
+ // Callable (including just a name of function).
240
+ case is_callable ($ func ):
241
+ $ twigElement = new $ classFunction ($ name , $ func );
242
242
break ;
243
- // Name of function + options array
244
- case is_array ($ func ) && is_string ($ func [0 ]) && isset ( $ func [ 1 ]) && is_array ( $ func [ 1 ]):
245
- $ twigElement = new $ classFunction ($ func [0 ], $ func [1 ]);
243
+ // Callable (including just a name of function) + options array.
244
+ case is_array ($ func ) && is_callable ($ func [0 ]):
245
+ $ twigElement = new $ classFunction ($ name , $ func [0 ], (! empty ( $ func [1 ]) && is_array ( $ func [ 1 ])) ? $ func [ 1 ] : [ ]);
246
246
break ;
247
247
}
248
248
249
249
if ($ twigElement !== null ) {
250
- $ this ->twig ->{'add ' .$ classType }($ name , $ twigElement );
251
- } elseif ($ func instanceof \Twig_SimpleFunction || $ func instanceof \Twig_SimpleFilter ) {
250
+ $ this ->twig ->{'add ' .$ classType }($ twigElement );
251
+ } elseif ($ func instanceof \Twig_Function || $ func instanceof \Twig_Filter ) {
252
252
$ this ->twig ->{'add ' .$ classType }($ func );
253
253
} else {
254
254
throw new \Exception ("Incorrect options for \"$ classType \" $ name. " );
0 commit comments