PHP Classes

Nano Http Status: Process the HTTP request response status values

Recommend this page to a friend!
  Info   View files Documentation   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 189 This week: 1All time: 8,601 This week: 560Up
Version License PHP version Categories
php-nano-http-status 1.0.1MIT/X Consortium ...7.0HTTP, PHP 7
Description 

Author

This package can process the HTTP request response status values.

It can check the HTTP request values and process them to make it easier to interpret.

The class can check the actual status value and tell if the request was sucessful, or needs redirection, or there was a forbidden access, or there was a general server error.

Innovation Award
PHP Programming Innovation award nominee
January 2018
Number 5
This package can process the HTTP request response status values.

It can check the HTTP request values and process them to make it easier to interpret.

The class can check the actual status value and tell if the request was sucessful, or needs redirection, or there was a forbidden access, or there was a general server error.

Manuel Lemos
Picture of Sergey Karavay
  Performance   Level  
Name: Sergey Karavay <contact>
Classes: 3 packages by
Country: Belarus Belarus
Age: 33
All time rank: 331911 in Belarus Belarus
Week rank: 411 Up2 in Belarus Belarus Up
Innovation award
Innovation award
Nominee: 1x

Documentation

PHP Nano Http Status

Latest Stable Version Build Status Maintainability Test Coverage Scrutinizer Code Quality License composer.lock Total Downloads

Truly minimalistic and self-contained package to handle HTTP statuses and relevant description messages. Such packages as Teapot or Httpstatus are nice and famous, but still either too heavy and over-complicated or simply does not fit to Gino Pane's high code quality standards.

Requirements

  • PHP >= 7.0;

Features

  • The full list of HTTP status codes as readable constants;
  • relevant status messages;
  • ability to customize messages;
  • ability to easily detect the class of the status;
  • no dependencies in production;
  • integrated tools for code quality, testing and building docs.

Installation

composer require gino-pane/nano-http-status

Basic Usage

Check existence of the code (using numeric codes or nice readable constants):

(new NanoHttpStatus())->statusExists(200); //true
(new NanoHttpStatus())->statusExists(400); //true
(new NanoHttpStatus())->statusExists(451); //true
(new NanoHttpStatus())->statusExists(511); //true
(new NanoHttpStatus())->statusExists(522); //false

Detect the class of the code using code numbers:

(new NanoHttpStatus())->isInformational(NanoHttpStatus::HTTP_OK); //false
(new NanoHttpStatus())->isSuccess(202);         //true
(new NanoHttpStatus())->isRedirection(301);     //true
(new NanoHttpStatus())->isClientError(404);     //true
(new NanoHttpStatus())->isServerError(NanoHttpStatus::HTTP_BAD_REQUEST); //false

Get status message by status code:

(new NanoHttpStatus())->getMessage(200); //OK
(new NanoHttpStatus())->getMessage(451); //Unavailable For Legal Reasons
(new NanoHttpStatus())->getMessage(452); //Undefined Status

Set localization mapping and get custom status messages:

$status = new NanoHttpStatus([
    NanoHttpStatus::HTTP_BAD_REQUEST => 'Very bad request',
    NanoHttpStatus::HTTP_BAD_GATEWAY => 'Not so bad gateway'
]);

$status->getMessage(400); //'Very bad request'
$status->getMessage(502); //'Not so bad gateway'

Please note, that `NanoHttpStatus` itself does not throw any exceptions for invalid statuses.

Useful Tools

Running Tests:

php vendor/bin/phpunit

or

composer test

Code Sniffer Tool:

php vendor/bin/phpcs --standard=PSR2 src/

or

composer psr2check

Code Auto-fixer:

php vendor/bin/phpcbf --standard=PSR2 src/ 

or

composer psr2autofix

Building Docs:

php vendor/bin/phpdoc -d "src" -t "docs"

or

composer docs

Changelog

To keep track, please refer to CHANGELOG.md.

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Make your changes.
  4. Run the tests, adding new ones for your own code if necessary (phpunit).
  5. Commit your changes (git commit -am 'Added some feature').
  6. Push to the branch (git push origin my-new-feature).
  7. Create new pull request.

Also please refer to CONTRIBUTION.md.

License

Please refer to LICENSE.

Notes

Powered by composer-package-template


  Files folder image Files  
File Role Description
Files folder imagesrc (2 files)
Files folder imagetests (1 file, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file CONTRIBUTION.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file NanoHttpStatus.php Class Class source
  Plain text file NanoHttpStatusInterface.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagesuites (1 directory)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  suites  
File Role Description
Files folder imagemain (1 file)

  Files folder image Files  /  tests  /  suites  /  main  
File Role Description
  Plain text file NanoHttpStatusTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:189
This week:1
All time:8,601
This week:560Up