@param array  $token
@param string $content

@return Context|null
@throws TokenException
486244
public function enterToken(array $token, $content)
    {
        switch ($token[Lexer::TYPE]) {
            case Lexer::T_ARRAY_CLOSE:
                return $this->parent;

            case Lexer::T_ARRAY_ARROW:
                $this->currentKey = array_pop($this->values);

                if (!is_scalar($this->currentKey)) {
                    throw new TokenException('array key must be scalar', $token);
                }
                break;

            case Lexer::T_QUOTED_STRING:
            case Lexer::T_NUMBER:
            case Lexer::T_TRUE:
            case Lexer::T_FALSE:
            case Lexer::T_NULL:
                $value = $this->getValueOfToken($token);
                $this->addValue($value);
                break;

            case Lexer::T_ARRAY_OPEN:
                $array = new ArrayContext($token, $this);
                $this->addValue($array);

                return $array;
                break;

            case Lexer::T_FUNC_OPEN:
                $func = new FuncContext($token, $this);
                $this->addValue($func);

                return $func;

            case Lexer::T_COMMA:
                if ($this->currentKey !== null) {
                    return null;
                }
                break;

            default:
                return null;
        }

        return $this;
    }
755869
public function parseLogBody($content)
    {
        $pattern      = "/^".self::STACK_TRACE_DIVIDER_PATTERN."/m";
        $parts        = array_map('ltrim', preg_split($pattern, $content));
        $context      = $parts[0];
        $stack_traces = (isset($parts[1])) ? $parts[1] : null;

        return compact('context', 'stack_traces');
    }
639330
public function replaceTokens($text, $tokens = [])
    {
        // Obtain Token Mappings:
        
        $mappings = $this->getTokenMappings();
        
        // Iterate Token Mappings:
        
        foreach ($mappings as $name => $spec) {
            
            // Ignore Custom Mappings:
            
            if (isset($spec['custom']) && $spec['custom']) {
                continue;
            }
            
            // Check Property Defined:
                
            if (!isset($spec['property'])) {
                throw new Exception(sprintf('Property is undefined for token mapping "%s"', $name));
            }
            
            // Obtain Value for Token:
            
            $value = isset($tokens[$name]) ? $tokens[$name] : $this->getPropertyValue($spec['property']);
            
            // Perform Token Replacement:
            
            $text = str_ireplace("{{$name}}", $value, $text);
            
        }
        
        // Answer Processed Text:
        
        return $text;
    }
172926
public static function orderBy(array $tokens, array $content) {
        if (empty($tokens['ORDER'])) return $content;

        $sortingRules = array_map(function($token) use ($content) {
            return [
                end($token['no_quotes']['parts']),
                $token['direction']
            ];
        }, $tokens['ORDER']);

        $reducedSortingRules = array_reduce($sortingRules, 'array_merge', []);
        $sortArgs            = array_map(function($value) use ($content) {
            if ($value === 'ASC')  return SORT_ASC;
            if ($value === 'DESC') return SORT_DESC;

            $contents = [];
            foreach ($content as $c) array_push($contents, $c[$value]);
            return $contents;
        }, $reducedSortingRules);

        $sortArgs[] = &$content;
        call_user_func_array('array_multisort', $sortArgs);

        return end($sortArgs);
    }
622230
public function setHtmlContent(string $content) : Tag
    {
        if ($this->isVoid) {
            throw new \LogicException('Void elements cannot have any contents.');
        }

        $this->content = $content;

        return $this;
    }
1292942
protected function handleUnmatchedState($content, $position, TokenList $tokenList) {
        if (empty($content)) {
            return;
        }

        $lastToken = $tokenList->last();
        if ($lastToken !== null && $lastToken->getName() === $this->name) {
            $lastToken->set('content', $lastToken->get('content', '') . $content);
        } else {
            $tokenList->addToken($this->name, $position)
                ->set('content', $content);
        }
    }
1002146
protected function handleEntryState($content, $position, TokenList $tokenList) {
        $lang = trim($content, " `\t\n\r\0\x0B");
        $tokenList->addToken($this->name . self::OPEN, $position)
            ->set('lang', $lang);
    }
1321867
public function setJsonContent($content)
    {
        $context = $this->_context;

        $this->setHeader('Content-Type', 'application/json; charset=utf-8');

        if (is_array($content)) {
            if (!isset($content['code'])) {
                $content = ['code' => 0, 'message' => '', 'data' => $content];
            }
        } elseif ($content instanceof \JsonSerializable) {
            $content = ['code' => 0, 'message' => '', 'data' => $content];
        } elseif (is_string($content)) {
            null;
        } elseif (is_int($content)) {
            $content = ['code' => $content, 'message' => ''];
        } elseif ($content === null) {
            $content = ['code' => 0, 'message' => '', 'data' => null];
        } elseif ($content instanceof ValidatorException) {
            $content = ['code' => -2, 'message' => $content->getMessage()];
        } elseif ($content instanceof \Exception) {
            if ($content instanceof \ManaPHP\Exception) {
                $this->setStatus($content->getStatusCode());
                $content = $content->getJson();
            } else {
                $this->setStatus(500);
                $content = ['code' => 500, 'message' => 'Server Internal Error'];
            }
        }

        $context->content = $this->_jsonEncode($content);

        return $this;
    }
159501
public static function create(array $tokens, array $content) {
        $content = self::orderBy($tokens, $content);

        return array_map(function($entry) use ($tokens) {
            $row = SelectSingleResult::create($tokens, $entry);
            return array_pop($row);
        }, $content);
    }
36152
public function parseToken($content, $position, $state, TokenList $tokenList) {
        if (!empty($content)) {
            $tokenList->addToken($this->name, $position)
                ->set('content', $content);
        }
    }
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] = '}}';
        }
    }
527966
public function sign(string $content, string $aud, ?string $kid = null): PbjxToken
    {
        $kid = $kid ?: $this->defaultKid;
        return PbjxToken::create($content, $aud, $kid, $this->getSecret($kid));
    }
890019
private function execute($content)
	{
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $this->url);
		curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Token '.$this->token, 'Content-Type: application/json', 'Accept: application/json']);
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode((object) $content));

		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		$result = curl_exec($ch);

		if(!$result)
			return curl_error( $ch );

		return $result;

	}
1047549
protected function _setToken($token)
    {
        if ($token !== null && !($token instanceof TokenInterface)) {
            throw $this->_createInvalidArgumentException($this->__('Invalid token'), null, null, $token);
        }

        $this->token = $token;
    }
731593
public static function detectByContent($content)
    {
        if ( ! class_exists('finfo') || ! is_string($content)) {
            return null;
        }
        try {
            $finfo = new finfo(FILEINFO_MIME_TYPE);

            return $finfo->buffer($content) ?: null;
        // @codeCoverageIgnoreStart
        } catch( ErrorException $e ) {
            // This is caused by an array to string conversion error.
        }
    }
1009725
public function writeContent(array $content)
    {
        if (!$this->canWrite()) {
            throw new Exception("Unable to write file {this->file}.");
        }
        
        $json = $this->jsonEncode($content);
        
        return $this->writeFileContent($this->file, $json);
    }
42727
public function setContent($content)
    {
        $this->content = null;
        if ($content === null) {
            return;
        }

        if (TypeHandling::isSimpleType(gettype($content)) && !is_array($content)) {
            $this->content = (string)$content;
        }

        if (is_resource($content)) {
            $this->content = $content;
        }

        return $this;
    }