Download the PHP package shrikeh/teapot without Composer
On this page you can find all versions of the php package shrikeh/teapot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shrikeh/teapot
More information about shrikeh/teapot
Files in shrikeh/teapot
Package teapot
Short Description PHP HTTP Response Status library
License MIT
Homepage https://shrikeh.github.io/teapot/
Informations about the package teapot
Teapot
This is a very simple library that aims to aid verbosity in any Web-based application by defining clearly the HTTP 1.1 response codes as constants. It includes two main components: an interface, which contains the constants, and an exception specifically for HTTP.
Usage
Using the StatusCodes interface
Assuming for a moment a PHPUnit test on a cURL client response:
This becomes:
While this is a trivial example, the additional verbosity of the code is clearer with other HTTP status codes:
As StatusCode
is an interface without any methods, you can directly implement it if you prefer:
This may be beneficial in an abstract class, so that child classes don't need to explicitly use the interface.
There are various "helper" interfaces within the library, such as WebDAV and Http. Additionally, the various status codes are split into the RFCs that defined them: the Http helper interface extends RFCs 2616, 2324, and 2774, for example. This allows you very granular control of what status codes you want to allow within your application.
All constants have doc blocks that use the official W3C and IETF draft specification descriptions of the status code, to aid IDEs and for reference.
Using the HttpException
The HttpException
is very straightforward. It simply is a named exception to aid verbosity:
The exception itself uses the StatusCode
interface, allowing you to avoid manually and explicitly importing it if you prefer:
Installation
Run the following command.
Coding Standards
The entire library is intended to be PSR-1, PSR-2 and PSR-4 compliant.
Get in touch
If you have any suggestions, feel free to email me at [email protected] or ping me on Twitter with @shrikeh.