vendor/bundles/FOS/UserBundle/Form/Handler/ProfileFormHandler.php
changeset 3 e54dfe4d0b2b
equal deleted inserted replaced
2:806e57d67020 3:e54dfe4d0b2b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the FOSUserBundle package.
       
     5  *
       
     6  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace FOS\UserBundle\Form\Handler;
       
    13 
       
    14 use Symfony\Component\Form\Form;
       
    15 use Symfony\Component\HttpFoundation\Request;
       
    16 
       
    17 use FOS\UserBundle\Model\UserInterface;
       
    18 use FOS\UserBundle\Model\UserManagerInterface;
       
    19 use FOS\UserBundle\Form\Model\CheckPassword;
       
    20 
       
    21 class ProfileFormHandler
       
    22 {
       
    23     protected $request;
       
    24     protected $userManager;
       
    25     protected $form;
       
    26 
       
    27     public function __construct(Form $form, Request $request, UserManagerInterface $userManager)
       
    28     {
       
    29         $this->form = $form;
       
    30         $this->request = $request;
       
    31         $this->userManager = $userManager;
       
    32     }
       
    33 
       
    34     public function process(UserInterface $user)
       
    35     {
       
    36         $this->form->setData(new CheckPassword($user));
       
    37 
       
    38         if ('POST' == $this->request->getMethod()) {
       
    39             $this->form->bindRequest($this->request);
       
    40 
       
    41             if ($this->form->isValid()) {
       
    42                 $this->onSuccess($user);
       
    43 
       
    44                 return true;
       
    45             }
       
    46 
       
    47             // Reloads the user to reset its username. This is needed when the
       
    48             // username or password have been changed to avoid issues with the
       
    49             // security layer.
       
    50             $this->userManager->reloadUser($user);
       
    51         }
       
    52 
       
    53         return false;
       
    54     }
       
    55 
       
    56     protected function onSuccess(UserInterface $user)
       
    57     {
       
    58         $this->userManager->updateUser($user);
       
    59     }
       
    60 }