pgs-soft/restfony-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Symfony3 bundle to implement REST crud

Installs: 3 202

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 5

Forks: 0

Open Issues: 4

Type:symfony-bundle

1.0.0 2016-08-10 09:35 UTC

This package is auto-updated.

Last update: 2020-02-17 08:20:59 UTC


README

Latest Stable Version Minimum PHP Version License Build Status Code Coverage Scrutinizer Code Quality

Bundle to assist with creating classes for Doctrine Entity with aim to speed up creating RESTful APIs.

Installation

Require the bundle with composer:

    composer require pgs-soft/restfony-bundle

Enable the bundle (with dependent bundles) in the kernel:

    <?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:

    # 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:

    # app/config/config.yml
    
    imports:
    # ...
        - { resource: rest.yml }
    
    # ...

Add routing definition, e.g.:

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

Usage

Having an entity run command:

    bin/console pgs:generate:crud MyEntity

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

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

And configs will be updated:

  • rest.yml - module for MyEntity will be added
  • rest_routing.yml - entry for MyEntity will be added

API Doc

If needed you can add NelmioApiDocBundle API documentation route, e.g.:

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

Authors

Contributors