class TestSiteUserLoginCommand
Same name in other branches
- 9 core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php \Drupal\TestSite\Commands\TestSiteUserLoginCommand
- 10 core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php \Drupal\TestSite\Commands\TestSiteUserLoginCommand
- 11.x core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php \Drupal\TestSite\Commands\TestSiteUserLoginCommand
Command to generate a login link for the test site.
@internal
Hierarchy
- class \Drupal\TestSite\Commands\TestSiteUserLoginCommand extends \Symfony\Component\Console\Command\Command
Expanded class hierarchy of TestSiteUserLoginCommand
1 file declares its use of TestSiteUserLoginCommand
- TestSiteApplication.php in core/
tests/ Drupal/ TestSite/ TestSiteApplication.php
File
-
core/
tests/ Drupal/ TestSite/ Commands/ TestSiteUserLoginCommand.php, line 20
Namespace
Drupal\TestSite\CommandsView source
class TestSiteUserLoginCommand extends Command {
/**
* The class loader to use for installation and initialization of setup.
*
* @var \Symfony\Component\Classloader\Classloader
*/
protected $classLoader;
/**
* {@inheritdoc}
*/
protected function configure() {
$this->setName('user-login')
->setDescription('Generate a one time login link for an user.')
->addArgument('uid', InputArgument::REQUIRED, 'The ID of the user for whom the link will be generated')
->addOption('site-path', NULL, InputOption::VALUE_REQUIRED, 'The path for the test site.');
}
/**
* {@inheritdoc}
*
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
chdir($root);
$this->classLoader = (require 'autoload.php');
$kernel = new DrupalKernel('prod', $this->classLoader, FALSE);
$kernel::bootEnvironment();
$kernel->setSitePath($input->getOption('site-path'));
Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $this->classLoader);
$request = Request::createFromGlobals();
$kernel->boot();
$kernel->preHandle($request);
$container = $kernel->getContainer();
$uid = $input->getArgument('uid');
if (!is_numeric($uid)) {
throw new InvalidArgumentException(sprintf('The "uid" argument needs to be an integer, but it is "%s".', $uid));
}
$userEntity = $container->get('entity_type.manager')
->getStorage('user')
->load($uid);
$url = user_pass_reset_url($userEntity) . '/login';
$output->writeln($url);
return 0;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
TestSiteUserLoginCommand::$classLoader | protected | property | The class loader to use for installation and initialization of setup. |
TestSiteUserLoginCommand::configure | protected | function | |
TestSiteUserLoginCommand::execute | protected | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.