Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
323aa99
commit 71f1acd
Showing
17 changed files
with
676 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Drush\Style; | ||
|
||
use Drush\Drush; | ||
use Drush\Exceptions\UserAbortException; | ||
use Symfony\Component\Console\Question\Question; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class DrushStyle extends SymfonyStyle | ||
{ | ||
public function confirm(string $question, bool $default = true): bool | ||
{ | ||
// Automatically accept confirmations if the --yes argument was supplied. | ||
if (Drush::affirmative()) { | ||
$this->comment($question . ': yes.'); | ||
return true; | ||
} elseif (Drush::negative()) { | ||
// Automatically cancel confirmations if the --no argument was supplied. | ||
$this->warning($question . ': no.'); | ||
return false; | ||
} | ||
return parent::confirm($question, $default); | ||
} | ||
|
||
public function choice(string $question, array $choices, mixed $default = null): mixed | ||
{ | ||
// Display the choices without their keys. | ||
$choices_values = array_values($choices); | ||
$return = parent::choice($question, $choices_values, $default); | ||
|
||
return array_search($return, $choices); | ||
} | ||
|
||
public function warning(string|array $message) | ||
{ | ||
$this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ! ', true); | ||
} | ||
|
||
public function note(string|array $message) | ||
{ | ||
$this->block($message, 'NOTE', 'fg=black;bg=yellow', ' ! '); | ||
} | ||
|
||
public function caution(string|array $message) | ||
{ | ||
$this->block($message, 'CAUTION', 'fg=black;bg=yellow', ' ! ', true); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function askRequired($question) | ||
{ | ||
$question = new Question($question); | ||
$question->setValidator(function (?string $value) { | ||
// FALSE is not considered as empty value because question helper use | ||
// it as negative answer on confirmation questions. | ||
if ($value === null || $value === '') { | ||
throw new \UnexpectedValueException('This value is required.'); | ||
} | ||
|
||
return $value; | ||
}); | ||
|
||
return $this->askQuestion($question); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src-symfony-compatibility/v6/Symfony/BufferedConsoleOutput.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Drush\Symfony; | ||
|
||
use Symfony\Component\Console\Formatter\OutputFormatterInterface; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
use Symfony\Component\Console\Output\ConsoleOutputInterface; | ||
use Symfony\Component\Console\Output\ConsoleSectionOutput; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* BufferedConsoleOutput supports separation of the stdout and stderr streams. | ||
*/ | ||
class BufferedConsoleOutput extends BufferedOutput implements ConsoleOutputInterface | ||
{ | ||
protected $stderr; | ||
private array $consoleSectionOutputs = []; | ||
|
||
/** | ||
* @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) | ||
* @param bool|null $decorated Whether to decorate messages (null for auto-guessing) | ||
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) | ||
*/ | ||
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null) | ||
{ | ||
parent::__construct($verbosity, $decorated, $formatter); | ||
|
||
$this->stderr = new BufferedOutput($this->getVerbosity(), $this->isDecorated(), $this->getFormatter()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getErrorOutput(): OutputInterface | ||
{ | ||
return $this->stderr; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setErrorOutput(OutputInterface $error): void | ||
{ | ||
$this->stderr = $error; | ||
} | ||
|
||
public function section(): ConsoleSectionOutput | ||
{ | ||
// @todo | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src-symfony-compatibility/v6/Symfony/IndiscriminateInputDefinition.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Drush\Symfony; | ||
|
||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* This is an InputDefinition that allows any option to be considered valid. | ||
* Used when passing a command through to another dispatcher that will do | ||
* the option validation. | ||
* | ||
* We use this instead of a LessStrictArgvInput in cases where we do not | ||
* know in advance whether the input should be handled indiscriminately. | ||
* In other words, an IndiscriminateInputDefinition is attached to individual | ||
* Commands that should accept any option, whereas a LessStrictArgvInput | ||
* should be used to make all command skip option validation. | ||
*/ | ||
class IndiscriminateInputDefinition extends InputDefinition | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function hasShortcut(string $name): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function hasOption(string $name): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getOption(string $name): InputOption | ||
{ | ||
if (parent::hasOption($name)) { | ||
return parent::getOption($name); | ||
} | ||
return new InputOption($name, null, InputOption::VALUE_OPTIONAL, '', []); | ||
} | ||
} |
Oops, something went wrong.