Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for using Handlers (by @WBerredo) and support for routing annotations (basic) #38

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5a13dd3
Initial test
WBerredo Nov 13, 2014
3c9a713
Work with handlers as service
WBerredo Nov 20, 2014
8c09680
Revert "Initial test"
WBerredo Nov 20, 2014
812692d
restore VoryxController class, for older controllers.
WBerredo Nov 20, 2014
eb08d00
refactory of put template
WBerredo Nov 20, 2014
28d43e9
Use the NelmioApiDocBundle to document the API
WBerredo Nov 20, 2014
72219c3
Add 'use' statement to NelmioAPiDoc
WBerredo Nov 20, 2014
a36a39f
Merge branch 'master' of https://github.com/WBerredo/restgeneratorbundle
WBerredo Nov 20, 2014
5c1b219
Fix the function that update DependencyInjection file
WBerredo Nov 24, 2014
e12a93b
Make documentation be optional
WBerredo Nov 24, 2014
a4f9247
Fix ident on documentation
WBerredo Nov 24, 2014
ad5bc07
Indent of functions on controller
WBerredo Nov 24, 2014
19c410c
Make the resource as object be optional.
WBerredo Nov 24, 2014
5cd1c9e
Update the templates.
WBerredo Nov 24, 2014
45fddae
Allow getAll function on handler without parameters
WBerredo Nov 28, 2014
e99058a
Permit show delete message.
WBerredo Dec 1, 2014
4e55ef3
Fix PHPdocs messages
WBerredo Dec 22, 2014
357cf75
update to composer for symfony 3
WickedSilver Mar 30, 2016
37fa661
added .idea in gitignore
WickedSilver Mar 30, 2016
b660a16
merged 'Work with handlers as service' including nelmio api doc by WB…
WickedSilver Mar 30, 2016
189dac3
create the DependencyInjection folder if it doesn't exist
WickedSilver Mar 30, 2016
7ab41e3
create everything including the BundleExtension.php
WickedSilver Mar 30, 2016
12dfff6
now fixed creation of the DependencyInjection the right way. also che…
WickedSilver Mar 31, 2016
9a8d0ec
added extension bare class file when not yet created and added phpdoc…
WickedSilver Mar 31, 2016
591d749
added type-fixing and fixed the extension generation
WickedSilver Mar 31, 2016
83b24af
fixed formattting issues
WickedSilver Mar 31, 2016
dff4ea3
more formatting fixes in docs and added ApiDoc input/output by default
WickedSilver Apr 1, 2016
938e268
fix for re-generate form using the --overwrite option
WickedSilver Apr 1, 2016
e0e36e3
added basic support for annotation routing format
WickedSilver Apr 1, 2016
09d9215
added entity name after route prefix in route annotation above contro…
WickedSilver Apr 1, 2016
c548387
added function route annotations for the REST controller methods and …
WickedSilver Apr 1, 2016
34a19ff
added Symfony3 readme, bin/console instead of app/console
WickedSilver Apr 1, 2016
d13c39a
resolved conflict on composer.json with voryx master
WickedSilver Apr 1, 2016
06b221d
testing of nicely saving the servicesREST.xml file
WickedSilver Apr 1, 2016
5c9f439
undid previous commit
WickedSilver Apr 1, 2016
92f8fad
removed input/output from ApiDoc which caused failures
WickedSilver Apr 13, 2016
a54d6c7
alpha version of test generation
WickedSilver Apr 15, 2016
0fea7c3
bug fix for wrong reference to test.php.twig
WickedSilver Apr 15, 2016
fae1f64
undid rendering of tests since it gave hard errors
WickedSilver Apr 15, 2016
f9cb269
Develop > Master (Implemented tests and fixed interactive mode) (#2)
WickedSilver Apr 22, 2016
b08b191
implemented/updated creating form to be compliant with symfony 2.8+ a…
WickedSilver Apr 25, 2016
f857083
resolved merge conflicts with current master version of voryx/restgen…
WickedSilver Apr 25, 2016
2e5f84d
hotfix for generating yml service when no yml exists
WickedSilver Apr 25, 2016
be3e8d5
hotfix for failing test generation on Length Validator
WickedSilver Apr 25, 2016
26a350c
Develop > Master (#3)
WickedSilver Apr 29, 2016
13e383e
fixed routing issues for generation of sub-entities (#4)
WickedSilver May 12, 2016
0132d8b
fixed minor typo in cgetAction api doc block
WickedSilver May 13, 2016
efbcb07
Fix to support Symfony >=2.8
boskee Jul 5, 2016
bbf1a4e
Update README.md
WBerredo Feb 24, 2017
d04571a
Merge pull request #6 from WBerredo/patch-1
WickedSilver Feb 24, 2017
55260df
Updated Dependencies
sujayjaju Jul 5, 2017
b39b6b5
Merge pull request #5 from boskee/master
WickedSilver Nov 23, 2017
9b01059
Merge pull request #7 from sujayjaju/master
WickedSilver Jan 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/vendor/
composer.lock
/nbproject/private/
nbproject/
nbproject/

.idea/
182 changes: 182 additions & 0 deletions README.Symfony3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Voryx REST Generator Bundle
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/ac1842d9-4e36-45cc-8db1-b97e2e62540e/big.png)](https://insight.sensiolabs.com/projects/ac1842d9-4e36-45cc-8db1-b97e2e62540e)

## About

A CRUD like REST Generator

## Features

* Generators RESTful action from entity
* Simplifies setting up a RESTful Controller


## Installation
Require the "voryx/restgeneratorbundle" package in your composer.json and update your dependencies.

```bash
$ php composer.phar require voryx/restgeneratorbundle dev-master
```

Add the VoryxRestGeneratorBundle to your application's kernel along with other dependencies:

```php
public function registerBundles()
{
$bundles = array(
//...
new Voryx\RESTGeneratorBundle\VoryxRESTGeneratorBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
new Nelmio\CorsBundle\NelmioCorsBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
//...
);
//...
}
```

## Configuration

This bundle depends on a number of other Symfony bundles, so they need to be configured in order for the generator to work properly

```yaml
framework:
csrf_protection: false #only use for public API

fos_rest:
routing_loader:
default_format: json
param_fetcher_listener: true
body_listener: true
#disable_csrf_role: ROLE_USER
body_converter:
enabled: true
view:
view_response_listener: force

nelmio_cors:
defaults:
allow_credentials: false
allow_origin: []
allow_headers: []
allow_methods: []
expose_headers: []
max_age: 0
paths:
'^/api/':
allow_origin: ['*']
allow_headers: ['*']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
max_age: 3600

sensio_framework_extra:
request: { converters: true }
view: { annotations: false }
router: { annotations: true }

nelmio_api_doc: ~
```

## Generating the Controller


Generate the REST controller

```bash
$ php bin/console voryx:generate:rest
```

This will guide you through the generator which will generate a RESTful controller for an entity.


## Example

Create a new entity called 'Post':

```bash
$ php bin/console doctrine:generate:entity --entity=AppBundle:Post --format=annotation --fields="name:string(255) description:string(255)" --no-interaction
```

Update the database schema:

```bash
$ php bin/console doctrine:schema:update --force
```

Generate the API controller:

```bash
$ php bin/console voryx:generate:rest --entity="AppBundle:Post"
```

Full example with all parameters

```bash
$ php app/console voryx:generate:rest --entity="AppBundle:Post" --document --overwrite --route-prefix="api" --route-format="yml" --service-format="yml" --test="none"
```

possible values for all parameters

| Parameter | Explanation | Values |
| --------- | ----------- | ------- |
| entity | The entity for which the REST api should be generated | **AppBundle:Post**, **AppBundle:Blog\Post**
| document | Whether or not you want API's documented by Nelmio | Yes if present, else No
| overwrite | Whether or not you want to overwrite existing generated files | Yes if present, else No
| resource | - | Yes if present, else No
| route-prefix | The route to prefix the generated Controller with (default api) | Any string
| route-format | The format that routing is generated in (default yml) | **yml** or **annotation**
| service-format | The format that the service is generated in (default yml) | **yml** or **xml**
| test | The type of test that should be generated | **none**, **oauth** or **no-authentication**


### Using the API
If you selected the default options you'll be able to start using the API like this:

Creating a new post (`POST`)

```bash
$ curl -i -H "Content-Type: application/json" -X POST -d '{"name" : "Test Post", "description" : "This is a test post"}' http://localhost/app_dev.php/api/posts
```

Updating (`PUT`)

```bash
$ curl -i -H "Content-Type: application/json" -X PUT -d '{"name" : "Test Post 1", "description" : "This is an updated test post"}' http://localhost/app_dev.php/api/posts/1
```

Get all posts (`GET`)

```bash
$ curl http://localhost/app_dev.php/api/posts
```

Get one post (`GET`)

```bash
$ curl http://localhost/app_dev.php/api/posts/1
```


Delete (`DELETE`)

```bash
$ curl -X DELETE http://localhost/app_dev.php/api/posts/1
```


## Related Entities

If you want the form to be able to convert related entities into the correct entity id on POST, PUT or PATCH, use the voryx_entity form type

```php
use Voryx\RESTGeneratorBundle\Form\Type\VoryxEntityType;

#Form/PostType()

->add(
'user', VoryxEntityType:class, array(
'class' => 'Acme\Bundle\Entity\User'
)
)
```
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function registerBundles()
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
new Nelmio\CorsBundle\NelmioCorsBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
//...
);
//...
Expand Down Expand Up @@ -73,6 +74,8 @@ sensio_framework_extra:
request: { converters: true }
view: { annotations: false }
router: { annotations: true }

nelmio_api_doc: ~
```

## Generating the Controller
Expand Down Expand Up @@ -107,6 +110,27 @@ Generate the API controller:
$ php app/console voryx:generate:rest --entity="AppBundle:Post"
```

Full example with all parameters

```bash
$ php app/console voryx:generate:rest --entity="AppBundle:Post" --document --resource --overwrite --route-prefix="api" --route-format="yml" --service-format="yml" --test="none"
$ php app/console voryx:generate:rest --entity="AppBundle:User/Domain" --document --overwrite --route-prefix="api" --route-format="annotation" --service-format="yml" --test="oauth2"
```

possible values for all parameters

| Parameter | Explanation | Values |
| --------- | ----------- | ------- |
| entity | The entity for which the REST api should be generated | **AppBundle:Post**, **AppBundle:Blog\Post**
| document | Whether or not you want API's documented by Nelmio | Yes if present, else No
| overwrite | Whether or not you want to overwrite existing generated files | Yes if present, else No
| resource | Whether or not you want the resource name encapsulating the response | Yes if present, else No
| route-prefix | The route to prefix the generated Controller with (default api) | Any string
| route-format | The format that routing is generated in (default yml) | **yml** or **annotation**
| service-format | The format that the service is generated in (default yml) | **yml** or **xml**
| test | The type of test that should be generated | **none**, **oauth** or **no-authentication**


### Using the API
If you selected the default options you'll be able to start using the API like this:

Expand Down Expand Up @@ -147,10 +171,12 @@ $ curl -X DELETE http://localhost/app_dev.php/api/posts/1
If you want the form to be able to convert related entities into the correct entity id on POST, PUT or PATCH, use the voryx_entity form type

```php
#Form/PostType()
use Voryx\RESTGeneratorBundle\Form\Type\VoryxEntityType;

// ...

->add(
'user', 'voryx_entity', array(
'user', VoryxEntityType:class, array(
'class' => 'Acme\Bundle\Entity\User'
)
)
Expand Down
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voryx/restgeneratorbundle",
"description": "REST API Generator for Symfony 2",
"description": "REST API Generator for Symfony",
"type": "symfony-bundle",
"license": "MIT",
"authors": [
Expand All @@ -9,14 +9,20 @@
},
{
"name": "David Dan"
},
{
"name": "Maarten Sprakel"
}
],
"require": {
"php": ">=5.3.0",
"php": ">=5.5.9",
"symfony/symfony": ">=2.8",
"sensio/generator-bundle": "~3.0",
"friendsofsymfony/rest-bundle": "~1.7",
"jms/serializer-bundle": "~1.1",
"nelmio/cors-bundle": "~1.4 "
"friendsofsymfony/rest-bundle": "^2.2",
"jms/serializer-bundle": "^2.0",
"nelmio/cors-bundle": "~1.5",
"nelmio/api-doc-bundle": "~2.7",
"doctrine/orm": ">=2.0"
},
"autoload": {
"psr-0": {
Expand Down
Loading