Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 414ff23

Browse files
committed
allow to pass unespaced arg to bench cmd
1 parent 36b1695 commit 414ff23

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

‎benchmark/shared.php‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<?php
22

3-
class ProcessResult {
4-
public $stdout;
5-
public $stderr;
3+
readonly class ProcessResult {
4+
public function __construct(
5+
public string $stdout,
6+
public string $stderr,
7+
) {}
8+
}
9+
10+
readonly class UnescapedArg {
11+
public function __construct(
12+
public string $arg,
13+
) {}
614
}
715

816
function runCommand(array $args, ?string $cwd = null): ProcessResult {
9-
$cmd = implode('', array_map('escapeshellarg', $args));
17+
$cmd = implode('', array_map(function (string|UnescapedArg $v): string {
18+
return $v instanceof UnescapedArg
19+
? $v->arg
20+
: escapeshellarg($v);
21+
}, $args));
1022
$pipes = null;
11-
$result = new ProcessResult();
1223
$descriptorSpec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
1324
fwrite(STDOUT, "> $cmd\n");
1425
$processHandle = proc_open($cmd, $descriptorSpec, $pipes, $cwd ?? getcwd(), null);
@@ -22,6 +33,8 @@ function runCommand(array $args, ?string $cwd = null): ProcessResult {
2233
stream_set_blocking($stdout, false);
2334
stream_set_blocking($stderr, false);
2435

36+
$stdoutStr = '';
37+
$stderrStr = '';
2538
$stdoutEof = false;
2639
$stderrEof = false;
2740

@@ -35,9 +48,9 @@ function runCommand(array $args, ?string $cwd = null): ProcessResult {
3548
foreach ($read as $stream) {
3649
$chunk = fgets($stream);
3750
if ($stream === $stdout) {
38-
$result->stdout .= $chunk;
51+
$stdoutStr .= $chunk;
3952
} elseif ($stream === $stderr) {
40-
$result->stderr .= $chunk;
53+
$stderrStr .= $chunk;
4154
}
4255
}
4356

@@ -47,6 +60,8 @@ function runCommand(array $args, ?string $cwd = null): ProcessResult {
4760

4861
fclose($stdout);
4962
fclose($stderr);
63+
64+
$result = new ProcessResult($stdoutStr, $stderrStr);
5065

5166
$statusCode = proc_close($processHandle);
5267
if ($statusCode !== 0) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /