-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathProcessContextFactory.php
More file actions
53 lines (48 loc) · 1.79 KB
/
ProcessContextFactory.php
File metadata and controls
53 lines (48 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php declare(strict_types=1);
namespace Amp\Parallel\Context;
use Amp\Cancellation;
use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Parallel\Ipc\IpcHub;
use Amp\Parallel\Ipc\LocalIpcHub;
final class ProcessContextFactory implements ContextFactory
{
use ForbidCloning;
use ForbidSerialization;
/**
* @param string|null $workingDirectory Working directory.
* @param array<string, string> $environment Array of environment variables, or use an empty array to inherit from
* the parent.
* @param string|non-empty-list<string>|null $binary Path to PHP binary or array of binary path and options.
* Null will attempt to automatically locate the binary.
* @param positive-int $childConnectTimeout Number of seconds the child will attempt to connect to the parent
* before failing.
* @param IpcHub $ipcHub Optional IpcHub instance.
*/
public function __construct(
private readonly ?string $workingDirectory = null,
private readonly array $environment = [],
private readonly string|array|null $binary = null,
private readonly int $childConnectTimeout = 5,
private readonly IpcHub $ipcHub = new LocalIpcHub(),
) {
}
/**
* @param string|non-empty-list<string> $script
*
* @throws ContextException
*/
#[\Override]
public function start(string|array $script, ?Cancellation $cancellation = null): ProcessContext
{
return ProcessContext::start(
ipcHub: $this->ipcHub,
script: $script,
workingDirectory: $this->workingDirectory,
environment: $this->environment,
cancellation: $cancellation,
binary: $this->binary,
childConnectTimeout: $this->childConnectTimeout,
);
}
}