Skip to content

Commit 98405ae

Browse files
authored
fix: child process cmd: option except iterable array (#429)
* fix: child process cmd: option except iterable array TypeError: settings.cmd is not iterable at startPhpProcess * fix: throw an exception if $cmd is not an indexed array * fix: array_values but with a hint for static analyzer
1 parent 7b90969 commit 98405ae

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/ChildProcess.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,22 @@ public function all(): array
5252
return $hydrated;
5353
}
5454

55+
/**
56+
* @param string|string[] $cmd
57+
* @return $this
58+
*/
5559
public function start(
5660
string|array $cmd,
5761
string $alias,
5862
?string $cwd = null,
5963
?array $env = null,
6064
bool $persistent = false
6165
): static {
66+
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
6267

6368
$process = $this->client->post('child-process/start', [
6469
'alias' => $alias,
65-
'cmd' => (array) $cmd,
70+
'cmd' => $cmd,
6671
'cwd' => $cwd ?? base_path(),
6772
'env' => $env,
6873
'persistent' => $persistent,
@@ -71,11 +76,17 @@ public function start(
7176
return $this->fromRuntimeProcess($process);
7277
}
7378

79+
/**
80+
* @param string|string[] $cmd
81+
* @return $this
82+
*/
7483
public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
7584
{
85+
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
86+
7687
$process = $this->client->post('child-process/start-php', [
7788
'alias' => $alias,
78-
'cmd' => (array) $cmd,
89+
'cmd' => $cmd,
7990
'cwd' => $cwd ?? base_path(),
8091
'env' => $env,
8192
'persistent' => $persistent,
@@ -84,9 +95,15 @@ public function php(string|array $cmd, string $alias, ?array $env = null, ?bool
8495
return $this->fromRuntimeProcess($process);
8596
}
8697

98+
/**
99+
* @param string|string[] $cmd
100+
* @return $this
101+
*/
87102
public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
88103
{
89-
$cmd = ['artisan', ...(array) $cmd];
104+
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
105+
106+
$cmd = ['artisan', ...$cmd];
90107

91108
return $this->php($cmd, $alias, env: $env, persistent: $persistent);
92109
}

0 commit comments

Comments
 (0)