Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rest Problem Bundle Laravel Package

alterway/rest-problem-bundle

View on GitHub
Deep Wiki
Context7

# RestProblemBundle

Bundle to manage Problems in API with Symfony2.

Build Status

This bundle follows the Problem Details for HTTP APIs recommandation.

## Installation

Edit your composer.json:

"require": {
    "alterway/rest-problem-bundle" : "master"
}

And run Composer:

php composer.phar update alterway/rest-problem-bundle

Enable your bundle in your AppKernel.php:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Alterway\Bundle\RestProblemBundle\AwRestProblemBundle(),
    );
}

Usage

use Alterway\Bundle\RestProblemBundle\Response\ProblemResponse;
use Alterway\Bundle\RestProblemBundle\Problem;

public function demoAction(Request $request)
{

    $form = // (...)

    $form->bind($request);
    if (!$form->isValid()) {
        $problem = new Problem\InvalidQueryForm($form);
        return new ProblemResponse($problem, 403);
    }
}

## Usage with annotations

Remember to enable annotations :

sensio_framework_extra:
router:  { annotations: true }
request: { converters: true }
view:    { annotations: true }
cache:   { annotations: true }

And to register the autoloader in your app/autoload.php file:

Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass')); 

This will send an application/api-problem+json header:

use Alterway\Bundle\RestProblemBundle\Response\ProblemResponse;
use Alterway\Bundle\RestProblemBundle\Controller\Annotations\Problem;

/**
* @Problem
*/
public function demoAction(Request $request)
{

    $form = // (...)

    $form->bind($request);
    if (!$form->isValid()) {
        return new Problem\InvalidQueryForm($form);
    }
}

Problem's types

You need to create your own problem types. There are by default the following problems:

  • Problem\InvalidQuery
  • Problem\InvalidQueryForm
  • ...

Todo

Add controllers and route to provide problemType

## Contribute

Install dev dependencies:

php composer.phar update --dev

Run Behat:

./vendor/bin/behat @AwRestProblemBundle

Copyright

Copyright (c) 2013 La Ruche Qui Dit Oui!. See LICENSE for details.

Contributors

  • Lead: Jean-François Lépine (Halleck45)
  • Developer: Antoine Lévêque (gh0stonio)

Sponsors

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware