validate partial block token

@param array<string,array|string|integer> $context current compile context
@param array<boolean|integer|string|array> $vars parsed arguments list

@return boolean|null Return true when partial block ends
961042
protected static function partialBlock(&$context, $vars) {
        if (count($context['partialblock']) > 0) {
            $ended = false;
            $append = $context['currentToken'][Token::POS_LOTHER] . $context['currentToken'][Token::POS_LSPACE];
            array_walk($context['partialblock'], function (&$pb) use ($append) {
                $pb .= $append;
            });
            if ($context['currentToken'][Token::POS_OP] === '/') {
                if (static::blockEnd($context, $vars, '#>') !== null) {
                    $c = $context['stack'][count($context['stack']) - 4];
                    $found = Partial::resolve($context, $vars[0][0]) !== null;
                    $v = $found ? "@partial-block{$context['parsed'][0][$c][1][Parser::PARTIALBLOCK]}" : "{$vars[0][0]}";
                    if (count($context['partialblock']) == 1) {
                        if ($found) {
                            $context['partials'][$v] = $context['partialblock'][0];
                        }
                        $context['usedPartial'][$v] = $context['partialblock'][0];
                        Partial::compileDynamic($context, $v);
                        if ($found) {
                            Partial::read($context, $vars[0][0]);
                        }
                    }
                    array_shift($context['partialblock']);
                    $context['parsed'][0] = array_slice($context['parsed'][0], 0, $c + 1);
                    $ended = true;
                }
            }
            $append = Token::toString($context['currentToken']);
            array_walk($context['partialblock'], function (&$pb) use ($context, $append) {
                $pb .= $append;
            });
            return $ended;
        }
    }
742503
protected static function compileToken(&$context, $info) {
        list($raw, $vars, $token, $indent) = $info;

        $context['tokens']['partialind'] = $indent;
        $context['currentToken'] = $token;

        if ($ret = static::operator($token[Token::POS_OP], $context, $vars)) {
            return $ret;
        }

        if (isset($vars[0][0])) {
            if ($ret = static::customHelper($context, $vars, $raw, true)) {
                return static::compileOutput($context, $ret, 'FIXME: helper', $raw, false);
            }
            if ($context['flags']['else'] && ($vars[0][0] === 'else')) {
                return static::doElse($context, $vars);
            }
            if ($vars[0][0] === 'lookup') {
                return static::compileLookup($context, $vars, $raw);
            }
            if ($vars[0][0] === 'log') {
                return static::compileLog($context, $vars, $raw);
            }
        }

        return static::compileVariable($context, $vars, $raw, false);
    }
440744
protected static function isDelimiter(&$context) {
        if (preg_match('/^=\s*([^ ]+)\s+([^ ]+)\s*=$/', $context['currentToken'][Token::POS_INNERTAG], $matched)) {
            $context['usedFeature']['delimiter']++;
            Parser::setDelimiter($context, $matched[1], $matched[2]);
            return true;
        }
    }
438894
public static function read(&$context, $name) {
        $isPB = ($name === '@partial-block');
        $context['usedFeature']['partial']++;

        if (isset($context['usedPartial'][$name])) {
            return;
        }

        $cnt = static::resolve($context, $name);

        if ($cnt !== null) {
            $context['usedPartial'][$name] = SafeString::escapeTemplate($cnt);
            return static::compileDynamic($context, $name);
        }

        if (!$context['flags']['skippartial'] && !$isPB) {
            $context['error'][] = "Can not find partial for '$name', you should provide partials or partialresolver in options";
        }
    }
1189260
protected function bindPartConcat($var, ServerRequestInterface $request, array $parts, &$part)
    {
        if (!is_string($var) || $var[0] !== '~' || substr($var, -1) !== '~') {
            return false;
        }
        
        $pieces = array_map('trim', explode('~', substr($var, 1, -1)));
        $bound = array_filter($this->bind($pieces, $request, $parts));
        $part = [join('', $bound)];
        
        return true;
    }
443272
public function validate( $variableSet, $nsMgr )
	{
		if ( isset( $this->as ) && strlen( $this->as ) )
		{
			$asQname = qname( $this->as, $nsMgr->getNamespaces() );
			// if ( is_null( $asQname ) || \XBRL::startsWith( $this->as, "xs:" ) || $asQname->namespaceURI != \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_SCHEMA ] )
			if ( $asQname && ! \XBRL::startsWith( $this->as, "xs:" ) && $asQname->namespaceURI == \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_SCHEMA ] )
			{
				\XBRL_Log::getInstance()->formula_validation( 'Variable parameter', 'Parameter type has namespace reserved for functions in the function registry (xfi)', array(
					'parameter' => $this->getQName()->clarkNotation(),
					'as' => $this->as,
					'error' => 'xbrlve:parameterTypeMismatch'
				) );

				return false;
			}
		}

		if ( isset( $this->select ) && strlen( $this->select ) )
		{
			try
			{
				$expression = XPath2Expression::Compile( $this->getSelectAsExpression(), $nsMgr );
				$this->expression = $expression;
			}
			catch( XPath2Exception $ex )
			{
				throw $ex;
			}
		}

		return true;
	}
