Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/ChildProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ public function start(
?array $env = null,
bool $persistent = false
): static {
$cmd = $this->ensureCmdIsAnIndexedArray($cmd);

$process = $this->client->post('child-process/start', [
'alias' => $alias,
'cmd' => (array) $cmd,
'cmd' => $cmd,
'cwd' => $cwd ?? base_path(),
'env' => $env,
'persistent' => $persistent,
Expand All @@ -72,9 +73,11 @@ public function start(

public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
{
$cmd = $this->ensureCmdIsAnIndexedArray($cmd);

$process = $this->client->post('child-process/start-php', [
'alias' => $alias,
'cmd' => (array) $cmd,
'cmd' => $cmd,
'cwd' => $cwd ?? base_path(),
'env' => $env,
'persistent' => $persistent,
Expand Down Expand Up @@ -132,4 +135,15 @@ protected function fromRuntimeProcess($process): static

return $this;
}

protected function ensureCmdIsAnIndexedArray(string|array $cmd): array
{
if (is_string($cmd)) {
return [$cmd];
}

if (array_keys($cmd) !== range(0, count($cmd) - 1)) {
throw new \InvalidArgumentException('Only indexed arrays are supported for the cmd: argument.');
}
}
}
Loading