LightnCandy\Compiler::customHelper PHP Method

customHelper() protected static method

Return compiled PHP code for a handlebars custom helper token
protected static customHelper ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars, boolean $raw, boolean $nosep, boolean $subExp = false ) : string | null
$context array\arraystring | integer>
$vars arrayinteger | string | array>
$raw boolean is this {{{ token or not
$nosep boolean true to compile without seperator
$subExp boolean true when compile for subexpression
return string | null Return compiled code segment for the token when the token is custom helper
    protected static function customHelper(&$context, $vars, $raw, $nosep, $subExp = false)
    {
        if (!isset($context['helpers'][$vars[0][0]])) {
            if ($subExp) {
                if ($vars[0][0] == 'lookup') {
                    return static::compileLookup($context, $vars, $raw, true);
                }
            }
            return;
        }
        $fn = $raw ? 'raw' : $context['ops']['enc'];
        $ch = array_shift($vars);
        $v = static::getVariableNames($context, $vars);
        static::addUsageCount($context, 'helpers', $ch[0]);
        $sep = $nosep ? '' : $context['ops']['seperator'];
        return $sep . static::getFuncName($context, 'hbch', "{$ch['0']} " . implode(' ', $v[1])) . "\$cx, '{$ch['0']}', {$v[0]}, '{$fn}', \$in){$sep}";
    }