I know it exists bundles like FOSRestBundle to achieve that but it can be quite complicated to use it. So I decided to create a simple RestController
class to add more "automatized" methods to list/add/update/delete entities.
So my first question is : is it better to use a trait or an intermediary class to implement it ?
Using a trait depends on 2 things :
Do you want to use
RestController
methods for some classes that doesn't depend onController
?Since you will surely use some
Controller
methods to writeRestController
, I think the answer is no.Do you plan to create others classes that you will have to use to complete your controllers ?
If the answer is yes, there are chances that you will keep
RestController
as aController
inherited one and write these others classes as traits. If the answer is no, it's even clearer thatRestController
should be an intermediary one.