Fix some todos dropping support for older Symfony releases
parent
efa08e7791
commit
5805a68645
|
@ -13,8 +13,6 @@ parameters:
|
||||||
- '../tests/Composer/Test/Autoload/Fixtures/*'
|
- '../tests/Composer/Test/Autoload/Fixtures/*'
|
||||||
- '../tests/Composer/Test/Plugin/Fixtures/*'
|
- '../tests/Composer/Test/Plugin/Fixtures/*'
|
||||||
- '../tests/Composer/Test/PolyfillTestCase.php'
|
- '../tests/Composer/Test/PolyfillTestCase.php'
|
||||||
# TODO Remove in 2.3
|
|
||||||
- '../src/Composer/Console/HtmlOutputFormatter.php'
|
|
||||||
|
|
||||||
reportUnmatchedIgnoredErrors: false
|
reportUnmatchedIgnoredErrors: false
|
||||||
|
|
||||||
|
|
|
@ -266,13 +266,7 @@ abstract class BaseCommand extends Command
|
||||||
$renderer = new Table($output);
|
$renderer = new Table($output);
|
||||||
$renderer->setStyle('compact');
|
$renderer->setStyle('compact');
|
||||||
$rendererStyle = $renderer->getStyle();
|
$rendererStyle = $renderer->getStyle();
|
||||||
if (method_exists($rendererStyle, 'setVerticalBorderChars')) {
|
$rendererStyle->setVerticalBorderChars('');
|
||||||
$rendererStyle->setVerticalBorderChars('');
|
|
||||||
} else {
|
|
||||||
// TODO remove in composer 2.2
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
$rendererStyle->setVerticalBorderChar('');
|
|
||||||
}
|
|
||||||
$rendererStyle->setCellRowContentFormat('%s ');
|
$rendererStyle->setCellRowContentFormat('%s ');
|
||||||
$renderer->setRows($table)->render();
|
$renderer->setRows($table)->render();
|
||||||
}
|
}
|
||||||
|
@ -282,20 +276,9 @@ abstract class BaseCommand extends Command
|
||||||
*/
|
*/
|
||||||
protected function getTerminalWidth()
|
protected function getTerminalWidth()
|
||||||
{
|
{
|
||||||
if (class_exists('Symfony\Component\Console\Terminal')) {
|
$terminal = new Terminal();
|
||||||
$terminal = new Terminal();
|
$width = $terminal->getWidth();
|
||||||
$width = $terminal->getWidth();
|
|
||||||
} else {
|
|
||||||
// For versions of Symfony console before 3.2
|
|
||||||
// TODO remove in composer 2.2
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
list($width) = $this->getApplication()->getTerminalDimensions();
|
|
||||||
}
|
|
||||||
if (null === $width) {
|
|
||||||
// In case the width is not detected, we're probably running the command
|
|
||||||
// outside of a real terminal, use space without a limit
|
|
||||||
$width = PHP_INT_MAX;
|
|
||||||
}
|
|
||||||
if (Platform::isWindows()) {
|
if (Platform::isWindows()) {
|
||||||
$width--;
|
$width--;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -731,13 +731,7 @@ EOT
|
||||||
$finder = new ExecutableFinder();
|
$finder = new ExecutableFinder();
|
||||||
$gitBin = $finder->find('git');
|
$gitBin = $finder->find('git');
|
||||||
|
|
||||||
// TODO in v2.3 always call with an array
|
$cmd = new Process(array($gitBin, 'config', '-l'));
|
||||||
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) {
|
|
||||||
$cmd = new Process(array($gitBin, 'config', '-l'));
|
|
||||||
} else {
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
$cmd = new Process(sprintf('%s config -l', ProcessExecutor::escape($gitBin)));
|
|
||||||
}
|
|
||||||
$cmd->run();
|
$cmd->run();
|
||||||
|
|
||||||
if ($cmd->isSuccessful()) {
|
if ($cmd->isSuccessful()) {
|
||||||
|
|
|
@ -85,13 +85,7 @@ EOT
|
||||||
$table = new Table($output);
|
$table = new Table($output);
|
||||||
$table->setStyle('compact');
|
$table->setStyle('compact');
|
||||||
$tableStyle = $table->getStyle();
|
$tableStyle = $table->getStyle();
|
||||||
if (method_exists($tableStyle, 'setVerticalBorderChars')) {
|
$tableStyle->setVerticalBorderChars('');
|
||||||
$tableStyle->setVerticalBorderChars('');
|
|
||||||
} else {
|
|
||||||
// TODO remove in composer 2.2
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
$tableStyle->setVerticalBorderChar('');
|
|
||||||
}
|
|
||||||
$tableStyle->setCellRowContentFormat('%s ');
|
$tableStyle->setCellRowContentFormat('%s ');
|
||||||
$table->setHeaders(array('Name', 'Version', 'License'));
|
$table->setHeaders(array('Name', 'Version', 'License'));
|
||||||
foreach ($packages as $package) {
|
foreach ($packages as $package) {
|
||||||
|
|
|
@ -64,13 +64,7 @@ class Compiler
|
||||||
$this->versionDate = new \DateTime(trim($process->getOutput()));
|
$this->versionDate = new \DateTime(trim($process->getOutput()));
|
||||||
$this->versionDate->setTimezone(new \DateTimeZone('UTC'));
|
$this->versionDate->setTimezone(new \DateTimeZone('UTC'));
|
||||||
|
|
||||||
// TODO in v2.3 always call with an array
|
$process = new Process(array('git', 'describe', '--tags', '--exact-match', 'HEAD'), __DIR__);
|
||||||
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) {
|
|
||||||
$process = new Process(array('git', 'describe', '--tags', '--exact-match', 'HEAD'), __DIR__);
|
|
||||||
} else {
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
$process = new Process('git describe --tags --exact-match HEAD');
|
|
||||||
}
|
|
||||||
if ($process->run() == 0) {
|
if ($process->run() == 0) {
|
||||||
$this->version = trim($process->getOutput());
|
$this->version = trim($process->getOutput());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -440,8 +440,7 @@ class Application extends BaseApplication
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
if ($required) {
|
if ($required) {
|
||||||
$this->io->writeError($e->getMessage());
|
$this->io->writeError($e->getMessage());
|
||||||
// TODO composer 2.3 simplify to $this->areExceptionsCaught()
|
if ($this->areExceptionsCaught()) {
|
||||||
if (!method_exists($this, 'areExceptionsCaught') || $this->areExceptionsCaught()) {
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
namespace Composer\Console;
|
namespace Composer\Console;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
use Composer\Pcre\Preg;
|
use Composer\Pcre\Preg;
|
||||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||||
|
@ -64,18 +65,19 @@ class HtmlOutputFormatter extends OutputFormatter
|
||||||
{
|
{
|
||||||
$formatted = parent::format($message);
|
$formatted = parent::format($message);
|
||||||
|
|
||||||
|
if ($formatted === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$clearEscapeCodes = '(?:39|49|0|22|24|25|27|28)';
|
$clearEscapeCodes = '(?:39|49|0|22|24|25|27|28)';
|
||||||
|
|
||||||
// TODO in 2.3 replace with Closure::fromCallable and then use Preg::replaceCallback
|
return Preg::replaceCallback("{\033\[([0-9;]+)m(.*?)\033\[(?:".$clearEscapeCodes.";)*?".$clearEscapeCodes."m}s", Closure::fromCallable([$this, 'formatHtml']), $formatted);
|
||||||
return preg_replace_callback("{\033\[([0-9;]+)m(.*?)\033\[(?:".$clearEscapeCodes.";)*?".$clearEscapeCodes."m}s", array($this, 'formatHtml'), $formatted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string[] $matches
|
* @param string[] $matches
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
private function formatHtml($matches)
|
private function formatHtml(array $matches): string
|
||||||
{
|
{
|
||||||
$out = '<span style="';
|
$out = '<span style="';
|
||||||
foreach (explode(';', $matches[1]) as $code) {
|
foreach (explode(';', $matches[1]) as $code) {
|
||||||
|
|
|
@ -323,18 +323,10 @@ class EventDispatcher
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) { // TODO Composer 2.2 turn all this into a finally
|
} finally {
|
||||||
$this->popEvent();
|
$this->popEvent();
|
||||||
|
|
||||||
throw $e;
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
$this->popEvent();
|
|
||||||
|
|
||||||
throw $e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->popEvent();
|
|
||||||
|
|
||||||
return $returnMax;
|
return $returnMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -518,13 +518,7 @@ class Perforce
|
||||||
{
|
{
|
||||||
$command = $this->generateP4Command(' login -a');
|
$command = $this->generateP4Command(' login -a');
|
||||||
|
|
||||||
// TODO in v3 generate command as an array
|
$process = Process::fromShellCommandline($command, null, null, $password);
|
||||||
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) {
|
|
||||||
$process = Process::fromShellCommandline($command, null, null, $password);
|
|
||||||
} else {
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
$process = new Process($command, null, null, $password);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $process->run();
|
return $process->run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,16 +115,6 @@ class ProcessExecutor
|
||||||
$this->io->writeError('Executing command ('.($cwd ?: 'CWD').'): '.$safeCommand);
|
$this->io->writeError('Executing command ('.($cwd ?: 'CWD').'): '.$safeCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO in 2.2, these two checks can be dropped as Symfony 4+ supports them out of the box
|
|
||||||
// make sure that null translate to the proper directory in case the dir is a symlink
|
|
||||||
// and we call a git command, because msysgit does not handle symlinks properly
|
|
||||||
if (null === $cwd && Platform::isWindows() && false !== strpos($command, 'git') && getcwd()) {
|
|
||||||
$cwd = realpath(getcwd());
|
|
||||||
}
|
|
||||||
if (null !== $cwd && !is_dir($cwd)) {
|
|
||||||
throw new \RuntimeException('The given CWD for the process does not exist: '.$cwd);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->captureOutput = func_num_args() > 3;
|
$this->captureOutput = func_num_args() > 3;
|
||||||
$this->errorOutput = '';
|
$this->errorOutput = '';
|
||||||
|
|
||||||
|
@ -181,8 +171,6 @@ class ProcessExecutor
|
||||||
$job['reject'] = $reject;
|
$job['reject'] = $reject;
|
||||||
};
|
};
|
||||||
|
|
||||||
$self = $this;
|
|
||||||
|
|
||||||
$canceler = function () use (&$job) {
|
$canceler = function () use (&$job) {
|
||||||
if ($job['status'] === ProcessExecutor::STATUS_QUEUED) {
|
if ($job['status'] === ProcessExecutor::STATUS_QUEUED) {
|
||||||
$job['status'] = ProcessExecutor::STATUS_ABORTED;
|
$job['status'] = ProcessExecutor::STATUS_ABORTED;
|
||||||
|
@ -204,21 +192,20 @@ class ProcessExecutor
|
||||||
};
|
};
|
||||||
|
|
||||||
$promise = new Promise($resolver, $canceler);
|
$promise = new Promise($resolver, $canceler);
|
||||||
$promise = $promise->then(function () use (&$job, $self) {
|
$promise = $promise->then(function () use (&$job) {
|
||||||
if ($job['process']->isSuccessful()) {
|
if ($job['process']->isSuccessful()) {
|
||||||
$job['status'] = ProcessExecutor::STATUS_COMPLETED;
|
$job['status'] = ProcessExecutor::STATUS_COMPLETED;
|
||||||
} else {
|
} else {
|
||||||
$job['status'] = ProcessExecutor::STATUS_FAILED;
|
$job['status'] = ProcessExecutor::STATUS_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 3.0 this should be done directly on $this when PHP 5.3 is dropped
|
$this->markJobDone();
|
||||||
$self->markJobDone();
|
|
||||||
|
|
||||||
return $job['process'];
|
return $job['process'];
|
||||||
}, function ($e) use (&$job, $self) {
|
}, function ($e) use (&$job) {
|
||||||
$job['status'] = ProcessExecutor::STATUS_FAILED;
|
$job['status'] = ProcessExecutor::STATUS_FAILED;
|
||||||
|
|
||||||
$self->markJobDone();
|
$this->markJobDone();
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
});
|
});
|
||||||
|
@ -261,16 +248,6 @@ class ProcessExecutor
|
||||||
$this->io->writeError('Executing async command ('.($cwd ?: 'CWD').'): '.$safeCommand);
|
$this->io->writeError('Executing async command ('.($cwd ?: 'CWD').'): '.$safeCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO in 2.2, these two checks can be dropped as Symfony 4+ supports them out of the box
|
|
||||||
// make sure that null translate to the proper directory in case the dir is a symlink
|
|
||||||
// and we call a git command, because msysgit does not handle symlinks properly
|
|
||||||
if (null === $cwd && Platform::isWindows() && false !== strpos($command, 'git') && getcwd()) {
|
|
||||||
$cwd = realpath(getcwd());
|
|
||||||
}
|
|
||||||
if (null !== $cwd && !is_dir($cwd)) {
|
|
||||||
throw new \RuntimeException('The given CWD for the process does not exist: '.$cwd);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO in v3, commands should be passed in as arrays of cmd + args
|
// TODO in v3, commands should be passed in as arrays of cmd + args
|
||||||
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) {
|
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) {
|
||||||
|
|
|
@ -85,13 +85,7 @@ class AllFunctionalTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO in v2.3 always call with an array
|
$proc = new Process([PHP_BINARY, '-dphar.readonly=0', './bin/compile'], $target);
|
||||||
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) {
|
|
||||||
$proc = new Process(array((defined('PHP_BINARY') ? PHP_BINARY : 'php'), '-dphar.readonly=0', './bin/compile'), $target);
|
|
||||||
} else {
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
$proc = new Process((defined('PHP_BINARY') ? escapeshellcmd(PHP_BINARY) : 'php').' -dphar.readonly=0 '.escapeshellarg('./bin/compile'), $target);
|
|
||||||
}
|
|
||||||
$exitcode = $proc->run();
|
$exitcode = $proc->run();
|
||||||
|
|
||||||
if ($exitcode !== 0 || trim($proc->getOutput())) {
|
if ($exitcode !== 0 || trim($proc->getOutput())) {
|
||||||
|
|
Loading…
Reference in New Issue