1185750
function render($context = null, $vars = array())
    {
        $directives = $this->getDirectives();

        foreach ($directives as $directive) {
            list($i, $name, $argv) = $directive;
            $this->executeDirective($name, $context, $argv);
        }

        return $this->getProcessedSource();
    }
349002
public static function log(&$context, $vars) {
        if (isset($vars[0][0]) && ($vars[0][0] === 'log')) {
            if (!$context['flags']['nohbh']) {
                if (count($vars) < 2) {
                    $context['error'][] = "No argument after {{log}} !";
                }
                $context['usedFeature']['log']++;
                return true;
            }
        }
    }
471153
public function partial($template, $vars=array())
	{
		return $this->_renderTemplate($template,
			array_merge($this->_vars, $vars));
	}
88666
private function validateRequest(ServerRequestInterface $request, array &$tokens)
    {
        $data = $request->getParsedBody();

        if (!isset($data[$this->formIndex]) || !isset($data[$this->formToken])) {
            return false;
        }

        $index = $data[$this->formIndex];
        $token = $data[$this->formToken];

        if (!isset($tokens[$index])) {
            return false;
        }

        $stored = $tokens[$index];
        unset($tokens[$index]);

        $lockTo = $request->getUri()->getPath();

        if (!Utils\Helpers::hashEquals($lockTo, $stored['lockTo'])) {
            return false;
        }

        $expected = self::encode(hash_hmac('sha256', ClientIp::getIp($request), base64_decode($stored['token']), true));

        return Utils\Helpers::hashEquals($token, $expected);
    }
1108993
private function check_context($part)
    {
        return $this->context === null || strpos($part->mime_id, $this->context . '.') === 0;
    }
160429
protected function _blockLoad($tpl, array $vars = array()) {
        $vars && \extract($vars);
        include "{$this->_template_dir}/{$tpl}.phtml";

        $this->_display_html .= \ob_get_contents();
        \ob_clean();
    }
20633
protected function containsComplexThrowToken(array $tokens, int $scopeOpener, int $scopeCloser): bool
    {
        for ($i = $scopeOpener + 1; $i < $scopeCloser; $i++) {
            if ($tokens[$i]['code'] !== T_THROW) {
                continue;
            }

            if ($tokens[$i + 2]['code'] !== T_VARIABLE) {
                continue;
            }

            return true;
        }

        return false;
    }
1074762
protected function formatContext(array $vars, array $context)
    {
        // Set top-level data in the 'context', merging to get those keys in front
        $context = array_merge([
            'timestamp' => $this->stringify($vars['datetime']),
            'channel'   => $this->stringify($vars['channel']),
            'severity'  => $this->stringify($vars['level_name']),
            'level'     => $vars['level'],
            'message'   => $vars['message'],
        ], $context);

        return $this->stringify($context) . "\n";
    }
142999
protected static function rawblock(&$token, &$context) {
        $inner = $token[Token::POS_INNERTAG];
        trim($inner);

        // skip parse when inside raw block
        if ($context['rawblock'] && !(($token[Token::POS_BEGINRAW] === '{{') && ($token[Token::POS_OP] === '/') && ($context['rawblock'] === $inner))) {
            return true;
        }

        $token[Token::POS_INNERTAG] = $inner;

        // Handle raw block
        if ($token[Token::POS_BEGINRAW] === '{{') {
            if ($token[Token::POS_ENDRAW] !== '}}') {
                $context['error'][] = 'Bad token ' . Token::toString($token) . ' ! Do you mean ' . Token::toString($token, array(Token::POS_ENDRAW => '}}')) . ' ?';
            }
            if ($context['rawblock']) {
                Parser::setDelimiter($context);
                $context['rawblock'] = false;
            } else {
                if ($token[Token::POS_OP]) {
                    $context['error'][] = "Wrong raw block begin with " . Token::toString($token) . ' ! Remove "' . $token[Token::POS_OP] . '" to fix this issue.';
                }
                $context['rawblock'] = $token[Token::POS_INNERTAG];
                Parser::setDelimiter($context);
                $token[Token::POS_OP] = '#';
            }
            $token[Token::POS_ENDRAW] = '}}';
        }
    }
26660
protected static function builtin(&$context, $vars) {
        if ($context['flags']['nohbh']) {
            if (isset($vars[1][0])) {
                $context['error'][] = "Do not support {{#{$vars[0][0]} var}} because you compile with LightnCandy::FLAG_NOHBHELPERS flag";
            }
        } else {
            if (count($vars) < 2) {
                $context['error'][] = "No argument after {{#{$vars[0][0]}}} !";
            }
        }
        $context['usedFeature'][$vars[0][0]]++;
    }
690828
public static function getPartialBlock(&$vars) {
        if (isset($vars[static::PARTIALBLOCK])) {
            $id = $vars[static::PARTIALBLOCK];
            unset($vars[static::PARTIALBLOCK]);
            return $id;
        }
        return 0;
    }