0

我已按照此处找到的所有建议使用 FOSUserBundle 设置 HWIOAuthBundle,但我希望能够访问用户注册时触发的事件,但到目前为止似乎无法做到这一点。遵循了这个问题中的建议,这是我的事件订阅者(请注意,我对所有事件都不感兴趣,但我只是想测试是否有任何事件被解雇):

<?php
namespace Acme\ClientBundle\EventListener;

use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\Event\GetResponseUserEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\UserEvent;
use Symfony\Bridge\Monolog\Logger;

/**
 * RegistrationConfirmListener
 */
class RegistrationConfirmListener implements EventSubscriberInterface
{
    /**
     * @var Logger
     */
    private $logger;

    function __construct(UrlGeneratorInterface $router, Logger $logger)
    {
        $this->router = $router;
        $this->logger = $logger;
    }

    public static function getSubscribedEvents()
    {
        return array(
            FOSUserEvents::REGISTRATION_INITIALIZE => 'onRegistrationInit',
            FOSUserEvents::REGISTRATION_CONFIRM    => 'onRegistrationConfirm',
            FOSUserEvents::REGISTRATION_CONFIRMED  => 'onRegistrationConfirmed',
            FOSUserEvents::REGISTRATION_COMPLETED  => 'onRegistrationCompleted',
            FOSUserEvents::REGISTRATION_SUCCESS    => 'onRegistrationSuccess',
        );
    }

    public function onRegistrationInit(UserEvent $event)
    {
        $this->logger->info('Registration has started: ' . serialize($event));
    }

    public function onRegistrationConfirm(GetResponseUserEvent $event)
    {
        $this->logger->info("Registration is confirming: " . serialize($event));
    }

    public function onRegistrationConfirmed(FilterUserResponseEvent $event)
    {
        $this->logger->info("Registration has been confirmed: " . serialize($event));
    }

    public function onRegistrationCompleted(FilterUserResponseEvent $event)
    {
        $this->logger->info("Registration has been completed: " . serialize($event));
    }

    public function onRegistrationSuccess(FormEvent $event)
    {
        $this->logger->info("Registration has been successful: " . serialize($event));
    }
}

这是我的服务定义:

acme_user.registration_complete:
    class: Acme\ClientBundle\EventListener\RegistrationConfirmListener
    arguments: [ @router, @logger ]
    tags:
        - { name: kernel.event_subscriber }

但是,即使身份验证/注册成功,我也看不到任何 FOSUserEvents 被记录。我认为可能相关的唯一其他信息是我还将 FOSUserBundle 与 SonataAdminBundle 集成,这似乎也可以正常工作。(好吧,一旦我弄清楚如何将 FOSUserBundle 升级到 v2.0 并修复了所需的更改,就正确了。)

有谁知道我在这里缺少什么才能参与这些事件?

4

1 回答 1

3

事实证明,HWIOAuthBundle 不使用 FOSUserBundle 注册控制器,因此它永远不会触发这些事件。

于 2013-09-03T13:17:31.500 回答