vendor/bundles/FOS/UserBundle/Command/PromoteUserCommand.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\Command;
       
    13 
       
    14 use Symfony\Component\Console\Output\OutputInterface;
       
    15 use FOS\UserBundle\Util\UserManipulator;
       
    16 
       
    17 /**
       
    18  * @author Matthieu Bontemps <matthieu@knplabs.com>
       
    19  * @author Thibault Duplessis <thibault.duplessis@gmail.com>
       
    20  * @author Luis Cordova <cordoval@gmail.com>
       
    21  * @author Lenar Lõhmus <lenar@city.ee>
       
    22  */
       
    23 class PromoteUserCommand extends RoleCommand
       
    24 {
       
    25     /**
       
    26      * @see Command
       
    27      */
       
    28     protected function configure()
       
    29     {
       
    30         parent::configure();
       
    31 
       
    32         $this
       
    33             ->setName('fos:user:promote')
       
    34             ->setDescription('Promotes a user by adding a role')
       
    35             ->setHelp(<<<EOT
       
    36 The <info>fos:user:promote</info> command promotes a user by adding a role
       
    37 
       
    38   <info>php app/console fos:user:promote matthieu ROLE_CUSTOM</info>
       
    39   <info>php app/console fos:user:promote --super matthieu</info>
       
    40 EOT
       
    41             );
       
    42     }
       
    43 
       
    44     protected function executeRoleCommand(UserManipulator $manipulator, OutputInterface $output, $username, $super, $role)
       
    45     {
       
    46         if ($super) {
       
    47             $manipulator->promote($username);
       
    48             $output->writeln(sprintf('User "%s" has been promoted as a super administrator.', $username));
       
    49         } else {
       
    50             if ($added = $manipulator->addRole($username, $role)) {
       
    51                 $output->writeln(sprintf('Role "%s" has been added to user "%s".', $role, $username));                              
       
    52             } else {
       
    53                 $output->writeln(sprintf('User "%s" did already have "%s" role.', $username, $role));
       
    54             }
       
    55         }
       
    56     }
       
    57 }