Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7004dc

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: (99 commits) [HttpClient][Messenger] add `PingWebhookMessage` and `PingWebhookMessageHandler` Use Stringable interface as much as possible [Messenger][Process] add `RunProcessMessage` and `RunProcessMessageHandler` Add generics to the progress bar iteration methods [SecurityBundle] Allow an array of `pattern` in firewall configuration [FrameworkBundle] Simplify marking store configuration [PsrHttpMessageBridge] Patch return types and fix CS [PsrHttpMessageBridge] Import the bridge into the monorepo Prepare release 2.3.1 Fix CS Don't rely on Request::getPayload() to populate the parsed body Prepare release 2.3.0 Implement ValueResolverInterface Leverage `Request::getPayload()` to populate the parsed body of PSR-7 requests Add native types where possible cs fix Prepare the 2.2.0 release Bump psr/http-message version Drop support for Symfony 4 Adjustments for PHP CS Fixer 3 ...
2 parents 8d97ce8 + 1276cfe commit b7004dc

File tree

6 files changed

+171
-0
lines changed

6 files changed

+171
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Add `RunProcessMessage` and `RunProcessMessageHandler`
8+
49
5.2.0
510
-----
611

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Process\Exception;
13+
14+
use Symfony\Component\Process\Messenger\RunProcessContext;
15+
16+
/**
17+
* @author Kevin Bond <[email protected]>
18+
*/
19+
final class RunProcessFailedException extends RuntimeException
20+
{
21+
public function __construct(ProcessFailedException $exception, public readonly RunProcessContext $context)
22+
{
23+
parent::__construct($exception->getMessage(), $exception->getCode());
24+
}
25+
}

Messenger/RunProcessContext.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Process\Messenger;
13+
14+
use Symfony\Component\Process\Process;
15+
16+
/**
17+
* @author Kevin Bond <[email protected]>
18+
*/
19+
final class RunProcessContext extends RunProcessMessage
20+
{
21+
public readonly ?int $exitCode;
22+
public readonly ?string $output;
23+
public readonly ?string $errorOutput;
24+
25+
public function __construct(RunProcessMessage $message, Process $process)
26+
{
27+
parent::__construct($message->command, $message->cwd, $message->env, $message->input, $message->timeout);
28+
29+
$this->exitCode = $process->getExitCode();
30+
$this->output = $process->isOutputDisabled() ? null : $process->getOutput();
31+
$this->errorOutput = $process->isOutputDisabled() ? null : $process->getErrorOutput();
32+
}
33+
}

Messenger/RunProcessMessage.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Process\Messenger;
13+
14+
/**
15+
* @author Kevin Bond <[email protected]>
16+
*/
17+
class RunProcessMessage implements \Stringable
18+
{
19+
public function __construct(
20+
public readonly array $command,
21+
public readonly ?string $cwd = null,
22+
public readonly ?array $env = null,
23+
public readonly mixed $input = null,
24+
public readonly ?float $timeout = 60.0,
25+
) {
26+
}
27+
28+
public function __toString(): string
29+
{
30+
return \implode(' ', $this->command);
31+
}
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Process\Messenger;
13+
14+
use Symfony\Component\Process\Exception\ProcessFailedException;
15+
use Symfony\Component\Process\Exception\RunProcessFailedException;
16+
use Symfony\Component\Process\Process;
17+
18+
/**
19+
* @author Kevin Bond <[email protected]>
20+
*/
21+
final class RunProcessMessageHandler
22+
{
23+
public function __invoke(RunProcessMessage $message): RunProcessContext
24+
{
25+
$process = new Process($message->command, $message->cwd, $message->env, $message->input, $message->timeout);
26+
27+
try {
28+
return new RunProcessContext($message, $process->mustRun());
29+
} catch (ProcessFailedException $e) {
30+
throw new RunProcessFailedException($e, new RunProcessContext($message, $e->getProcess()));
31+
}
32+
}
33+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Process\Tests\Messenger;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Process\Exception\RunProcessFailedException;
16+
use Symfony\Component\Process\Messenger\RunProcessMessage;
17+
use Symfony\Component\Process\Messenger\RunProcessMessageHandler;
18+
19+
class RunProcessMessageHandlerTest extends TestCase
20+
{
21+
public function testRunSuccessfulProcess()
22+
{
23+
$context = (new RunProcessMessageHandler())(new RunProcessMessage(['ls'], cwd: __DIR__));
24+
25+
$this->assertSame(['ls'], $context->command);
26+
$this->assertSame(0, $context->exitCode);
27+
$this->assertStringContainsString(basename(__FILE__), $context->output);
28+
}
29+
30+
public function testRunFailedProcess()
31+
{
32+
try {
33+
(new RunProcessMessageHandler())(new RunProcessMessage(['invalid']));
34+
} catch (RunProcessFailedException $e) {
35+
$this->assertSame(['invalid'], $e->context->command);
36+
$this->assertSame(127, $e->context->exitCode);
37+
38+
return;
39+
}
40+
41+
$this->fail('Exception not thrown');
42+
}
43+
}

0 commit comments

Comments
 (0)