src/EventSubscriber/User/ProfileSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\User;
  3. use App\Entity\User\User;
  4. use App\Manager\Boutique\PanierManager;
  5. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  6. use FOS\UserBundle\FOSUserEvents;
  7. use FOS\UserBundle\Event\FormEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  11. class ProfileSubscriber implements EventSubscriberInterface
  12. {
  13.     private $router;
  14.     private $session;
  15.     private $panierManager;
  16.     public function __construct(UrlGeneratorInterface $routerSessionInterface $sessionPanierManager $panierManager) {
  17.         $this->router           $router;
  18.         $this->session          $session;
  19.         $this->panierManager    $panierManager;
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         return array(
  24.             FOSUserEvents::PROFILE_EDIT_SUCCESS => array('onProfileEditSuccess', -10),
  25.         );
  26.     }
  27.     public function onProfileEditSuccess(FormEvent $event)
  28.     {
  29.         $user $event->getForm()->getData();
  30.         // On MAJ le client du panier si on en a un
  31.         $panierId $this->session->get('panierId');
  32.         if (!is_null($panierId)) {
  33.             $this->panierManager->modifierUser($user);
  34.             if (!is_null($user->getPays())) {
  35.                 $this->panierManager->modifierLivraisonPays($user$user->getPays());
  36.             }
  37.         }
  38.         $redirect $this->router->generate('fos_user_profile_show');
  39.         $response = new RedirectResponse($redirect);
  40.         $event->setResponse($response);
  41.     }
  42. }