PHP code example of jnjxp / http-status

1. Go to this page and download the library: Download jnjxp/http-status library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jnjxp / http-status example snippets




use Jnjxp\HttpStatus\StatusCode;

// Class Constants for HTTP Status Magic Numbers in `StatusCode`
// eg...
$response = $response->withStatus(StatusCode::HTTP_OK);



use Jnjxp\HttpStatus\ResponseClass;

$responseClass = new ResponseClass;

Switch ($responseClass->getClass($response)){
// one of: 'INFORMATIONAL', 'SUCCESS', 'REDIRECTION', 'CLIENT_ERROR', 'SERVER_ERROR'
// Cooresponding class constants on `ResponseClass`

    case ResponseClass::INFORMATIONAL:
        // Response is 1xx
    break;

    case ResponseClass::SUCCESS:
        // Response is 2xx
    break;

    case ResponseClass::REDIRECTION:
        // Response is 3xx
    break;

    case ResponseClass::CLIENT_ERROR:
        // Response is 4xx
    break;

    case ResponseClass::SERVER_ERROR:
        // Response is 5xx
    break;
}

// Boolean tests available

$responseClass->isResponse(ResponseClass::SUCCESS, $resposne);

$responseClass->isInformational($response);
$responseClass->isSuccess($response);
$responseClass->isRedirection($response);
$responseClass->isClientError($response);
$responseClass->isServerError($response);