api/ApiBundle/EventSubscriber/UserSubscriber.php line 60

Open in your IDE?
  1. <?php
  2. namespace Pmag\ApiBundle\EventSubscriber;
  3. use Pmag\ApiBundle\ApiEvents\ClientEvents;
  4. use Pmag\ApiBundle\Event\ClientEvent;
  5. use Pmag\ApiBundle\Service\MailerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Twig\Environment;
  8. /**
  9.  * UserSubscriber
  10.  * @package Pmag\ApiBundle\EventSubscriber
  11.  * @author Daly Ala <rafin_ala03@hotmail.fr>
  12.  **/
  13. class UserSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var MailerInterface
  17.      */
  18.     private $mailer;
  19.     /**
  20.      * @var Environment
  21.      */
  22.     private $twig;
  23.     /**
  24.      * UserSubscriber constructor.
  25.      * @param MailerInterface $mailer
  26.      * @param Environment $twig
  27.      */
  28.     public function __construct(MailerInterface $mailerEnvironment $twig)
  29.     {
  30.         $this->mailer $mailer;
  31.         $this->twig $twig;
  32.     }
  33.     /**
  34.      * @return array The event names to listen to
  35.      */
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return array(
  39.             ClientEvents::CLIENT_REGISTRATION_SUCCESS => 'onRegistrationSuccess',
  40.             ClientEvents::CLIENT_CHANGE_PASSWORD_SUCCESS=> 'onChangePasswordSuccess'
  41.         );
  42.     }
  43.     /**
  44.      * Actions to perform after client registration success goes here
  45.      *
  46.      * @param ClientEvent $clientEvent
  47.      * @throws \Exception
  48.      */
  49.     public function onRegistrationSuccess(ClientEvent $clientEvent)
  50.     {
  51.         $client $clientEvent->getClient();
  52.         // send confirmation email
  53.         $this->mailer->sendEmail(
  54.             'Welcome',
  55.             $client->getEmail(),
  56.             $this->twig->render('emails/security/register.html.twig', [
  57.                     'client' => $client,
  58.                 ]
  59.             )
  60.         );
  61.     }
  62.     /**
  63.      * Actions to perform after client reset password success goes here
  64.      *
  65.      * @param ClientEvent $clientEvent
  66.      * @throws \Exception
  67.      */
  68.     public function onChangePasswordSuccess(ClientEvent $clientEvent)
  69.     {
  70.         $client $clientEvent->getClient();
  71.         // send reset password success email
  72.         $this->mailer->sendEmail(
  73.             'Password Successfully Reset',
  74.             $client->getEmail(),
  75.             $this->twig->render('emails/security/change-password.html.twig', [
  76.                 'client' => $client
  77.             ])
  78.         );
  79.     }
  80. }