Closed Ocramius closed 11 years ago
After playing with the code some more, I agree with this wholeheartedly. Not quite sure how to go about it myself though.
Seems like keeping the pattern doctrine.$something.$name
will actually help us. We can define an abstract factory and solve the problems related to our multi-entity-manager-problems in no-time this way:
<?php
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class SuperDuperDoctrineFactory implements Zend\ServiceManager\AbstractFactoryInterface
{
public function canCreateServiceWithName(ServiceLocatorInterface $sl, $name, $requestedName)
{
// @todo this is over-simplified obviously
return 0 === strpos('doctrine.', $requestedName);
}
public function createServiceWithName(ServiceLocatorInterface $sl, $name, $requestedName)
{
// @todo pseudo-code
$service = match('doctrine.<$serviceType>.<$serviceName>', $requestedName);
$factory = $this->getFactory($serviceType, $serviceName);
return $factory->createService($sl);
}
}
Thoughts?
I've got this up and running locally in tandem with DoctrineMongoODMModule
. Works well. All tests pass without any changes to the test suite at all. I'll make a few more tweaks and then put in a PR (although I'm offline for a little while, probably won't get to it for just over a week.).
Handled in #226
The pattern in the subject currently makes it hard for the end user to provide own factories. It can still live as a sane default, but should be instead a fallback logic