-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redesigned module architecture #6
base: master
Are you sure you want to change the base?
Redesigned module architecture #6
Conversation
…Listener. Tests are now divided as well.
… instead of a closure
Nice to see the additions :) A real short scan:
|
|
Ok, I did some research and now I have the answer for the third question. The split is to ensure SRP. |
$listener->attach($em); | ||
$listener = $sm->get('CacheListener'); | ||
|
||
$em->attach($listener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this, you proxy to two methods you don't actually need to call. attach()
meant for single listeners, not aggregated listeners. An aggregate is proxied to attachAggregate()
. The aggregate attachment method is then proxied to attach()
on the aggregate itself.
If you revert this change, it will save you two calls :)
To be honest, you can go into fully SRP and split every single bit, but there's often no need for it. Separation of concerns is only needed to a certain extend. Take for instance the service class which does route matching, cache fetching and cache storage all in the same class. You could create a RouteMatcher, a RouteMatch class, a CacheAccess service layer, CacheCommand execution classes and so on. But really, this goes way too far. I'd say just combine the cache/route logic into the listener. If there happens to be more logic required for e.g. response storage (say, you cache the headers from the response as well) or route matching (e.g. more parameters you can tune per route), then we could split those parts from the listener. A second thing: the ServiceLocatorAware shouldn't be needed. You can grab the config in the factory and inject it into the listener. So the factory is responsible for injecting the right config. You can convert the options into an Options class, which if created within a separate factory. An example is the ModuleOptions from my Soflomo\Blog with its own factory. The options class is the best way to do it. However, for such a small module, injecting the |
I did it for learning purposes, I'm guessing it's now easier to be extended (maybe not ?!)
Commits are somewhat messy, I'm trying to do better ^^
If you find time to take a look at this PR and maybe give me some feedback, I'd appreciate.