/**
  * Formats modifiers calling.
  * @param  MacroTokens
  * @param  string
  * @throws CompileException
  * @return MacroTokens
  */
 public function modifiersFilter(MacroTokens $tokens, $var)
 {
     $inside = FALSE;
     $res = new MacroTokens($var);
     while ($tokens->nextToken()) {
         if ($tokens->isCurrent(MacroTokens::T_WHITESPACE)) {
             $res->append(' ');
         } elseif ($inside) {
             if ($tokens->isCurrent(':', ',')) {
                 $res->append(', ');
                 $tokens->nextAll(MacroTokens::T_WHITESPACE);
             } elseif ($tokens->isCurrent('|')) {
                 $res->append(')');
                 $inside = FALSE;
             } else {
                 $res->append($tokens->currentToken());
             }
         } else {
             if ($tokens->isCurrent(MacroTokens::T_SYMBOL)) {
                 if ($this->compiler && $tokens->isCurrent('escape')) {
                     $res = $this->escapeFilter($res);
                     $tokens->nextToken('|');
                 } elseif (!strcasecmp($tokens->currentValue(), 'safeurl')) {
                     $res->prepend('Latte\\Runtime\\Filters::safeUrl(');
                     $inside = TRUE;
                 } else {
                     $res->prepend('$template->' . $tokens->currentValue() . '(');
                     $inside = TRUE;
                 }
             } else {
                 throw new CompileException("Modifier name must be alphanumeric string, '{$tokens->currentValue()}' given.");
             }
         }
     }
     if ($inside) {
         $res->append(')');
     }
     return $res;
 }
Example #2
0
 /**
  * Formats modifiers calling.
  * @param  MacroTokens
  * @param  string
  * @throws CompileException
  * @return MacroTokens
  */
 public function modifierPass(MacroTokens $tokens, $var, $isContent = FALSE)
 {
     $inside = FALSE;
     $res = new MacroTokens($var);
     while ($tokens->nextToken()) {
         if ($tokens->isCurrent($tokens::T_WHITESPACE)) {
             $res->append(' ');
         } elseif ($inside) {
             if ($tokens->isCurrent(':', ',')) {
                 $res->append(', ');
                 $tokens->nextAll($tokens::T_WHITESPACE);
             } elseif ($tokens->isCurrent('|')) {
                 $res->append(')');
                 $inside = FALSE;
             } else {
                 $res->append($tokens->currentToken());
             }
         } else {
             if ($tokens->isCurrent($tokens::T_SYMBOL)) {
                 if ($tokens->isCurrent('escape')) {
                     if ($isContent) {
                         $res->prepend('LR\\Filters::convertTo($_fi, ' . var_export(implode($this->context), TRUE) . ', ')->append(')');
                     } else {
                         $res = $this->escapePass($res);
                     }
                     $tokens->nextToken('|');
                 } elseif (!strcasecmp($tokens->currentValue(), 'checkurl')) {
                     $res->prepend('LR\\Filters::safeUrl(');
                     $inside = TRUE;
                 } else {
                     $name = strtolower($tokens->currentValue());
                     $res->prepend($isContent ? '$this->filters->filterContent(' . var_export($name, TRUE) . ', $_fi, ' : 'call_user_func($this->filters->' . $name . ', ');
                     $inside = TRUE;
                 }
             } else {
                 throw new CompileException("Modifier name must be alphanumeric string, '{$tokens->currentValue()}' given.");
             }
         }
     }
     if ($inside) {
         $res->append(')');
     }
     return $res;
 }