snapshotpl/status-code

There is no license information available for the latest version (1.0.0) of this package.

HTTP status code value object implementation in PHP

1.0.0 2016-02-19 18:47 UTC

This package is auto-updated.

Last update: 2024-10-29 04:04:04 UTC


README

HTTP status code value object implementation in PHP.

Features

  • validation,
  • auto setup reason phrase (if known),
  • immutable,
  • support PSR-7 Psr\Http\Message\ResponseInterface.

Supported RFCs:

Supported drafts:

Installation

Add to composer:

{
    "require": {
        "snapshotpl/status-code": "^1.0"
    }
}

Usage

$statusCode = new StatusCode(404);

$statusCode->isClientError(); // true
$statusCode->isRfc2516() // true
$statusCode->isServerError(); // false

echo $statusCode; // 404 Not Found

You can use it with anny PSR-7 implementation:

$response = new Zend\Diactoros\Response();
$statusCode = StatusCode::createFromResponse($response);
echo $statusCode; // 200 OK
$response = new Zend\Diactoros\Response();
$statusCode = new StatusCode(404, 'Not exists');
$newResponse = $statusCode->attachToResponse($response);
echo $newResponse->getStatusCode(); // 404
echo $newResponse->getReasonPhrase(); // Not exists