Download the PHP package tembra/jsonapi-errors-php without Composer
On this page you can find all versions of the php package tembra/jsonapi-errors-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package jsonapi-errors-php
Description
This framework agnostic package implements a simple and efficient way to throw or respond errors in JSON API specification version v1.0 as described in JSON API Errors. It also helps creating documentation for these errors on your application. It is based on 3rd party package neomerx/json-api
that fully implements the JSON API Format.
It greatly simplifies the error processing with high code quality.
Still framework agnostic, you can easily integrate it with Laravel/Lumen and Dingo API.
Milestone to v1.0
- [x] Makes JSON API Errors as simple as calling a function
- [x] Standardize the errors
- [x] Provide most common error functions for HTTP Status Codes
- [x] Throw an exception or return the JSON string
- [x] Override JSON API Error Objects members
- [ ] Support for Localization
- [ ] Generate Documentation for Application Error Codes
- [ ] Build PHPUnit tests
Sample usage
Assuming you don't want a specific class to standardize the errors and also don't want the documentation or localization, you can use as simple as this:
will output as string
The first parameter is an associative array where key
is the error code
in JSON API compliant format and value
is another associative array where key/value
pairs are some others members that JSON API Error Objects may have.
The second parameter false
is to define whether a JsonApiException
should be thrown or only the JSON string should be returned.
For more advanced usage please check out the Wiki.
Questions?
Do not hesitate to contact me on [email protected] or post an issue.
License
BSD 3-Clause. Please see License File for more information.