Question

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?

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top