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

add support of multiple entity managers #80

Open
YahouSerious opened this issue May 29, 2013 · 11 comments
Open

add support of multiple entity managers #80

YahouSerious opened this issue May 29, 2013 · 11 comments

Comments

@YahouSerious
Copy link

Is it possible to add a configuration option "entity_manager" for multitenancy ? Thanks

@makasim
Copy link
Contributor

makasim commented May 30, 2013

Sorry, I dont get what you want. Could you be more descriptive?

  • Where to add it? bundle config security factory config?
  • multitenancy - what is this?

@YahouSerious
Copy link
Author

I'm working on a multi customer application( multi database connection ). Each client got his own database, so I need to use a custom entity manager. Your "identity_class" use the default entity manager. This could be a good thing to use custom entity manager(in my case :)).

cf: http://symfony.com/doc/master/cookbook/doctrine/multiple_entity_managers.html

@makasim
Copy link
Contributor

makasim commented May 30, 2013

Good question. I dont know a good way to solve it, honestly I dont even have time to investigate it deeper. So you do a PR, that's would be really good.

Solution for know to create your own provider and use it. or overwrite this service

@makasim makasim closed this as completed May 30, 2013
@makasim makasim reopened this May 30, 2013
@makasim
Copy link
Contributor

makasim commented May 30, 2013

closed by mistake

@YahouSerious
Copy link
Author

ok, but at this time, i got trouble with class OpenIdIdentity. It can't inherite from Fp\OpenIdBundle\Entity\UserIdentity. Are you sure you must not put something like "@Orm\Column(name="identity", type="string")" in your classes ? Thanks.

@makasim
Copy link
Contributor

makasim commented May 31, 2013

make sure doctrine auto mapping enabled.

@YahouSerious
Copy link
Author

I can't enable auto mapping when several entity managers are defined

@makasim
Copy link
Contributor

makasim commented May 31, 2013

so you have to add fp openid mappings explisitly, use this example:

doctrine:
    orm:
        entity_managers:
            default:
                # The name of a DBAL connection (the one marked as default is used if not set)
                connection:                               default
                mappings: # Required
                    CoreBundle:                           { type: annotation, dir: Entity/, alias: '' }
                    JMSPaymentCoreBundle:                 { type: xml, dir: Resources/config/doctrine }

@YahouSerious
Copy link
Author

Like this ?
mappings:
FpOpenIdBundle:
type: annotation
prefix: Fp\OpenId\Entity
dir: "%kernel.root_dir%/../vendor/fp/openid-bundle/Fp/OpenIdBundle/Entity"
alias: 'FpOpenId'
is_bundle: false

@makasim
Copy link
Contributor

makasim commented May 31, 2013

no, fpopenid uses xml for schemas, so that would be (not tested):

mappings: 
    FpOpenIdBundle: { type: xml, dir: Resources/config/doctrine }

@YahouSerious
Copy link
Author

Thanks it works ! :)

Now i'm trying to inject the custom entity manager ...

config.yml:

# OpenId
fp_open_id:
    db_driver: orm
    entity_manager: "@doctrine.orm.customer_entity_manager"
    identity_class: App\SiteBundle\Entity\OpenIdIdentity

Configuration.php

/**
     * 
     *  {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('fp_open_id');

        $rootNode
            ->children()
                ->scalarNode('db_driver')->defaultNull()->end()
                ->scalarNode('entity_manager')->defaultValue('doctrine.orm.entity_manager')->end()
                ->scalarNode('identity_class')->defaultNull()->end()
            ->end()
        ;

        $this->addTemplateSection($rootNode);

        return $treeBuilder;
    }

FpOpenIdExtension.php

// ....

/**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        // ... 

        if ($configs['entity_manager']) {
            $this->loadEntityManagerr($configs, $container, $loader);
        }
    }

/**
     * @param array $configs
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
     *
     * @throws \InvalidArgumentException
     */
    public function loadEntityManagerr(array $configs, ContainerBuilder $container, $loader)
    {
        $container->setParameter('entity_manager', $configs['entity_manager']);
    }

And here is the trouble, i don't know how inject the entity manager in fp_openid.identity_manager service:

<services>
        <service id="fp_openid.identity_manager" class="%fp_openid.identity_manager.class%">
           <!--  <argument type="service" id="doctrine.orm.entity_manager" /> --> 
            <argument type="service" id="%entity_manager%" />
            <argument>%fp_openid.model.identity.class%</argument>
        </service>

    </services>

Thanks for your help

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

No branches or pull requests

2 participants