vendor\project-biz\portal-bundle\src\Command\Command.php line 13

Open in your IDE?
  1. <?php
  2. namespace ProjectBiz\PortalBundle\Command;
  3. use Symfony\Component\DependencyInjection\ContainerInterface;
  4. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  5. /**
  6.  * Base class for commands to provide the loginUser() function.
  7.  */
  8. class Command extends \Symfony\Component\Console\Command\Command {
  9.     public function __construct(
  10.         \Swift_Mailer $mailer,
  11.         ContainerInterface $container
  12.     )
  13.     {
  14.         $this->mailer    $mailer;
  15.         $this->container $container;
  16.         parent::__construct();
  17.     }
  18.     protected function loginUser($username)
  19.     {
  20.         $userProvider $this->container->get('projectbiz.user.user_provider');
  21.         $user         $userProvider->loadUserByUsername($username);
  22.         // create the authentication token
  23.         $token = new UsernamePasswordToken(
  24.             $user,
  25.             null,
  26.             'main',
  27.             $user->getRoles()
  28.         );
  29.         // give it to the security context
  30.         $this->container->get('security.token_storage')->setToken($token);
  31.         return $user;
  32.     }
  33. }