本文整理匯總了PHP中Symfony\Component\Console\Helper\DialogHelper::askHiddenResponse方法的典型用法代碼示例。如果您正苦於以下問題:PHP DialogHelper::askHiddenResponse方法的具體用法?PHP DialogHelper::askHiddenResponse怎麽用?PHP DialogHelper::askHiddenResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Console\Helper\DialogHelper
的用法示例。
在下文中一共展示了DialogHelper::askHiddenResponse方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: askAuth
public function askAuth()
{
$dialog = new DialogHelper();
self::$user = $dialog->ask($this->getOutput(), "<question>GitHub User</question> ");
self::$pass = $dialog->askHiddenResponse($this->getOutput(), " <question>Password</question> ");
return $this;
}
示例2: getDbService
/**
* Create DbService instance based on CLI options, prompt for pass
* @param InputInterface $input
* @param OutputInterface $output
* @return DbService
*/
private function getDbService(InputInterface $input, OutputInterface $output)
{
$base = $input->getOption('base');
if (!$base) {
$output->writeln('<error>Missing base DB name</error>');
return null;
}
$this->arguments['base'] = $base;
$this->arguments['host'] = $input->getOption('host');
$this->arguments['username'] = $input->getOption('username');
$this->arguments['file'] = $input->getOption('file');
$this->arguments['password'] = (string) $this->dialog->askHiddenResponse($output, '<question>Please enter the DB password (default "")</question>', $this->arguments['password']);
$target = $input->getOption('target');
$schemaFile = null;
if (!$target) {
$target = 'compare_' . date('YmdHis');
$output->writeln(sprintf('<info>Missing target DB name - creating schema %s</info>', $target));
$schemaFile = $this->dialog->ask($output, '<question>File to create base schema</question>', null);
if (!$schemaFile || !file_exists($schemaFile)) {
$output->writeln(sprintf('<error>Invalid schema file: %s</error>', $schemaFile));
return null;
}
}
$this->arguments['target'] = $target;
$service = new DbService($this->arguments['host'], $this->arguments['username'], $this->arguments['password'], $this->arguments['base'], $this->arguments['target']);
$this->dropSchema = $schemaFile !== null;
//ensure schemas exist, create target schema if required
$service->checkSchemas($this->dropSchema);
if ($schemaFile) {
$service->loadTargetSchema($schemaFile);
}
return $service;
}
示例3: testAskHiddenResponse
public function testAskHiddenResponse()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('This test is not supported on Windows');
}
$dialog = new DialogHelper();
$dialog->setInputStream($this->getInputStream("8AM\n"));
$this->assertEquals('8AM', $dialog->askHiddenResponse($this->getOutputStream(), 'What time is it?'));
}
示例4: getDbService
/**
* Create DbService instance based on CLI options, prompt for pass
* @param InputInterface $input
* @param OutputInterface $output
* @return DbService
*/
private function getDbService(InputInterface $input, OutputInterface $output)
{
$base = $input->getOption('base');
if (!$base) {
$output->writeln('<error>Missing base DB name</error>');
return null;
}
$target = $input->getOption('target');
if (!$target) {
$output->writeln('<error>Missing target DB name</error>');
return null;
}
$host = $input->getOption('host');
$user = $input->getOption('username');
$pass = (string) $this->dialog->askHiddenResponse($output, '<question>Please enter the DB password (default "")</question>', false);
return new DbService($host, $user, $pass, $base, $target);
}
示例5: testAskHiddenResponse
/**
* @group tty
*/
public function testAskHiddenResponse()
{
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test is not supported on Windows');
}
$dialog = new DialogHelper();
$dialog->setInputStream($this->getInputStream("8AM\n"));
$this->assertEquals('8AM', $dialog->askHiddenResponse($this->getOutputStream(), 'What time is it?'));
}
示例6: createAdminUser
/**
* @param OutputInterface $output
* @param DialogHelper $dialog
*/
protected function createAdminUser(OutputInterface $output, DialogHelper $dialog)
{
// Try to create a user account:
$adminEmail = $dialog->askAndValidate($output, 'Your email address: ', function ($answer) {
if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
throw new Exception('Must be a valid email address.');
}
return $answer;
}, false);
$adminPass = $dialog->askHiddenResponse($output, 'Enter your desired admin password: ');
$adminName = $dialog->ask($output, 'Enter your name: ');
try {
$user = new User();
$user->setEmail($adminEmail);
$user->setName($adminName);
$user->setIsAdmin(1);
$user->setHash(password_hash($adminPass, PASSWORD_DEFAULT));
$this->reloadConfig();
$store = Factory::getStore('User');
$store->save($user);
$output->writeln('<info>User account created!</info>');
} catch (\Exception $ex) {
$output->writeln('<error>PHPCI failed to create your admin account.</error>');
$output->writeln('<error>' . $ex->getMessage() . '</error>');
die;
}
}
示例7: getCredentials
private function getCredentials(InputInterface $input, OutputInterface $output, DialogHelper $dialog)
{
$email = $password = null;
if (!$input->getOption('email') && !$input->getOption('password')) {
$output->writeln("\n<info>--- Account Informations ---</info>\n");
do {
$email = $dialog->ask($output, 'Please provide a valid e-mail address : ');
} while (!\Swift_Validate::email($email));
do {
$password = $dialog->askHiddenResponse($output, 'Please provide a password (hidden, 6 character min) : ');
} while (strlen($password) < 6);
$output->writeln("\n\t<info>Email / Password successfully set</info>\n");
} elseif ($input->getOption('email') && $input->getOption('password')) {
if (!\Swift_Validate::email($input->getOption('email'))) {
throw new \RuntimeException('Invalid email addess');
}
$email = $input->getOption('email');
$password = $input->getOption('password');
} else {
throw new \RuntimeException('You have to provide both email and password');
}
return [$email, $password];
}
示例8: askHiddenResponse
/**
* @inheritdoc
*/
public function askHiddenResponse($question, $fallback = true)
{
return parent::askHiddenResponse($this->output, $this->formatQuestion($question), $fallback);
}
示例9: testAskHiddenResponseOnErrorOutput
/**
* @group tty
*/
public function testAskHiddenResponseOnErrorOutput()
{
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test is not supported on Windows');
}
$dialog = new DialogHelper();
$dialog->setInputStream($this->getInputStream("8AM\n"));
$this->assertEquals('8AM', $dialog->askHiddenResponse($output = $this->getConsoleOutput($this->getOutputStream()), 'What time is it?'));
rewind($output->getErrorOutput()->getStream());
$this->assertContains('What time is it?', stream_get_contents($output->getErrorOutput()->getStream()));
}