Symfony 2 | HWIOAuthBundle - 如何创建自定义资源所有者?

时间:2013-06-12 08:11:51

标签: php symfony hwioauthbundle

我开始实现HWIOAuthBundle并希望创建自己的自定义资源所有者。但是我不清楚文件/目录结构。

我需要将文件放在哪里才能利用捆绑包?

3 个答案:

答案 0 :(得分:4)

我覆盖了HWIOAuthBundle linkedin资源所有者,因为我需要处理连接异常。 您可以使用编译器传递来执行此操作:

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');
    }
}

然后在你的包中:

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());
    }
}

有关捆绑覆盖的更多信息: http://symfony.com/doc/current/cookbook/bundles/override.html

答案 1 :(得分:0)

看起来Bundle不支持自定义资源所有者而不直接编辑包(这只是乍一看,我从来没有真正使用过这个包)。

oauth.xml文件(https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/config/oauth.xml)链接到每个现有的资源所有者,所以我想你可以看看这里链接的其中一个是一个很好的起点。

答案 2 :(得分:0)

根据bundle documentation你可以做到。

我认为这是使用位于供应商捆绑包目录HWI \ Bundle \ OAuthBundle \ OAuth \ ResourceOwner中的 GenericOauth2ResourceOwner 类。