isSubExp() public static method

Check a parsed result is a subexpression or not
public static isSubExp ( arrayinteger | array> $var ) : boolean
$var arrayinteger | array>
return boolean return true when input is a subexpression
Beispiel #1
0
 /**
  * handle partial
  *
  * @param array<string,array|string|integer> $context current compile context
  * @param array<boolean|integer|string|array> $vars parsed arguments list
  *
  * @return string Return compiled code segment for the partial
  */
 public static function partial(&$context, $vars)
 {
     // mustache spec: ignore missing partial
     if ($context['usedFeature']['dynpartial'] === 0 && $context['usedFeature']['inlpartial'] === 0 && !isset($context['usedPartial'][$vars[0][0]])) {
         return $context['ops']['seperator'];
     }
     Parser::getBlockParams($vars);
     $p = array_shift($vars);
     if ($context['flags']['runpart']) {
         if (!isset($vars[0])) {
             $vars[0] = $context['flags']['partnc'] ? array(0, 'null') : array();
         }
         $v = static::getVariableNames($context, $vars);
         $tag = ">{$p['0']} " . implode(' ', $v[1]);
         if (Parser::isSubExp($p)) {
             list($p) = static::compileSubExpression($context, $p[1]);
         } else {
             $p = "'{$p['0']}'";
         }
         $sp = $context['tokens']['partialind'] ? ", '{$context['tokens']['partialind']}'" : '';
         return $context['ops']['seperator'] . static::getFuncName($context, 'p', $tag) . "\$cx, {$p}, {$v['0']}{$sp}){$context['ops']['seperator']}";
     }
     return "{$context['ops']['seperator']}'" . Partial::compileStatic($context, $p[0]) . "'{$context['ops']['seperator']}";
 }
Beispiel #2
0
 /**
  * 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;
 }