HWIOauthBundle & FOSUserBundle events not firing

泄露秘密 提交于 2019-12-08 12:05:57

问题


I have followed all of the advice found here for setting up the HWIOAuthBundle with the FOSUserBundle, but I wish to be able to access the events fired when a user registers and so far seem unable to do that. Having followed the advice in this question, here is my event subscriber (note that I am not interested in all of the events, but I just wanted to test if any of them were being fired):

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

And here is my service definition:

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

However I cannot see any of the FOSUserEvents being logged, even though the authentication/registration is successful. The only other information I have that I feel may be relevant is that I am also integrating the FOSUserBundle with then SonataAdminBundle, which also seems to be working correctly. (Well, correctly once I figured out how to upgrade the FOSUserBundle to v2.0 and fixed the changes required.)

Does anyone have any idea what I am missing here to be able to hook into these events?


回答1:


Turns out that the HWIOAuthBundle does not use the FOSUserBundle registration controller so it will never fire those events.



来源:https://stackoverflow.com/questions/18493324/hwioauthbundle-fosuserbundle-events-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!