Giter VIP home page Giter VIP logo

vnderror's Introduction

ramsey/vnderror

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

Ramsey\VndError is a PHP implementation of the vnd.error specification. This implementation currently targets the e88d5cd1ad revision of the specification.

From the vnd.error specification:

vnd.error is a simple way of expressing an error response in XML or JSON.

Often when returning a response to a client a response type is needed to represent a problem to the user (human or otherwise). A media type representation is a convenient way of expressing the error in a standardised format and can be understood by many client applications.

Examples

Use application/vnd.error+json or application/vnd.error+xml media types to communicate errors with HTTP 4xx and 5xx status codes.

use Ramsey\VndError\VndError;

$vndError = new VndError('Validation failed', 42);
$vndError->addLink('help', 'http://.../', array('title' => 'Error Information'));
$vndError->addLink('describes', 'http://.../', array('title' => 'Error Description'));

JSON output (application/vnd.error+json):

header('Content-Type: application/vnd.error+json');
echo $vndError->asJson();

Results in:

{
    "message": "Validation failed",
    "logref": 42,
    "_links": {
        "help": {
            "href": "http://.../",
            "title": "Error Information"
        },
        "describes": {
            "href": "http://.../",
            "title": "Error Description"
        }
    }
}

XML output (application/vnd.error+xml)

header('Content-Type: application/vnd.error+xml');
echo $vndError->asXml();

Results in:

<?xml version="1.0"?>
<resource logref="42">
    <link rel="help" href="http://.../" title="Error Information"/>
    <link rel="describes" href="http://.../" title="Error Description"/>
    <message>Validation failed</message>
</resource>

Installation

The preferred method of installation is via Composer:

php composer.phar require ramsey/vnderror

vnderror's People

Contributors

ramsey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vnderror's Issues

VndError::fromJson() fails

Missing argument 1 for Ramsey\VndError\VndError::__construct(), called in /home/jkleijn/Projects/php/kleijnweb/swagger-bundle/vendor/nocarrier/hal/src/Nocarrier/Hal.php on line 127 and defined

/home/jkleijn/Projects/php/kleijnweb/swagger-bundle/vendor/ramsey/vnderror/src/VndError.php:42
/home/jkleijn/Projects/php/kleijnweb/swagger-bundle/vendor/nocarrier/hal/src/Nocarrier/Hal.php:127
$ composer show --installed | grep -P '(hal|vnd)'
nocarrier/hal                     0.9.12  application/hal builder / formatter for PHP 5.3+
ramsey/vnderror                   3.0.0   application/vnd.error builder / formatter for PHP 5.3+

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.