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
RestControllermethods for some classes that doesn't depend onController?Since you will surely use some
Controllermethods 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
RestControlleras aControllerinherited one and write these others classes as traits. If the answer is no, it's even clearer thatRestControllershould be an intermediary one.