Symfony : is it better to use a trait or an intermediary class to complete Controller one?

105 views Asked by At

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 ?

1

There are 1 answers

0
Ivan Gabriele On BEST ANSWER

Using a trait depends on 2 things :

  • Do you want to use RestController methods for some classes that doesn't depend on Controller ?

    Since you will surely use some Controller methods to write RestController, 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 a Controller inherited one and write these others classes as traits. If the answer is no, it's even clearer that RestController should be an intermediary one.