fos-rest-behavior/README.md

71 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2016-03-20 17:20:19 +01:00
# fos-rest-behavior
2016-09-23 11:47:36 +02:00
This a propel behavior to auto-generate methods of [FOSRestBundle](http://symfony.com/doc/current/bundles/FOSRestBundle/index.html).
## Installation
`composer require deblan/fos-rest-behavior`
## How to
```
<table name="foo">
2016-09-23 11:48:22 +02:00
<column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" />
<column name="label" type="VARCHAR" size="256"/>
<column name="is_active" type="BOOLEAN" size="1"/>
2016-09-23 11:47:36 +02:00
2016-09-23 11:48:22 +02:00
<behavior name="Deblan\Propel\Behavior\FOSRestBehavior">
<parameter name="id" value="all"/>
<parameter name="label" value="myGroup"/>
<parameter name="is_active" value="myGroup, anotherGroup"/>
</behavior>
2016-09-23 11:47:36 +02:00
</table>
```
After the model generation, the abstract class `Foo` will be updated with new annotations and methods:
```
/**
* [...]
*
* @JMS\Serializer\Annotation\ExclusionPolicy("all")
*/
abstract class Foo implements ActiveRecordInterface
{
2016-09-23 11:48:22 +02:00
...
2016-09-23 11:47:36 +02:00
/**
* @JMS\Serializer\Annotation\SerializedName("id")
* @JMS\Serializer\Annotation\Groups({"all"})
* @JMS\Serializer\Annotation\VirtualProperty
*/
public function getRestId()
{
return $this->getId();
}
2016-09-23 11:48:22 +02:00
/**
2016-09-23 11:47:36 +02:00
* @JMS\Serializer\Annotation\SerializedName("label")
* @JMS\Serializer\Annotation\Groups({"myGroup"})
* @JMS\Serializer\Annotation\VirtualProperty
*/
public function getRestLabel()
{
return $this->getLabel();
}
2016-09-23 11:48:22 +02:00
/**
2016-09-23 11:47:36 +02:00
* @JMS\Serializer\Annotation\SerializedName("is_active")
* @JMS\Serializer\Annotation\Groups({"myGroup", "anotherGroup"})
* @JMS\Serializer\Annotation\VirtualProperty
*/
public function getRestIsActive()
{
return $this->getIsActive();
}
2016-09-23 11:48:22 +02:00
...
2016-09-23 11:47:36 +02:00
}
```