Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 | HWIOAuthBundle - How to create custom resource owner?

I started to implement HWIOAuthBundle and want to create my own custom resource owner. However I'm unclear about the file/directory structure.

Where would I need to place my files to take advantage of the bundle?

like image 800
n00b Avatar asked Jun 12 '13 08:06

n00b


1 Answers

I overrode the HWIOAuthBundle linkedin resource owner, because I needed to handle connection exceptions. You can use a compiler pass to do this:

namespace UserAccountBundle\DependencyInjection\Compiler;

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

class OverrideServiceCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $definition = $container->getDefinition('hwi_oauth.resource_owner.linkedin');
        $definition->setClass('UserAccountBundle\OAuth\MyLinkedInResourceOwner');
    }
}

Then in your bundle:

namespace UserAccountBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use UserAccountBundle\DependencyInjection\Compiler\OverrideServiceCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class UserAccountBundle extends Bundle
{

    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new OverrideServiceCompilerPass());
    }
}

More on bundle overrides: http://symfony.com/doc/current/cookbook/bundles/override.html

like image 77
jimconte Avatar answered Nov 14 '22 23:11

jimconte