jnjxp/http-status

HTTP Status Helpers

0.1.0 2016-10-23 17:12 UTC

This package is auto-updated.

Last update: 2024-12-26 09:25:43 UTC


README

HTTP Status Code Helpers

Latest version Build Status Coverage Status Quality Score

Install

composer require jnjxp/http-status

Usage

HTTP Status Constants

<?php

use Jnjxp\HttpStatus\StatusCode;

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

Determine HTTP Response Status Class

<?php

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);