vendor/bundles/FOS/UserBundle/Form/Handler/GroupFormHandler.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\GroupInterface;
       
    18 use FOS\UserBundle\Model\GroupManagerInterface;
       
    19 
       
    20 class GroupFormHandler
       
    21 {
       
    22     protected $request;
       
    23     protected $groupManager;
       
    24     protected $form;
       
    25 
       
    26     public function __construct(Form $form, Request $request, GroupManagerInterface $groupManager)
       
    27     {
       
    28         $this->form = $form;
       
    29         $this->request = $request;
       
    30         $this->groupManager = $groupManager;
       
    31     }
       
    32 
       
    33     public function process(GroupInterface $group = null)
       
    34     {
       
    35         if (null === $group) {
       
    36             $group = $this->groupManager->createGroup('');
       
    37         }
       
    38 
       
    39         $this->form->setData($group);
       
    40 
       
    41         if ('POST' == $this->request->getMethod()) {
       
    42             $this->form->bindRequest($this->request);
       
    43 
       
    44             if ($this->form->isValid()) {
       
    45                 $this->onSuccess($group);
       
    46 
       
    47                 return true;
       
    48             }
       
    49         }
       
    50 
       
    51         return false;
       
    52     }
       
    53 
       
    54     protected function onSuccess(GroupInterface $group)
       
    55     {
       
    56         $this->groupManager->updateGroup($group);
       
    57     }
       
    58 }