@@ -570,18 +570,23 @@ private function variable($id, $filters, $escape, $level)
570
570
if (!(%s)) {
571
571
throw new Mustache_Exception_UnknownFilterException(%s);
572
572
}
573
- $value = call_user_func($filter, $value );%s
573
+ $value = call_user_func($filter, %s );%s
574
574
' ;
575
+ const FILTER_FIRST_VALUE = '$this->resolveValue($value, $context) ' ;
576
+ const FILTER_VALUE = '$value ' ;
575
577
576
578
/**
577
579
* Generate Mustache Template variable filtering PHP source.
578
580
*
581
+ * If the initial $value is a lambda it will be resolved before starting the filter chain.
582
+ *
579
583
* @param string[] $filters Array of filters
580
584
* @param int $level
585
+ * @param bool $first (default: false)
581
586
*
582
587
* @return string Generated filter PHP source
583
588
*/
584
- private function getFilters (array $ filters , $ level )
589
+ private function getFilters (array $ filters , $ level, $ first = true )
585
590
{
586
591
if (empty ($ filters )) {
587
592
return '' ;
@@ -593,8 +598,9 @@ private function getFilters(array $filters, $level)
593
598
$ findArg = $ this ->getFindMethodArgs ($ method );
594
599
$ callable = $ this ->getCallable ('$filter ' );
595
600
$ msg = var_export ($ name , true );
601
+ $ value = $ first ? self ::FILTER_FIRST_VALUE : self ::FILTER_VALUE ;
596
602
597
- return sprintf ($ this ->prepare (self ::FILTER , $ level ), $ method , $ filter , $ findArg , $ callable , $ msg , $ this ->getFilters ($ filters , $ level ));
603
+ return sprintf ($ this ->prepare (self ::FILTER , $ level ), $ method , $ filter , $ findArg , $ callable , $ msg , $ value , $ this ->getFilters ($ filters , $ level, false ));
598
604
}
599
605
600
606
const LINE = '$buffer .= "\n"; ' ;
0 commit comments