Ali's answer is completely right, I just want to say something about ServiceLocatorAwareInterface:
Some time ago I was a big fan of ServiceLocatorAwareInterface in my services. Now I'm not sure about that. You must consider this:
Ask ServiceLocator in your Services to make them useless.
Since the service locator is what it is, you can’t talk anymore about what your class depends on, because there’s potentially everything. Instead, you should use Dependancy injection and download everything you need in the Service, with factories, factories - this is the only place where you can use ServiceLocator, this is the place where it belongs.
Ocramius said that it’s better than what I’m trying to say right now, so I link his work here about this:
Best Practices Ocramius Zf2
It inspired me. Hope you too.
source share