/** * Pseudocast (expand). * @return MacroTokens */ public function expandFilter(MacroTokens $tokens) { $res = new MacroTokens('array('); $expand = NULL; while ($tokens->nextToken()) { if ($tokens->isCurrent('(expand)') && $tokens->depth === 0) { $expand = TRUE; $res->append('),'); } elseif ($expand && $tokens->isCurrent(',') && !$tokens->depth) { $expand = FALSE; $res->append(', array('); } else { $res->append($tokens->currentToken()); } } if ($expand !== NULL) { $res->prepend('array_merge(')->append($expand ? ', array()' : ')'); } return $res->append(')'); }
/** * 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; }