8000 [Console] Add DialogHelper::askHiddenResponse method by romainneutron · Pull Request #5731 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Add DialogHelper::askHiddenResponse method #5731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 16, 2012
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments. 8000
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests and CS
  • Loading branch information
romainneutron committed Oct 12, 2012
commit ac01d5d7524ffcb399af7dd2495748900640809c
28 changes: 19 additions & 9 deletions src/Symfony/Component/Console/Helper/DialogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function askConfirmation(OutputInterface $output, $question, $default = t
public function askHiddenResponse(OutputInterface $output, $question, $fallback = true)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$exe = __DIR__ . '\\hiddeninput.exe';
$exe = __DIR__ . '/hiddeninput.exe';

// handle code running from a phar
if ('phar:' === substr(__FILE__, 0, 5)) {
Expand All @@ -105,15 +105,17 @@ public function askHiddenResponse(OutputInterface $output, $question, $fallback
}

return $value;
} elseif ($this->hasSttyAvailable()) {
}

if ($this->hasSttyAvailable()) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this blank line should be removed.

$output->write($question);

$sttyMode = shell_exec('/usr/bin/env stty -g');

shell_exec('/usr/bin/env stty -echo');
$value = fgets($this->inputStream ?: STDIN, 4096);
shell_exec(sprintf('/usr/bin/env stty %s', escapeshellarg($sttyMode)));
shell_exec(sprintf('/usr/bin/env stty %s', $sttyMode));

if (false === $value) {
throw new \RuntimeException('Aborted');
Expand All @@ -123,7 +125,9 @@ public function askHiddenResponse(OutputInterface $output, $question, $fallback
$output->writeln('');

return $value;
} elseif (false !== $shell = $this->getShell()) {
}

if (false !== $shell = $this->getShell()) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this blank line should be removed.

$output->write($question);
$readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read mypassword';
Expand All @@ -132,7 +136,9 @@ public function askHiddenResponse(OutputInterface $output, $question, $fallback
$output->writeln('');

return $value;
} elseif ($fallback) {
}

if ($fallback) {
return $this->ask($output, $question);
}

Expand All @@ -158,8 +164,10 @@ public function askHiddenResponse(OutputInterface $output, $question, $fallback
*/
public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null)
{
$interviewer = function() use ($output, $question, $default) {
return $this->ask($output, $question, $default);
$that = $this;

$interviewer = function() use ($output, $question, $default, $that) {
return $that->ask($output, $question, $default);
};

return $this->validateAttempts($interviewer, $output, $validator, $attempts);
Expand All @@ -186,8 +194,10 @@ public function askAndValidate(OutputInterface $output, $question, $validator, $
*/
public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true)
{
$interviewer = function() use ($output, $question, $fallback) {
return $this->askHiddenResponse($output, $question, $fallback);
$that = $this;

$interviewer = function() use ($output, $question, $fallback, $that) {
return $that->askHiddenResponse($output, $question, $fallback);
};

return $this->validateAttempts($interviewer, $output, $validator, $attempts);
Expand Down
0