Skip to content

Commit 65c65a0

Browse files
committed
[Console] add ExecuteCommand and ExecuteCommandHandler
1 parent 5e6ea11 commit 65c65a0

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Add support for choosing exit code while handling signal, or to not exit at all
88
* Add `ProgressBar::setPlaceholderFormatter` to set a placeholder attached to a instance, instead of being global.
99
* Add `ReStructuredTextDescriptor`
10+
* Add `ExecuteCommand` and `ExecuteCommandHandler`
1011

1112
6.2
1213
---
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 ExecuteCommand
18+
{
19+
public function __construct(
20+
public readonly array|string $input,
21+
public readonly bool $catchExceptions = false,
22+
) {
23+
}
24+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\Input\ArrayInput;
16+
use Symfony\Component\Console\Input\StringInput;
17+
use Symfony\Component\Console\Output\BufferedOutput;
18+
19+
/**
20+
* @author Kevin Bond <kevinbond@gmail.com>
21+
*/
22+
final class ExecuteCommandHandler
23+
{
24+
public function __construct(private readonly Application $application)
25+
{
26+
}
27+
28+
public function __invoke(ExecuteCommand $message): BufferedOutput
29+
{
30+
$input = is_array($message->input) ? new ArrayInput($message->input) : new StringInput($message->input);
31+
$output = new BufferedOutput();
32+
33+
$this->application->setCatchExceptions($message->catchExceptions);
34+
$this->application->run($input, $output);
35+
36+
return $output;
37+
}
38+
}

src/Symfony/Component/Console/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"symfony/event-dispatcher": "^5.4|^6.0",
2828
"symfony/dependency-injection": "^5.4|^6.0",
2929
"symfony/lock": "^5.4|^6.0",
30+
"symfony/messenger": "^6.3",
3031
"symfony/process": "^5.4|^6.0",
3132
"symfony/var-dumper": "^5.4|^6.0",
3233
"psr/log": "^1|^2|^3"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy