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

Provide easy means to change entity managers #32

Open
mrardon opened this issue Oct 25, 2014 · 1 comment
Open

Provide easy means to change entity managers #32

mrardon opened this issue Oct 25, 2014 · 1 comment

Comments

@mrardon
Copy link

mrardon commented Oct 25, 2014

Allow configuration to switch entity managers.

We use several database connections and manually map our entity managers. This causes problems when we don't want the OAuth entities to exist in the main entity manager.

As a workaround I added a compiler pass which while not the prettiest of solutions but it allows everything to work as intended.


use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class OAuthCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $replaceEmServices = [
            'oauth2.user_provider',
            'oauth2.scope_manager',
            'oauth2.storage.client_credentials',
            'oauth2.storage.authorization_code',
            'oauth2.storage.user_credentials',
            'oauth2.storage.access_token',
            'oauth2.storage.refresh_token',
            'oauth2.storage.scope',
            'oauth2.client_manager',
        ];

        //Set this to the service id of your entity manager
        $newEntityManager = 'doctrine.orm.connect_entity_manager';

        foreach ($replaceEmServices as $serviceId) {
            if ($container->hasDefinition($serviceId)) {
                $definition = $container->getDefinition($serviceId);
                $reference  = new Reference($newEntityManager);

                $definition->replaceArgument(0, $reference);
            }
        }
    }
}
@Gmulti
Copy link

Gmulti commented Dec 23, 2014

Does it work with an object manager like mongodb odm ?

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