/** * 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']}"; }
/** * validate partial * * @param array<string,array|string|integer> $context current compile context * @param array<boolean|integer|string|array> $vars parsed arguments list * * @return integer|boolean Return 1 or larger number for runtime partial, return true for other case */ protected static function partial(&$context, $vars) { if (Parser::isSubExp($vars[0])) { if ($context['flags']['runpart']) { return $context['usedFeature']['dynpartial']++; } else { $context['error'][] = "You use dynamic partial name as '{$vars[0][2]}', this only works with option FLAG_RUNTIMEPARTIAL enabled"; return true; } } else { if ($context['currentToken'][Token::POS_OP] !== '#>') { Partial::read($context, $vars[0][0]); } } if (!$context['flags']['runpart']) { $named = count(array_diff_key($vars, array_keys(array_keys($vars)))) > 0; if ($named || count($vars) > 1) { $context['error'][] = "Do not support {{>{$context['currentToken'][Token::POS_INNERTAG]}}}, you should do compile with LightnCandy::FLAG_RUNTIMEPARTIAL flag"; } } return true; }