| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Console\Tester; |
| 13 |
|
| 14 |
use Symfony\Component\Console\Application; |
| 15 |
use Symfony\Component\Console\Input\ArrayInput; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
class ApplicationTester |
| 28 |
{ |
| 29 |
use TesterTrait; |
| 30 |
|
| 31 |
public function __construct( |
| 32 |
private Application $application, |
| 33 |
) { |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function run(array $input, array $options = []): int |
| 49 |
{ |
| 50 |
$this->input = new ArrayInput($input); |
| 51 |
if (isset($options['interactive'])) { |
| 52 |
$this->input->setInteractive($options['interactive']); |
| 53 |
} |
| 54 |
|
| 55 |
if ($this->inputs) { |
| 56 |
$this->input->setStream(self::createStream($this->inputs)); |
| 57 |
} |
| 58 |
|
| 59 |
$this->initOutput($options); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
$prevShellVerbosity = [getenv('SHELL_VERBOSITY'), $_ENV['SHELL_VERBOSITY'] ?? false, $_SERVER['SHELL_VERBOSITY'] ?? false]; |
| 64 |
if (\function_exists('putenv')) { |
| 65 |
@putenv('SHELL_VERBOSITY'); |
| 66 |
} |
| 67 |
unset($_ENV['SHELL_VERBOSITY'], $_SERVER['SHELL_VERBOSITY']); |
| 68 |
|
| 69 |
try { |
| 70 |
return $this->statusCode = $this->application->run($this->input, $this->output); |
| 71 |
} finally { |
| 72 |
if (false !== $prevShellVerbosity[0]) { |
| 73 |
if (\function_exists('putenv')) { |
| 74 |
@putenv('SHELL_VERBOSITY='.$prevShellVerbosity[0]); |
| 75 |
} |
| 76 |
} |
| 77 |
if (false !== $prevShellVerbosity[1]) { |
| 78 |
$_ENV['SHELL_VERBOSITY'] = $prevShellVerbosity[1]; |
| 79 |
} |
| 80 |
if (false !== $prevShellVerbosity[2]) { |
| 81 |
$_SERVER['SHELL_VERBOSITY'] = $prevShellVerbosity[2]; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} |