Open marcelo-lipienski opened 10 years ago
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.
The split is to ensure SRP.
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 $config['slm_cache']
is "good enough" for me.
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.