In my Symfony 3 app I have several classes that do some kind of task, for example calculating amounts, finding things, naming directories...
Currently, they are all in Service directory, so directory structure looks something like this:
- AppBundle
-- Controller
-- Entity
-- Form
-- Service
-- LiveStatsCalculator.php
-- DirectoryNamer.php
-- AdvertisementPlayCalendarFactory.php
-- MediaConfigGenerator.php
...
Is this good approach, or should I separate directories, based on a task class is responsible for? For example:
- AppBundle
-- Controller
-- Calculator
-- LiveStatsCalculator.php
-- Entity
-- Factory
-- AdvertisementPlayCalendarFactory.php
-- Form
-- Namer
-- DirectoryNamer.php
Or, perhaps, there is even better solution? :)
The easiest way to learn best practices of framework is to look how the internal framework bundles are organized.
I.e you can go to github for symfony/framework-bundle https://github.com/symfony/framework-bundle
They have responsibility based naming solution and it is reasonable. Having all services stored in a single namespace would end in converting your service into trash can. Or you end in splitting namespaces inside your Services namepsace. I think it is not you want to end with.
Meaningful names and locaiton are always preferred.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With