I would just make Factory methods non-stationary and pass them to every object that needs this factory.
To configure Factory, you need to pass it using the $qux parameter in the constructor.
class Foo_Factory { public function __construct($qux) { $this->qux = $qux; } public function getFoo( $type ) {
With this approach, you should easily use it in classes where you need to work with Factory without "problems" with passing around a service container or registry.
In this example, I would use the direct approach only to simply bypass the objects that you really need, and not abstract them in container classes.
The decision about whether to use a DIC or a registry or a plain old DI is what I think should be done for your entire project. I strongly prefer DIC in the registry, but like a normal DI, it's even better. For this context, it is difficult to argue about or against a particular approach.
To summarize: if static Factory is a problem, just make it not static.
I hope I understood your message correctly;)
edorian
source share