Symfony : is there a best practice about the directories' name including traits and interfaces?

8.7k views Asked by At

I guess I can't create a Trait or Interface directory inside my bundle since this is a keyword that would bring problems when used (i.e. use MyBundle\trait\MyTrait).

Is there a best practice about how to name these directories ?

3

There are 3 answers

0
BentCoder On BEST ANSWER

Symfony specific: Put your traits in Util folder. In terms of the interfaces; e.g. you have a service class called Hello and HelloInterface then they both should go to Service folder or if you have some kind of class called Yow and YowInterface then you can put them Util folder as well. As simple as that.

0
John Cartwright On

Regarding naming convention, see coding standards

Regarding directory structure, I don't specifically put them in a trait directory. It depends on how you want to organize your code. Generally, most people will put the trait inside a package folder for the behaviour it represents, i.e., Mysql\ConnectionTrait

0
Fernando Caraballo On

You can create it on many ways, but like John said there's not a specific one.

I would create them in a CoreBundle and not necessarily with Trait as a class name. e.g. in my project we have them all created in

CoreBundle\Entity\Traits\ExampleEntity