/** * Return compiled PHP code for a handlebars block end token * * @param array<string,array|string|integer> $context current compile context * @param array<boolean|integer|string|array> $vars parsed arguments list * @param string|null $match should also match to this operator * * @return boolean Return true */ protected static function blockEnd(&$context, &$vars, $match = null) { $context['level']--; $c = count($context['stack']) - 2; $pop = $c >= 0 ? $context['stack'][$c + 1] : ''; if ($match !== null && $match !== $pop) { return; } $pop2 = $c >= 0 ? $context['stack'][$c] : ''; switch ($context['currentToken'][Token::POS_INNERTAG]) { case 'with': if (!$context['flags']['nohbh']) { if ($pop2 !== '[with]') { $context['error'][] = 'Unexpect token: {{/with}} !'; return; } } return true; } switch ($pop) { case '#': case '^': $elsechain = array_shift($context['elselvl']); if (isset($elsechain[0])) { $context['currentToken'][Token::POS_RSPACE] = $context['currentToken'][Token::POS_BACKFILL] = '{{/' . implode('}}{{/', $elsechain) . '}}' . Token::toString($context['currentToken']) . $context['currentToken'][Token::POS_RSPACE]; return Token::POS_BACKFILL; } case '#>': case '#*': list($levels, $spvar, $var) = Expression::analyze($context, $vars[0]); $v = Expression::toString($levels, $spvar, $var); if ($pop2 !== $v) { $context['error'][] = 'Unexpect token ' . Token::toString($context['currentToken']) . " ! Previous token {{{$pop}{$pop2}}} is not closed"; return; } return true; default: $context['error'][] = 'Unexpect token: ' . Token::toString($context['currentToken']) . ' !'; return; } }
/** * compile {{with}} token * * @param array<string,array|string|integer> $context current compile context * @param array<boolean|integer|string|array> $vars parsed arguments list * * @return string|null Return compiled code segment for the token */ protected static function with(&$context, $vars) { $v = isset($vars[1]) ? static::getVariableNameOrSubExpression($context, $vars[1]) : array(null, array()); $bp = Parser::getBlockParams($vars); $bs = $bp ? 'array(' . Expression::listString($bp) . ')' : 'null'; $be = $bp ? " as |{$bp['0']}|" : ''; return $context['ops']['seperator'] . static::getFuncName($context, 'wi', 'with ' . $v[1] . $be) . "\$cx, {$v[0]}, {$bs}, \$in, function(\$cx, \$in) {{$context['ops']['f_start']}"; }
/** * Return compiled PHP code for a handlebars block end token * * @param array<string,array|string|integer> $context current compile context * @param array<boolean|integer|string|array> $vars parsed arguments list * @param string|null $matchop should also match to this operator * * @return boolean Return true */ protected static function blockEnd(&$context, $vars, $match = null) { $context['level']--; $c = count($context['stack']) - 2; $pop = $c >= 0 ? $context['stack'][$c + 1] : ''; if ($match !== null && $match !== $pop) { return; } $pop2 = $c >= 0 ? $context['stack'][$c] : ''; switch ($context['currentToken'][Token::POS_INNERTAG]) { case 'with': if (!$context['flags']['nohbh']) { if ($pop2 !== '[with]') { $context['error'][] = 'Unexpect token: {{/with}} !'; return; } } return true; } switch ($pop) { case '#>': case '#*': case '#': case '^': list($levels, $spvar, $var) = Expression::analyze($context, $vars[0]); $v = Expression::toString($levels, $spvar, $var); if ($pop2 !== $v) { $context['error'][] = 'Unexpect token ' . Token::toString($context['currentToken']) . " ! Previous token {{{$pop}{$pop2}}} is not closed"; return; } if ($pop == '^') { return "{$context['ops']['cnd_else']}''{$context['ops']['cnd_end']}"; } return "{$context['ops']['f_end']}}){$context['ops']['seperator']}"; default: $context['error'][] = 'Unexpect token: ' . Token::toString($context['currentToken']) . ' !'; return; } }