Checks if token is an error and processes it.

@param Token $token
@return $this
@throws SyntaxException
@throws UnknownSyntaxException
424358
protected function assertErrorToken(Token $token)
    {
        if (!$token->isError()) {
            return $this;
        }
        switch ($token->getType()) {
            case Token::TYPE_ERROR_INVALID_ESCAPE:
                throw new SyntaxException(
                    "Invalid escape sequence at position #{$this->getNextPosition()}",
                    $this->getNextPosition()
                );

            default:
                throw new UnknownSyntaxException(
                    "Unknown type of error token: {$token->getType()} at position #{$this->getNextPosition()}",
                    $this->getNextPosition()
                );
        }
    }
497894
protected function verifyCsrfToken($token=null)
    {
        if ($this->options['csrfTokenEnabled']) {
            $token || $token = $this->request->getParam($this->options['csrfTokenName']);
            
            $data = static::getCsrfTokenData();
            
            $res = FormToken::instance()->verify($token, $data);
            
            if ($res['errcode']) {
                $this->stop()->errorInfo = $res;
            }
        }
        
        return $this->errorInfo;
    }
909259
public function invalidate(Token $token)
    {
        if (! $this->blacklistEnabled) {
            throw new JWTException('You must have the blacklist enabled to invalidate a token.');
        }

        return $this->blacklist->add($this->decode($token));
    }
1198479
private function _checkProhibitedTokens($token) {
		if ($this->_isActive('checkProhibitedTokens')) {
			if (in_array($token->getName(), $this->_prohibitedTokens)) {
				$msg = $this->_getMessage("PROHIBITED_TOKEN", $token->getName());
				$this->_writeError('checkProhibitedTokens', $msg);
			}
		}
	}
732776
private function parseArgument($token)
    {
        $c = \count($this->arguments);

        // if input is expecting another argument, add it
        if ($this->definition->hasArgument($c)) {
            $arg = $this->definition->getArgument($c);
            $this->arguments[$arg->getName()] = $arg->isArray() ? [$token] : $token;

        // if last argument isArray(), append token to last argument
        } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
            $arg = $this->definition->getArgument($c - 1);
            $this->arguments[$arg->getName()][] = $token;

        // unexpected argument
        } else {
            $all = $this->definition->getArguments();
            if (\count($all)) {
                throw new RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all))));
            }

            throw new RuntimeException(sprintf('No arguments expected, got "%s".', $token));
        }
    }
631479
public function validateToken($token)
    {
        if (isset($_SESSION[$this->session_name])) {
            if ($_SESSION[$this->session_name] === $token) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
540886
public function parse(Token $token)
    {
        $lineno = $token->getLine();

        $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
        $body = $this->parser->subparse(array($this, 'decideImresizeEnd'), true);
        $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

        return new ImresizeNode($body, $lineno, $this->getTag());
    }
619674
public function setToken($token)
    {
        $token = trim($token);

        $this->isChanged('token', $token);

        $this->token = $token;

        return $this;
    }
982558
protected function _verify($token)
    {
        if (empty($token)) {
            $this->_tokenError();
        }

        $subject = $this->_subject();
        $subject->set([
            'token' => $token,
            'repository' => $this->_table(),
            'query' => $this->_table()->find(
                $this->findMethod(),
                [
                    'token' => $token,
                    'conditions' => [$this->_table()->aliasField($this->config('tokenField')) => $token]
                ]
            ),
        ]);

        $this->_trigger('beforeFind', $subject);
        $entity = $subject->query->first();

        if (empty($token)) {
            $this->_tokenError();
        }

        $subject->set(['entity' => $entity]);
        $this->_trigger('afterFind', $subject);

        if (!isset($subject->verified)) {
            $subject->set(['verified' => false]);
        }
        $this->_trigger('verifyToken', $subject);

        if ($subject->verified) {
            return $subject->entity;
        }

        $this->_tokenError('tokenExpired');
    }
1052728
public function setToken($token)
    {
        $this->tokenKey = $token->key;
        $this->tokenSecret = $token->secret;

        return $this;
    }
1180878
public static function hasSyntax($token, $syntax = self::VAR_SYNTAX)
    {
        if (!\is_array($token)) {
            return false;
        }

        $regexp = \sprintf('#%s#', $syntax);

        return (bool) \preg_match($regexp, $token[1]);
    }
1234792
private function _checkProhibitedKeywords($token) {
		if ($this->_isActive('checkProhibitedKeywords')) {
			foreach ($this->_prohibitedKeywords as $keyword) {
				if (strpos($token->text, $keyword) !== FALSE) {
					$msg = $this->_getMessage('PROHIBITED_KEYWORD', $token->text);
					$this->_writeError('checkProhibitedKeywords', $msg);
				}
			}
		}
	}
425969
private function _processParenthesisOpen($token) {
		if ($this->_inFuncCall) {
			// inside a function call
			$this->_fcLeftParenthesis += 1;
		} elseif ($this->_inControlStatement || $this->_inFunctionStatement) {
			// inside a function or control statement
			$this->_csLeftParenthesis += 1;
		}

		// We are in a array declaration
		if ($this->_beforeArrayDeclaration) {
			$stackitem = new StatementItem();
			$stackitem->line = $token->line;
			$stackitem->type = 'ARRAY';
			$stackitem->name = 'ARRAY';
			$this->statementStack->push($stackitem);

			$this->_beforeArrayDeclaration = false;
		}

		$this->statementStack->getCurrentStackItem()->openParentheses += 1;
	}
852558
public function setToken($token, $tokenSecret)
    {
        $this->token = $token;
        $this->tokenSecret = $tokenSecret;

        return $this;
    }
831972
public function verify($token)
    {
        $user = new User();
        if ($token === 'NULL' || $user->isToken($token) !== true) {
            Error::set(__printl('auth:error:token'), 'token');
        }
        if ($this->fail() !== true) {
            if (!(new User())->isLogin()) {
                $id = $user->getByWhere('token', $token)[0]['id'];
                $email = $user->getByWhere('token', $token)[0]['email'];
                $update = new Update();
                $update->update(['token' => 'NULL'], $id);
                $subject = __printl('auth:subject:verified');
                $link = __config()->auth->verification_link.'/'.$token;
                $html = __printl('auth:body:verified');
                $html = str_replace(':email', $email, $html);
                $email = new EmailHandler($subject, $html, $email);
                Success::set(__config()->auth->success->verified);
            } else {
                Error::set(__printl('auth:error:already:login'), 'login');
            }
        }
    }
200964
public function parse(Token $token)
    {
        parent::parse($token);

        $values = preg_split('/->/', $token->getValue());
        if (2 !== count($values)) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }

        $fixture = $this->parser->parse($values[0]);
        $method = $this->parser->parse(sprintf('<%s>', $values[1]));

        try {
            return new FixtureMethodCallValue($fixture, $method);
        } catch (\TypeError $exception) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $exception);
        }
    }
