Skip to content

Commit

Permalink
fix: throw an exception if $cmd is not an indexed array
Browse files Browse the repository at this point in the history
  • Loading branch information
SRWieZ committed Nov 22, 2024
1 parent ededd88 commit e07c964
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ChildProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function start(
?array $env = null,
bool $persistent = false
): static {
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
$cmd = $this->ensureCmdIsAnIndexedArray($cmd);

$process = $this->client->post('child-process/start', [
'alias' => $alias,
Expand All @@ -73,8 +73,8 @@ public function start(

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

$process = $this->client->post('child-process/start-php', [
'alias' => $alias,
'cmd' => $cmd,
Expand Down Expand Up @@ -135,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.');
}
}
}

0 comments on commit e07c964

Please sign in to comment.