0

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?

Community
  • 1
  • 1
frak
  • 858
  • 1
  • 10
  • 30
  • Do you have other services that are being properly loaded? Is there a chances that your services.yml file is not being loaded? Does app/console container:debug show your service? – Cerad Aug 28 '13 at 16:28
  • Yes, the service is being loaded and I can see it when I run container:debug, but thanks for the extra debugging tip – frak Aug 28 '13 at 16:31
  • Is the code you posted your real code or did you edit it for your question? I ask because your constructor only shows one argument. It should have thrown an error message. Do you have error_reporting(E_ALL); somewhere? Do simple typos throw an error for you? – Cerad Aug 28 '13 at 16:32
  • I did edit the code for my question as the router is not used yet, I have added this back in – frak Aug 28 '13 at 16:36
  • Well. I don't see anything else wrong as far as event handling. Maybe stick a die statement in onRegistrationInitialize. It's possible that the logger is not properly initialized and thus your log messages are not being persisted. – Cerad Aug 28 '13 at 16:40
  • Just gave this a try and no luck – frak Aug 28 '13 at 16:50
  • And you are testing this by going through the FOSUserBundle registration process? You have not overridden the registration controller? If you put a die statement in you listener's constructor does it die? Running your test in development mode? Kind of scraping the bottom of the barrel here. – Cerad Aug 28 '13 at 17:00
  • In order: no, I am going through the HWIOauth registration process, no, yes and yes. – frak Aug 28 '13 at 17:05
  • Well. When all else fails try deleting app/cache/dev. You mentioned going from FOSUserBundle 1.x to 2.x. Maybe you are somehow still accessing the S1.x registration controller. Maybe put a die statement in the S2 registration controller. Maybe try dispatching an event from a different controller completely. Maybe make a functional test or symfony command. It's going to be something simple. – Cerad Aug 28 '13 at 17:13

1 Answers1

3

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

frak
  • 858
  • 1
  • 10
  • 30