Get or set status code and return last status code

@param int  $code
@param bool $trigger
@return int|bool
767800
public static function status($code = null, $trigger = true)
    {
        if (self::$httpCode === null) {
            self::$httpCode = \UtilsStatusCode();
        }

        if ($code === null || self::$httpCode === $code) {
            return self::$httpCode;
        } elseif (headers_sent() || $code < 100 || $code > 599) {
            return false;
        }

        header('X-PHP-Response-Code: ' . $code, true, $code);

        $lastCode = self::$httpCode;
        self::$httpCode = $code;

        if ($trigger) {
            App::trigger('changestatus', array($code, null));
        }

        return $lastCode;
    }
235356
public function check($code) {
        $code = trim($code);
        // last token should be ;
        if(substr($code, -1) != ';') {
            $this->error = ['line' => (substr_count($code, "\n") + 1), 'prev' => ']', 'token' => ';', 'must' => true];
            return false;
        }
        // exclude last token
        $code = substr($code, 0, -1);
        // get all tokens
        $tokens = token_get_all($code);
        $prev = false;
        $this->error['line'] = false;
        foreach($tokens as $token) {
            if(is_array($token)) {
                $tn = token_name($token['0']);
                if(in_array($tn, ['T_WHITESPACE', 'T_COMMENT']))
                    continue;
                $this->error = ['line' => $token[2], 'prev' => $prev, 'token' => $tn];
                if(!in_array($tn, self::$valid_tokens))
                    return false;
                elseif($tn == 'T_STRING' && !in_array(strtolower($token[1]), ['true', 'false']))
                    return false;
                if($this->validSequence($prev, $tn))
                   $prev = $tn;
                else
                    return false; 
            } else {
                // line will be defined in any case, so no needed to define it here 
                $this->error['prev'] = $prev;
                $this->error['token'] = $token;
                if(in_array($token, self::$valid_symbols) && $this->validSequence($prev, $token))
                    $prev = $token;
                else
                    return false;
            }
        }
        // chek pairs of $braces
        $braces = 0;
        $inString = 0;
        $this->error['line'] = 0;
        foreach($tokens as $token) {
            if($inString & 1) {
                switch ($token) {
                    case '`':
                    case '"': --$inString; break;
                }
            } else {
                switch ($token) {
                    case '`':
                    case '"': ++$inString; break;
     
                    case '[': case '(': ++$braces; break;
                    case ']': case ')':
                        if ($inString) {
                            --$inString;
                        }
                        else {
                            --$braces;
                            if ($braces < 0) {
                                return false;
                            }
                        }
                    break;
                }
            }
        }
        if ($braces) {
            return false;
        }
        return true;
    }
1041938
public static function get( $code = 200 )
	{
		if( isset( self::$http_status_codes[$code] ) )
		{
			return( self::$http_status_codes[ $code ] );
		}
		return( false );
	}
1299647
protected function getCodeResponse($statusCode)
    {
        $this->checkParameters();

        /** @var ResponsesInterface $responses */
        $responses = $this->getIntegration()->getFromContainer(ResponsesInterface::class);
        $outputMediaType = $this->codecMatcher->getEncoderRegisteredMatchedType();

        return $responses->getResponse($statusCode, $outputMediaType, null, $this->supportedExtensions);
    }
59535
public function sendHttpCode($code = null)
    {
        if (func_num_args() == 0) {
            return $this->sendHttpCode;
        }

        if (!$code) {
            return $this->sendHttpCode = false;
        }

        if ($code === true) {
            $code = 500;
        }

        if ($code < 400 || 600 <= $code) {
            throw new InvalidArgumentException(
                 "Invalid status code '$code', must be 4xx or 5xx"
            );
        }

        return $this->sendHttpCode = $code;
    }
