doctrine / DoctrineModule

Doctrine Module for Laminas
http://www.doctrine-project.org/projects/doctrine-module.html
MIT License
398 stars 270 forks source link

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

Closed Ocramius closed 11 years ago

Ocramius commented 12 years ago

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 commented 12 years ago

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

Ocramius commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

Handled in #226