Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / User / LoginUrlCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Command\User\LoginUrlCommand.
6  */
7
8 namespace Drupal\Console\Command\User;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Core\Entity\EntityTypeManagerInterface;
16 use Drupal\Console\Core\Style\DrupalStyle;
17
18 /**
19  * Class UserLoginCommand.
20  *
21  * @package Drupal\Console
22  */
23 class LoginUrlCommand extends Command
24 {
25     use CommandTrait;
26
27     /**
28      * @var EntityTypeManagerInterface
29      */
30     protected $entityTypeManager;
31
32     /**
33      * LoginUrlCommand constructor.
34      *
35      * @param EntityTypeManagerInterface $entityTypeManager
36      */
37     public function __construct(EntityTypeManagerInterface $entityTypeManager)
38     {
39         $this->entityTypeManager = $entityTypeManager;
40         parent::__construct();
41     }
42
43     /**
44      * {@inheritdoc}
45      */
46     protected function configure()
47     {
48         $this
49             ->setName('user:login:url')
50             ->setDescription($this->trans('commands.user.login.url.description'))
51             ->addArgument(
52                 'user-id',
53                 InputArgument::REQUIRED,
54                 $this->trans('commands.user.login.url.options.user-id'),
55                 null
56             );
57     }
58
59     /**
60    * {@inheritdoc}
61    */
62     protected function execute(InputInterface $input, OutputInterface $output)
63     {
64         $io = new DrupalStyle($input, $output);
65
66         $uid = $input->getArgument('user-id');
67         $user = $this->entityTypeManager->getStorage('user')->load($uid);
68
69         if (!$user) {
70             $io->error(
71                 sprintf(
72                     $this->trans('commands.user.login.url.errors.invalid-user'),
73                     $uid
74                 )
75             );
76
77             return 1;
78         }
79
80         $url = user_pass_reset_url($user);
81         $io->success(
82             sprintf(
83                 $this->trans('commands.user.login.url.messages.url'),
84                 $user->getUsername(),
85                 $url
86             )
87         );
88     }
89 }