2017 © Pedro Peláez
 

symfony-bundle doze-bundle

An easy to use library for building REST APIs in Symfony

image

dbstudios/doze-bundle

An easy to use library for building REST APIs in Symfony

  • Thursday, July 12, 2018
  • by LartTyler
  • Repository
  • 0 Watchers
  • 0 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 13 % Grown

The README.md

Installation

$ composer require dbstudios/doze-bundle

Configuration

Add the following to app/AppKernel.php:, (*1)

<?php
    // app/AppKernel.php

    // ...
    class AppKernel extends Kernel {
        public function registerBundles() {
            // ...

            $bundles = [
                // ...
                new DaybreakStudios\DozeBundle\DaybreakStudiosDozeBundle(),
            ];

            // ...

            return $bundles;
        }

        // ...
    }

You will also need to add a service definition for the responder in your bundle's services.yml:, (*2)

services:
    app.doze.responder:
        class: DaybreakStudios\DozeBundle\ResponderService
        arguments:
            - '@app.serializer'
            - '@request_stack'

    app.serializer:
        class: Symfony\Component\Serializer\Serializer
        arguments:
            -
                - '@app.serializer.normalizer.datetime'
                - '@app.serializer.normalizer.collection'
                - '@app.serializer.normalizer.entity'
                - '@app.serializer.normalizer.object'
            -
                - '@app.serializer.encoder.json'

    app.serializer.normalizer.datetime:
        class: Symfony\Component\Serializer\Normalizer\DateTimeNormalizer

    # This normalizer is only necessary if you plan on normalizing
    # Doctrine collections to paged collections.
    # @see https://github.com/LartTyler/Doze#paged-collections
    app.serializer.normalizer.collection:
        class: DaybreakStudios\Doze\Serializer\PagedCollectionNormalizer
        arguments:
            - 25

    # This normalizer is only necessary if you plan on normalizing database entities.
    # @see https://github.com/LartTyler/Doze#serializing-database-objects
    app.serializer.normalizer.entity:
        class: DaybreakStudios\Doze\Serializer\EntityNormalizer

    app.serializer.normalizer.object:
        class: Symfony\Component\Serializer\Normalizer\ObjectNormalizer

    app.serializer.encoder.json:
        class: Symfony\Component\Serializer\Encoder\JsonEncoder

Optionally, you may also add any or all of the following parameters to your application if you need to modify the default behavior of Doze., (*3)

// app/config/parameters.yml

parameters:
    # Whether or not to use the built-in CORS listener. If disabled, Doze will not be able to respond to
    # CORS requests unless you add the necessary CORS headers yourself.
    dbstudios.cors_listener.enabled: true

    # An array of origins that are allowed to send CORS requests.
    # If the only value in this array is an asterisk, all origins will be allowed.
    dbstudios.cors_listener.allowed_origins:
        - '*'

    # An array of headers that are allowed in CORS requests.
    # An asterisk denotes all headers are allowed.
    dbstudios.cors_listener.allowed_headers:
        - '*'

    # An array of methods that are allowed in CORS requests.
    # An asterisk denotes all methods are allowed.
    dbstudios.cors_listener.allowed_methods:
        - '*'

    # A boolean indicating whether or not credentials are allowed in CORS requests.
    dbstudios.cors_listener.allow_credentials: true

All of the parameters listed above show their default values. You will only need to include a parameter if you need to change it from what's shown above., (*4)

Usage

In the example below, the responder will be used to serialize data coming from Doctrine in a controller action. However, Doze can be used to serialize any kind of data, and may be used anywhere that you have access to the service container, or via dependency injection., (*5)

<?php
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use DaybreakStudios\DozeBundle\ResponderService;

    class MyController extends Controller {
        public function indexAction(ResponderService $responder, $id) {
            $entity = $this->getDoctrine()->getRepository('AppBundle:MyEntity')->find($id);

            if ($entity === null)
                return $responder->createNotFoundResponse();

            return $responder->createResponse($entity);
        }
    }

The Versions

12/07 2018

dev-master

9999999-dev

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

12/07 2018

1.6.0

1.6.0.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

05/07 2018

1.5.0

1.5.0.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

20/12 2017

1.4.0

1.4.0.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

03/10 2017

1.3.0

1.3.0.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

08/06 2017

1.2.1

1.2.1.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

07/06 2017

1.2.0

1.2.0.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

07/06 2017

1.1.1

1.1.1.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

05/06 2017

1.1.0

1.1.0.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

05/06 2017

1.0.0

1.0.0.0

An easy to use library for building REST APIs in Symfony

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires