1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-22 14:01:14 +01:00

Reorder Process constructor params

Shifted $binary to the end as it should rarely be needed.
This commit is contained in:
Aaron Piotrowski 2017-12-12 21:06:11 -06:00
parent 4d99a9d968
commit 8decdceb5d
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 13 additions and 9 deletions

View File

@ -29,12 +29,14 @@ class Process implements Context {
*
* @param string|array $script Path to PHP script or array with first element as path and following elements options
* to the PHP script (e.g.: ['bin/worker', 'Option1Value', 'Option2Value'].
* @param string|null $cwd Working directory.
* @param mixed[] $env Array of environment variables.
* @param string $binary Path to PHP binary. Null will attempt to automatically locate the binary.
*
* @return \Amp\Parallel\Context\Process
*/
public static function run($script, string $binary = null): self {
$process = new self($script, $binary);
public static function run($script, string $cwd = null, array $env = [], string $binary = null): self {
$process = new self($script, $cwd, $env, $binary);
$process->start();
return $process;
}
@ -42,13 +44,13 @@ class Process implements Context {
/**
* @param string|array $script Path to PHP script or array with first element as path and following elements options
* to the PHP script (e.g.: ['bin/worker', 'Option1Value', 'Option2Value'].
* @param string $binary Path to PHP binary. Null will attempt to automatically locate the binary.
* @param string $cwd Working directory.
* @param string|null $cwd Working directory.
* @param mixed[] $env Array of environment variables.
* @param string $binary Path to PHP binary. Null will attempt to automatically locate the binary.
*
* @throws \Error If the PHP binary path given cannot be found or is not executable.
*/
public function __construct($script, string $binary = null, string $cwd = "", array $env = []) {
public function __construct($script, string $cwd = null, array $env = [], string $binary = null) {
$options = [
"html_errors" => "0",
"display_errors" => "0",

View File

@ -19,10 +19,12 @@ class DefaultWorkerFactory implements WorkerFactory {
*/
public function create(): Worker {
if (Thread::supported()) {
return new WorkerThread;
return new WorkerThread(BasicEnvironment::class);
}
return new WorkerProcess(
BasicEnvironment::class,
[],
\getenv("AMP_PHP_BINARY") ?: (\defined("AMP_PHP_BINARY") ? \AMP_PHP_BINARY : null)
);
}

View File

@ -11,19 +11,19 @@ class WorkerProcess extends AbstractWorker {
const SCRIPT_PATH = __DIR__ . "/Internal/worker-process.php";
/**
* @param string|null $binary Path to PHP binary. Null will attempt to automatically locate the binary.
* @param string $envClassName Name of class implementing \Amp\Parallel\Worker\Environment to instigate.
* Defaults to \Amp\Parallel\Worker\BasicEnvironment.
* @param mixed[] $env Array of environment variables to pass to the worker. Empty array inherits from the current
* PHP process. See the $env parameter of \Amp\Process\Process::__construct().
* @param string|null $binary Path to PHP binary. Null will attempt to automatically locate the binary.
*
* @throws \Error If the PHP binary path given cannot be found or is not executable.
*/
public function __construct(string $binary = null, string $envClassName = BasicEnvironment::class, array $env = []) {
public function __construct(string $envClassName = BasicEnvironment::class, array $env = [], string $binary = null) {
$script = [
self::SCRIPT_PATH,
$envClassName,
];
parent::__construct(new Process($script, $binary, __DIR__, $env));
parent::__construct(new Process($script, null, $env, $binary));
}
}