diff options
Diffstat (limited to 'vendor/symfony/console/Messenger')
3 files changed, 110 insertions, 0 deletions
diff --git a/vendor/symfony/console/Messenger/RunCommandContext.php b/vendor/symfony/console/Messenger/RunCommandContext.php new file mode 100644 index 0000000..2ee5415 --- /dev/null +++ b/vendor/symfony/console/Messenger/RunCommandContext.php | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | /* | ||
| 4 | * This file is part of the Symfony package. | ||
| 5 | * | ||
| 6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
| 7 | * | ||
| 8 | * For the full copyright and license information, please view the LICENSE | ||
| 9 | * file that was distributed with this source code. | ||
| 10 | */ | ||
| 11 | |||
| 12 | namespace Symfony\Component\Console\Messenger; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * @author Kevin Bond <kevinbond@gmail.com> | ||
| 16 | */ | ||
| 17 | final class RunCommandContext | ||
| 18 | { | ||
| 19 | public function __construct( | ||
| 20 | public readonly RunCommandMessage $message, | ||
| 21 | public readonly int $exitCode, | ||
| 22 | public readonly string $output, | ||
| 23 | ) { | ||
| 24 | } | ||
| 25 | } | ||
diff --git a/vendor/symfony/console/Messenger/RunCommandMessage.php b/vendor/symfony/console/Messenger/RunCommandMessage.php new file mode 100644 index 0000000..b530c43 --- /dev/null +++ b/vendor/symfony/console/Messenger/RunCommandMessage.php | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | /* | ||
| 4 | * This file is part of the Symfony package. | ||
| 5 | * | ||
| 6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
| 7 | * | ||
| 8 | * For the full copyright and license information, please view the LICENSE | ||
| 9 | * file that was distributed with this source code. | ||
| 10 | */ | ||
| 11 | |||
| 12 | namespace Symfony\Component\Console\Messenger; | ||
| 13 | |||
| 14 | use Symfony\Component\Console\Exception\RunCommandFailedException; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * @author Kevin Bond <kevinbond@gmail.com> | ||
| 18 | */ | ||
| 19 | class RunCommandMessage implements \Stringable | ||
| 20 | { | ||
| 21 | /** | ||
| 22 | * @param bool $throwOnFailure If the command has a non-zero exit code, throw {@see RunCommandFailedException} | ||
| 23 | * @param bool $catchExceptions @see Application::setCatchExceptions() | ||
| 24 | */ | ||
| 25 | public function __construct( | ||
| 26 | public readonly string $input, | ||
| 27 | public readonly bool $throwOnFailure = true, | ||
| 28 | public readonly bool $catchExceptions = false, | ||
| 29 | ) { | ||
| 30 | } | ||
| 31 | |||
| 32 | public function __toString(): string | ||
| 33 | { | ||
| 34 | return $this->input; | ||
| 35 | } | ||
| 36 | } | ||
diff --git a/vendor/symfony/console/Messenger/RunCommandMessageHandler.php b/vendor/symfony/console/Messenger/RunCommandMessageHandler.php new file mode 100644 index 0000000..1bc4994 --- /dev/null +++ b/vendor/symfony/console/Messenger/RunCommandMessageHandler.php | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | /* | ||
| 4 | * This file is part of the Symfony package. | ||
| 5 | * | ||
| 6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
| 7 | * | ||
| 8 | * For the full copyright and license information, please view the LICENSE | ||
| 9 | * file that was distributed with this source code. | ||
| 10 | */ | ||
| 11 | |||
| 12 | namespace Symfony\Component\Console\Messenger; | ||
| 13 | |||
| 14 | use Symfony\Component\Console\Application; | ||
| 15 | use Symfony\Component\Console\Command\Command; | ||
| 16 | use Symfony\Component\Console\Exception\RunCommandFailedException; | ||
| 17 | use Symfony\Component\Console\Input\StringInput; | ||
| 18 | use Symfony\Component\Console\Output\BufferedOutput; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * @author Kevin Bond <kevinbond@gmail.com> | ||
| 22 | */ | ||
| 23 | final class RunCommandMessageHandler | ||
| 24 | { | ||
| 25 | public function __construct( | ||
| 26 | private readonly Application $application, | ||
| 27 | ) { | ||
| 28 | } | ||
| 29 | |||
| 30 | public function __invoke(RunCommandMessage $message): RunCommandContext | ||
| 31 | { | ||
| 32 | $input = new StringInput($message->input); | ||
| 33 | $output = new BufferedOutput(); | ||
| 34 | |||
| 35 | $this->application->setCatchExceptions($message->catchExceptions); | ||
| 36 | |||
| 37 | try { | ||
| 38 | $exitCode = $this->application->run($input, $output); | ||
| 39 | } catch (\Throwable $e) { | ||
| 40 | throw new RunCommandFailedException($e, new RunCommandContext($message, Command::FAILURE, $output->fetch())); | ||
| 41 | } | ||
| 42 | |||
| 43 | if ($message->throwOnFailure && Command::SUCCESS !== $exitCode) { | ||
| 44 | throw new RunCommandFailedException(sprintf('Command "%s" exited with code "%s".', $message->input, $exitCode), new RunCommandContext($message, $exitCode, $output->fetch())); | ||
| 45 | } | ||
| 46 | |||
| 47 | return new RunCommandContext($message, $exitCode, $output->fetch()); | ||
| 48 | } | ||
| 49 | } | ||
