Skip to content
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

Drush 10 / Symfony 6 compatibility #5108

Merged
merged 1 commit into from Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -34,7 +34,7 @@
"ext-dom": "*",
"chi-teck/drupal-code-generator": "^2.4",
"composer/semver": "^1.4 || ^3",
"consolidation/annotated-command": "^4.5",
"consolidation/annotated-command": "^4.5.3",
"consolidation/config": "^2",
"consolidation/filter-via-dot-access-data": "^2",
"consolidation/robo": "^3.0.9",
Expand Down
201 changes: 99 additions & 102 deletions composer.lock

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions src-symfony-compatibility/v6/Style/DrushStyle.php
@@ -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 src-symfony-compatibility/v6/Symfony/BufferedConsoleOutput.php
@@ -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
}
}
@@ -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, '', []);
}
}