doctrine / DoctrineBundle

Symfony Bundle for Doctrine ORM and DBAL
https://www.doctrine-project.org/projects/doctrine-bundle.html
MIT License
4.72k stars 453 forks source link

Custom Mapping Type from bundles #101

Closed chEbba closed 10 years ago

chEbba commented 12 years ago

It will be useful to have an availability defining maping types, ex. have a bundle with many custom types. For now it can be done with appending your types to doctrine.dbal.connection_factory.types parameter (it works only if your bundle is loaded after Doctrine one).

Tags with CompilerPass are used for similar cases, but as typesConfig is just an array it doesn't seem so cool:

Use some interface/class and tag it:

interface TypeProvider
{
    public function getTypesConfig();
}
<service id="acme_bundle.dbal.type_provider" class="TypeProviderImpl">
    <argument type="collection">
        <argument key="custom">AcmeBundle\DBAL\Type\CustomType</argument>
    </argument>
    <tag name="doctrine.dbal.type">
</service>

Or use some fake services which will be removed on compile

<service id="acme_bundle.dbal.type" class="AcmeBundle\DBAL\Type\CustomType">
    <tag name="doctrine.dbal.type" type="custom">
</service>

Another way is don't use tags but use some parameter pattern like doctrine.dbal.types.bundle_name, collect them with CompilerPass and add to doctrine.dbal.connection_factory.types.

<parameter key="doctrine.dbal.types.bundle_name" type="collection">
    <parameter key="custom">AcmeBundle\DBAL\Type\CustomType</parameter>
</parameter>

Does anybody interesting in such feature? What implementation will be better?

sroze commented 10 years ago

:+1: I think that the best way to do is to use one of the powerful service container's features: tags !

stof commented 10 years ago

Your bundle can register its custom types by prepending some config: http://symfony.com/doc/current/cookbook/bundles/prepend_extension.html

I don't like the idea of introducing a new concept of type providers in the bundle. And I don't like using fake services either as it would make people think they can inject other services in their types (you cannot)