Symfony: is there a best practice for naming directories including traits and interfaces?

I guess I cannot create a directory Trait

or Interface

inside my package, as it is a keyword that brings problems when used (i.e. use MyBundle\trait\MyTrait

).

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

+3


source to share


3 answers


For naming convention, see coding standards



As for the directory structure, I do not specifically put them in the traits directory. It depends on how you want to organize your code. Generally, most people put a trait inside the package folder for their behavior, i.e. Mysql \ ConnectionTrait

+2


source




Symphony: put your traits in the Util folder. In terms of interfaces; for example you have service class Hello and HelloInterface then both should go to service folder or if you have some class called Yow and YowInterface you can put them in Util folder as well. So simple.

+7


source


You can create it in different ways, but as John said, there is no specific one.

I would create them in CoreBundle and not necessarily with Trait as the class name. for example in my project we created everything in

CoreBundle \ Entity \ Traits \ ExampleEntity

+4


source







All Articles