ParentRuntime::createProcess()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 3
nc 4
nop 3
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/yii2-async
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace VXM\Async\Runtime;
9
10
use Spatie\Async\Pool;
11
use Spatie\Async\Process\ParallelProcess;
12
use Spatie\Async\Process\Runnable;
13
use Spatie\Async\Process\SynchronousProcess;
14
use Spatie\Async\Runtime\ParentRuntime as BaseParentRuntime;
15
use Symfony\Component\Process\Process;
16
17
/**
18
 * ParentRuntime support invoke console environment in child runtime mode.
19
 *
20
 * @author Vuong Minh <[email protected]>
21
 * @since 1.0.0
22
 */
23
class ParentRuntime extends BaseParentRuntime
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public static function createProcess($task, ?int $outputLength = null, ?string $binary = 'php'): Runnable
29
    {
30
        if (! self::$isInitialised) {
31
            self::init();
32
        }
33
34
        if (! Pool::isSupported()) {
35
            return new SynchronousProcess($task, self::getId());
36
        }
37
38
        $process = new Process([
39
            $binary,
40
            self::$childProcessScript,
41
            self::$autoloader,
42
            self::encodeTask($task),
43
            $outputLength,
44
            base_path(),
45
        ]);
46
47
        return new ParallelProcess($process, self::getId());
48
    }
49
}
50