m6web/fos-rest-extra-bundle

There is no license information available for the latest version (v4.0.0) of this package.

Extra feature for the FOSRestBundle

Installs: 152 125

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 48

Forks: 3

Open Issues: 5

Type:symfony-bundle

v4.0.0 2022-07-21 12:19 UTC

This package is auto-updated.

Last update: 2024-03-21 16:02:23 UTC


README

Provide extra feature for the FOSRestBundle.

Dependency

FOSRestExtraBundle requires FOSRestBundle.

Installation

Add this line in your composer.json:

{
    "require": {
        "m6web/fos-rest-extra-bundle": "~1.0"
    }
}

Update your vendors:

$ composer update m6web/fos-rest-extra-bundle

Add to your AppKernel.php:

new FOS\RestBundle\FOSRestBundle(),
new M6Web\Bundle\FOSRestExtraBundle\M6WebFOSRestExtraBundle(),

Then modify the FOSRestBundle configuration of your application to add :

fost_rest:
    param_fetcher_listener: true

Configuration

m6_web_fos_rest_extra:
    param_fetcher:

        # Define if extra parameters are allowed. The behavior defined here is the default one and can
        # be overrided by a "RestrictExtraParam" annotation on the current action.
        # Optionnal, true by default
        allow_extra: true

        # Define if all parameters are strict. If true, all given parameters have to match defined
        # format for each on of them.
        # Optionnal, false by default
        strict: false

        # HTTP status code of throwed exception on query with invalid parameters
        # Optionnal, 400 by default
        error_status_code: 400

Usage

  • RestrictExtraParam(true/false) Annotation : to allow (false) or forbid (true) unknown parameters, true by default.
use FOS\RestBundle\Controller\Annotations\QueryParam;
use M6Web\Bundle\FOSRestExtraBundle\Annotation\RestrictExtraParam;

/**
 * TestController
 */
class TestController
{
    /**
     * Restricted controller : only "param1" is permitted
     *
     * @return void
     *
     * @RestrictExtraParam(true)
     *
     * @QueryParam(name="param1", requirements="\d+", nullable=true, description="My Param 1")
     */
    public function getRestrictedAction() {

    }

    /**
     * Unrestricted controller : "param1" and unknown parameters are permitted
     * except if bundle configuration doesn't allow it
     *
     * @QueryParam(name="param1", requirements="\d+", nullable=true, description="My Param 1")
     *
     * @return void
     */
    public function getNonRestrictedAction() {

    }
}

Launch Tests

$ bin/atoum