/**
* 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;
}
}