671820
private function _processControlStatement($token) {
		$csText = strtolower($token->text);

		$this->_inControlStatement = true;
		$this->_currentStatement = $csText;

		// first token: if not one whitespace, error
		if ($this->_isActive('spaceAfterControlStmt')) {
			if (!$this->tokenizer->checkNextToken(T_WHITESPACE)) {
				if (($token->id !== T_ELSE) && ($token->id !== T_TRY) && ($token->id !== T_DO)) {
					$msg = $this->_getMessage('SPACE_AFTER_TOKEN', $csText);
					$this->_writeError('spaceAfterControlStmt', $msg);
				}
			}
		}

		// for some control structures like "else" and "do",
		// there is no statements they will be followed directly by "{"
		if (($token->id === T_ELSE) || ($token->id === T_DO) || ($token->id === T_TRY)) {
			if ($this->tokenizer->checkNextValidToken(T_BRACES_OPEN)) {
				$this->_inControlStatement = false;
				$this->_justAfterControlStmt = true;
			}
		}

		// "else if" is different
		if ($token->id === T_ELSE) {
			if ($this->tokenizer->checkNextValidToken(T_IF)) {
				// control statement for "else" is done
				// new control statement "if" will start
				$this->_inControlStatement = false;
			}

			// ELSE just after a IF with no curly : we close the IF statement
			if ($this->statementStack->getCurrentStackItem()->type === StatementItem::TYPE_IF && $this->statementStack->getCurrentStackItem()->noCurly === true) {
				$this->statementStack->pop();
			}
		}

		if ($token->id === T_IF) {
			// IF just after a ELSE with no curly : we close the ELSE statement
			if ($this->statementStack->getCurrentStackItem()->type === StatementItem::TYPE_ELSE && $this->statementStack->getCurrentStackItem()->noCurly === true) {
				$this->statementStack->pop();
			}
		}

		// "else" and "elseif" should start in the same line as "}"
		if ($token->id === T_ELSE || $token->id === T_ELSEIF) {
			$position = $this->_config->getTestProperty('controlStructElse', 'position');
			$previousToken = $this->tokenizer->peekPrvsValidToken();
			if ($previousToken->id === T_BRACES_CLOSE) {
				if (($position === SAME_LINE) && ($previousToken->line !== $token->line)) {
					$msg = $this->_getMessage('CS_STMT_ALIGNED_WITH_CURLY', $csText);
					$this->_writeError('controlStructElse', $msg);
				}
				if (($position === NEW_LINE) && ($previousToken->line === $token->line)) {
					$msg = $this->_getMessage('CS_STMT_ON_NEW_LINE', $csText);
					$this->_writeError('controlStructElse', $msg);
				}
			}
		}

		// The checkNeedBraces rule is usually launched after a closing parenthesis
		// In the case of the "else", we need to launch it now
		if ($token->id === T_ELSE) {
			$this->_checkNeedBraces();
		}

		// By default we consider that the statement block will start after the next '{'
		// In case there is no curly opening we need to consider the next line as being the statement
		if ($this->tokenizer->checkNextValidToken(T_PARENTHESIS_OPEN)) {
			// in case the statement type is IF, FOR, FOREACH, CATCH, WHILE we skip the conditional
			$startPos = $this->tokenizer->findClosingParenthesisPosition($token->position);
		} else {
			$startPos = $token->position;
		}

		// Now we expect the '{' token
		if (!$this->tokenizer->checkNextValidToken(T_BRACES_OPEN, null, $startPos + 1)) {

			// If not the case, we store the control statement in the stack
			$stackitem = new StatementItem();
			$stackitem->line = $token->line;
			$stackitem->type = strtoupper($csText);
			$stackitem->name = $csText;
			$stackitem->noCurly = true;
			$this->statementStack->push($stackitem);
		}

		// To avoid a false positive when treating the while statement of a do/while
		// We keep track that we have met a do statement
		if ($token->id === T_DO) {
			// Note : The current stack item is not yet the control statement itself, it's the parent
			$this->statementStack->getCurrentStackItem()->afterDoStatement = true;
		}
	}