protected static function advancedVariable($vars, &$context, $token)
{
$ret = array();
$i = 0;
foreach ($vars as $idx => $var) {
// handle (...)
if (preg_match(SafeString::IS_SUBEXP_SEARCH, $var)) {
$ret[$i] = static::subexpression($var, $context);
$i++;
continue;
}
// handle |...|
if (preg_match(SafeString::IS_BLOCKPARAM_SEARCH, $var, $matched)) {
$ret[static::BLOCKPARAM] = explode(' ', $matched[1]);
continue;
}
if ($context['flags']['namev']) {
if (preg_match('/^((\\[([^\\]]+)\\])|([^=^["\']+))=(.+)$/', $var, $m)) {
if (!$context['flags']['advar'] && $m[3]) {
$context['error'][] = "Wrong argument name as '[{$m['3']}]' in {$token} ! You should fix your template or compile with LightnCandy::FLAG_ADVARNAME flag.";
}
$idx = $m[3] ? $m[3] : $m[4];
$var = $m[5];
// handle foo=(...)
if (preg_match(SafeString::IS_SUBEXP_SEARCH, $var)) {
$ret[$idx] = static::subexpression($var, $context);
continue;
}
}
}
if ($context['flags']['advar'] && !preg_match("/^(\"|\\\\')(.*)(\"|\\\\')\$/", $var)) {
// foo] Rule 1: no starting [ or [ not start from head
if (preg_match('/^[^\\[\\.]+[\\]\\[]/', $var) || preg_match('/[\\[\\]][^\\]\\.]+$/', $var) || preg_match('/\\][^\\]\\[\\.]+\\./', $var) || preg_match('/\\.[^\\]\\[\\.]+\\[/', preg_replace('/^(..\\/)+/', '', preg_replace('/\\[[^\\]]+\\]/', '[XXX]', $var)))) {
$context['error'][] = "Wrong variable naming as '{$var}' in {$token} !";
} else {
$name = preg_replace('/(\\[.+?\\])/', '', $var);
// Scan for invalid charactors which not be protected by [ ]
// now make ( and ) pass, later fix
if (preg_match('/[!"#%\'*+,;<=>{|}~]/', $name)) {
$context['error'][] = "Wrong variable naming as '{$var}' in {$token} ! You should wrap ! \" # % & ' * + , ; < = > { | } ~ into [ ]";
}
}
}
$var = static::getExpression($var, $context, $idx);
if (is_string($idx)) {
$ret[$idx] = $var;
} else {
$ret[$i] = $var;
$i++;
}
}
return $ret;
}