Skip to content

Commit

Permalink
[Console] add ExecuteCommand and ExecuteCommandHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Mar 25, 2023
1 parent 5e6ea11 commit 65c65a0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Add support for choosing exit code while handling signal, or to not exit at all
* Add `ProgressBar::setPlaceholderFormatter` to set a placeholder attached to a instance, instead of being global.
* Add `ReStructuredTextDescriptor`
* Add `ExecuteCommand` and `ExecuteCommandHandler`

6.2
---
Expand Down
24 changes: 24 additions & 0 deletions src/Symfony/Component/Console/Messenger/ExecuteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Console\Messenger;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
final class ExecuteCommand
{
public function __construct(
public readonly array|string $input,
public readonly bool $catchExceptions = false,
) {
}
}
38 changes: 38 additions & 0 deletions src/Symfony/Component/Console/Messenger/ExecuteCommandHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Console\Messenger;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
final class ExecuteCommandHandler
{
public function __construct(private readonly Application $application)
{
}

public function __invoke(ExecuteCommand $message): BufferedOutput
{
$input = is_array($message->input) ? new ArrayInput($message->input) : new StringInput($message->input);
$output = new BufferedOutput();

$this->application->setCatchExceptions($message->catchExceptions);
$this->application->run($input, $output);

return $output;
}
}
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"symfony/event-dispatcher": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/lock": "^5.4|^6.0",
"symfony/messenger": "^6.3",
"symfony/process": "^5.4|^6.0",
"symfony/var-dumper": "^5.4|^6.0",
"psr/log": "^1|^2|^3"
Expand Down

0 comments on commit 65c65a0

Please sign in to comment.