Skip to content
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

Remove silly doctrine.$something.{$this->something} pattern from factories #76

Closed
Ocramius opened this issue Aug 12, 2012 · 4 comments
Closed
Labels

Comments

@Ocramius
Copy link
Member

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

@superdweebie
Copy link
Contributor

After playing with the code some more, I agree with this wholeheartedly. Not quite sure how to go about it myself though.

@Ocramius
Copy link
Member Author

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?

@superdweebie
Copy link
Contributor

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.).

@Ocramius
Copy link
Member Author

Handled in #226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants