LightnCandy\Expression::toString PHP Метод

toString() публичный статический Метод

get normalized handlebars expression for a variable
public static toString ( integer $levels, boolean $spvar, array $var ) : string
$levels integer trace N levels top parent scope
$spvar boolean is the path start with @ or not
$var array
Результат string normalized expression for debug display
    public static function toString($levels, $spvar, $var)
    {
        return ($spvar ? '@' : '') . str_repeat('../', $levels) . (is_array($var) && count($var) ? implode('.', array_map(function ($v) {
            return $v === null ? 'this' : "[{$v}]";
        }, $var)) : 'this');
    }

Usage Example

Пример #1
0
 /**
  * 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;
     }
 }
All Usage Examples Of LightnCandy\Expression::toString