Reputation: 11297
I have a symfony app that provides REST based services. I have one module that is responsible for user login/logout/register actions called the UserBundle.
I have other bundles that provide resources once a user logs (and is provided a token hash).
Now for every resource requested, the client sends the token back which needs to be authenticated. Where exactly do I place this authentication function? I mean I know it needs to be a service that can be injected into multiple bundles but does that mean it is best I create it's own bundle? What about additional services that I may need in future? If I create a bundle for each, then my code organization would get ugly real quick.
Any tips?
Upvotes: 1
Views: 201
Reputation: 4010
I would put the service in UserBundle, since the UserBundle deals with authentication.
Generally I like to place services into the bundle to which they are most relevant. I also typically have a "Default" bundle into which I aggregate a limited number of truly generic services, entities, controllers, etc. In theory anything that goes into Default could be used generically in another project and is almost always something required by more than one other bundle. Occasionally I have bits and pieces in Default that mature to a point where they would make more sense in a more specific, yet still generic, bundle (similar to your UserBundle.. I figure it's probably something that can be dropped into more than one project); these get refactored and named accordingly.
Once-upon-a-time I used to split out new bundles for anything I perceived to be a "module". These days, however, I try to limit the number of bundles in an app.. I've found this to make the code more clear and easier to manage; especially since my idea for any given module's "boundaries" is invariable wrong and I end up moving code around. Plus working primarily in one core bundle makes navigating the code a lot more straightforward.
Upvotes: 2