Completed
Push — master ( 461219...630231 )
by Harry
04:03
created

ProcessTrait::setProcessFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Helper\Process;
15
16
use Graze\DataFile\Helper\Builder\BuilderTrait;
17
use Psr\Log\LogLevel;
18
use RuntimeException;
19
use Symfony\Component\Process\Process;
20
21
trait ProcessTrait
22
{
23
    use BuilderTrait;
24
25
    /**
26
     * @param string         $commandline The command line to run
27
     * @param string|null    $cwd         The working directory or null to use the working dir of the current PHP
28
     *                                    process
29
     * @param array|null     $env         The environment variables or null to inherit
30
     * @param string|null    $input       The input
31
     * @param int|float|null $timeout     The timeout in seconds or null to disable
32
     * @param array          $options     An array of options for proc_open
33
     *
34
     * @return Process
35
     * @throws RuntimeException When proc_open is not installed
36
     */
37 65
    public function getProcess(
38
        $commandline,
39
        $cwd = null,
40
        array $env = null,
41
        $input = null,
42
        $timeout = 60,
43
        array $options = []
44
    ) {
45 65
        $this->log(LogLevel::DEBUG, "Running command: {cmd}", ['cmd' => $commandline]);
46 65
        return $this->getBuilder()->build(Process::class, $commandline, $cwd, $env, $input, $timeout, $options);
47
    }
48
49
    /**
50
     * Abstract Log function that might should be handed by the OptionalLoggerTrait or similar
51
     *
52
     * @param string $level
53
     * @param string $message
54
     * @param array  $context
55
     *
56
     * @return void
57
     */
58
    abstract protected function log($level, $message, array $context = []);
59
}
60