726375
public function getStatusText($code = null)
    {
        if ($code === null) {
            return $this->_context->status_text;
        } else {
            $texts = [
                200 => 'OK',
                201 => 'Created',
                202 => 'Accepted',
                203 => 'Non-Authoritative Information',
                204 => 'No Content',
                205 => 'Reset Content',
                206 => 'Partial Content',
                207 => 'Multi-Status',
                208 => 'Already Reported',
                301 => 'Moved Permanently',
                302 => 'Found',
                303 => 'See Other',
                304 => 'Not Modified',
                305 => 'Use Proxy',
                307 => 'Temporary Redirect',
                308 => 'Permanent Redirect',
                400 => 'Bad Request',
                401 => 'Unauthorized',
                402 => 'Payment Required',
                403 => 'Forbidden',
                404 => 'Not Found',
                405 => 'Method Not Allowed',
                406 => 'Not Acceptable',
                407 => 'Proxy Authentication Required',
                408 => 'Request Time-out',
                409 => 'Conflict',
                410 => 'Gone',
                411 => 'Length Required',
                412 => 'Precondition Failed',
                413 => 'Request Entity Too Large',
                414 => 'Request-URI Too Long',
                415 => 'Unsupported Media Type',
                416 => 'Requested range unsatisfiable',
                417 => 'Expectation failed',
                418 => 'I\'m a teapot',
                421 => 'Misdirected Request',
                422 => 'Unprocessable entity',
                423 => 'Locked',
                424 => 'Method failure',
                425 => 'Unordered Collection',
                426 => 'Upgrade Required',
                428 => 'Precondition Required',
                429 => 'Too Many Requests',
                431 => 'Request Header Fields Too Large',
                449 => 'Retry With',
                450 => 'Blocked by Windows Parental Controls',
                500 => 'Internal Server Error',
                501 => 'Not Implemented',
                502 => 'Bad Gateway or Proxy Error',
                503 => 'Service Unavailable',
                504 => 'Gateway Time-out',
                505 => 'HTTP Version not supported',
                507 => 'Insufficient storage',
                508 => 'Loop Detected',
                509 => 'Bandwidth Limit Exceeded',
                510 => 'Not Extended',
                511 => 'Network Authentication Required',
            ];

            return isset($texts[$code]) ? $texts[$code] : 'App Error';
        }
    }
921826
public function getStatus($includeStatusCode = false)
    {
        if (!isset($this->data->status))
            return null;
        return ($includeStatusCode) ? sprintf("%s: %s", $this->data->status, $this->data->statusCode) : $this->data->status;
    }
418967
public function getStatus($code) {

        $filename = __DIR__.'/../../data/'.substr($code, 0,1).'.json';
        if(file_exists($filename)) {
            return json_decode(file_get_contents($filename), true)[$code];
        }
        return [];
    }
985060
public function setStatus(int $code): Response
    {
        # `Status::getText` will throw an exception for invalid status codes
        $this->statusText = Status::getText($code);
        $this->statusCode = $code;
        return $this;
    }
1091019
public function setStatusCode(int $statusCode, string $statusText = null)
    {
        $this->statusCode = $statusCode;

        if ($statusText === null && isset(ResponseHeaders::$statusTexts[$statusCode])) {
            $this->statusText = ResponseHeaders::$statusTexts[$statusCode];
        } else {
            $this->statusText = $statusText;
        }
    }
789551
private function getHttpStatusCode($statusCode)
    {
        if ($statusCode >= 100 && $statusCode < 600) {
            return $statusCode;
        } elseif (
                FrontControllerException::BAD_REQUEST === $statusCode
                || FrontControllerException::INTERNAL_ERROR === $statusCode
                || FrontControllerException::NOT_FOUND === $statusCode
        ) {
            return $statusCode - FrontControllerException::UNKNOWN_ERROR;
        }

        return 500;
    }
11439
public function setCode( $code = null)
	{
		// Require that the response be unlocked before changing it
		$this->requireUnlocked();
		$this->status = new Status($code);
		return $this;
	}
339156
public function withStatus($code, $reasonPhrase = '')
    {
        $this->statusCode = (int)$code;
        if ($reasonPhrase == '') {
            $this->reasonPhrase = Status::getReasonPhrase($this->statusCode);
        } else {
            $this->reasonPhrase = $reasonPhrase;
        }

        return $this;
    }
258930
public static function getReason($code, $default = null)
    {
        $code = (int) $code;
        
        if (array_key_exists($code, static::$webDavStatusMessages)) {
            return static::$webDavStatusMessages[$code];
        }
        
        return parent::getReason($code, $default);
    }
563481
public function getAuthorizationCode($code)
    {
        $result = $this->client->getItem(array(
            "TableName"=> $this->config['code_table'],
            "Key" => array('authorization_code'   => array('S' => $code))
        ));
        if ($result->count()==0) {
            return false ;
        }
        $token = $this->dynamo2array($result);
        if (!array_key_exists("id_token", $token )) {
            $token['id_token'] = null;
        }
        $token['expires'] = strtotime($token['expires']);

        return $token;

    }
131021
public function getAuthorizationCode($code)
    {
        $sql  = sprintf('SELECT * from %s where authorization_code = :code', $this->config['code_table']);
        $code = $this->fetch($sql, compact('code'));
        if ($code) {
            // convert date string back to timestamp
            $code['expires'] = strtotime($code['expires']);
        }

        return $code;
    }
630528
protected function _setStatus($code, $reasonPhrase = '')
    {
        if (!isset($this->_statusCodes[$code])) {
            throw new InvalidArgumentException(sprintf(
                'Invalid status code: %s. Use a valid HTTP status code in range 1xx - 5xx.',
                $code
            ));
        }

        $this->_status = $code;
        if (empty($reasonPhrase)) {
            $reasonPhrase = $this->_statusCodes[$code];
        }
        $this->_reasonPhrase = $reasonPhrase;
        $this->_setContentType();
    }