pgs-soft / restfony-bundle
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
Requires
- php: >=5.6
- doctrine/doctrine-bundle: ^1.6
- friendsofsymfony/rest-bundle: ^2.0
- jms/serializer-bundle: ^1.1
- knplabs/knp-paginator-bundle: ^2.5
- lexik/form-filter-bundle: ^5.0
- nelmio/api-doc-bundle: ^2.13
- symfony/symfony: ^3.1
- willdurand/hateoas-bundle: ^1.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.11
- pdepend/pdepend: ^2.2
- phing/phing: ^2.14
- php-mock/php-mock-phpunit: ^1.1
- phpmd/phpmd: ^2.4
- phpspec/prophecy: ^1.6
- phpunit/php-code-coverage: ^4.0
- phpunit/phpunit: ^5.5
- sebastian/phpcpd: ^2.0
- sensio/generator-bundle: ^3.0
- squizlabs/php_codesniffer: ^2.6
- theseer/phpdox: 0.8.1.1
This package is auto-updated.
Last update: 2020-02-17 08:20:59 UTC
README
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
- Lech Groblewicz lgroblewicz@pgs-soft.com
- Michał Sikora
Contributors
- Tomasz Brzeziński tbrzezinski@pgs-soft.com
- Karol Joński kjonski@pgs-soft.com
- Krzysztof Maczkowiak kmaczkowiak@pgs-soft.com
- Grzegorz Mandziak gmandziak@pgs-soft.com
- Kamil Purzyński kpurzynski@pgs-soft.com
- Dariusz Rzeźnik drzeznik@pgs-soft.com
- Jakub Werłos jwerlos@pgs-soft.com
- Krzysztof Wojtas kwojtas@pgs-soft.com