2017 © Pedro Peláez
 

symfony-bundle restfony-bundle

Symfony3 bundle to implement REST crud

image

pgs-soft/restfony-bundle

Symfony3 bundle to implement REST crud

  • Saturday, August 27, 2016
  • by kubawerlos
  • Repository
  • 5 Watchers
  • 6 Stars
  • 3,026 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 4 Open issues
  • 3 Versions
  • 9 % Grown

The README.md

PGS Software / Restfony Bundle

Latest Stable Version Minimum PHP Version License Build Status Code Coverage Scrutinizer Code Quality, (*1)

Bundle to assist with creating classes for Doctrine Entity with aim to speed up creating RESTful APIs., (*2)

Installation

Require the bundle with composer:, (*3)

    composer require pgs-soft/restfony-bundle

Enable the bundle (with dependent bundles) in the kernel:, (*4)

    <?php
    // app/AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Pgs\RestfonyBundle\PgsRestfonyBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
            new Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle(),
            new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
            new Lexik\Bundle\FormFilterBundle\LexikFormFilterBundle(),
            // ...
        );
    }

Prepare config for Restfony and FOSRestBundle:, (*5)

    # app/config/rest.yml

    jms_serializer:
        handlers:
            datetime:
                default_format: 'Y-m-d\TH:i:sP'
        property_naming:
            separator: null
            lower_case: false
    fos_rest:
        param_fetcher_listener: true
        body_listener: true
        format_listener: true
        routing_loader:
            default_format: json
            include_format: false
        serializer:
            serialize_null: true
    pgs_restfony:
        modules:

and include it in the main config:, (*6)

    # app/config/config.yml

    imports:
    # ...
        - { resource: rest.yml }

    # ...

Add routing definition, e.g.:, (*7)

    # app/config/routing.yml 

    # ...

    appbundle_rest:
        resource: "@AppBundle/Resources/config/rest_routing.yml"
        prefix:   /api/

Usage

Having an entity run command:, (*8)

    bin/console pgs:generate:crud MyEntity

provide entity shortcut name (e.g. AppBundle:MyEntity), decide about adding "write" actions and generation of routing., (*9)

New files will be generated: - Controller/MyEntityController.php - controller with RESTful actions and ApiDoc - Form/Filter/MyEntityFilterType.php - form filter class - Form/Type/MyEntityType.php - form type class - Manager/MyEntityManager.php - empty class to manage repository - Manager/MyEntityManagerInterface.php - interface for manager from above - Repository/MyEntityRepository.php - empty repository class - Resources/config/serializer/Entity.MyEntity.yml - config for JMS Serializer - Tests/MyEntityControllerTest.php - set up of tests for generated actions, (*10)

And configs will be updated: - rest.yml - module for MyEntity will be added - rest_routing.yml - entry for MyEntity will be added, (*11)

API Doc

If needed you can add NelmioApiDocBundle API documentation route, e.g.:, (*12)

    # app/config/routing_dev.yml

    # ...

    NelmioApiDocBundle:
        resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
        prefix:   /api/doc

Authors

Contributors

The Versions