|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kaliop\eZMigrationBundle\Core\Process; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Process\Exception\LogicException; |
|
6
|
|
|
use Symfony\Component\Process\ProcessBuilder as BaseProcessBuilder; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* All we want is to make the ProcessBuilder return an eZMigrationBundle Process. |
|
10
|
|
|
* Since all the members of the original ProcessBuilder are private, this turns out to be more complex that simply |
|
11
|
|
|
* overriding the getProcess() method |
|
12
|
|
|
*/ |
|
13
|
|
|
class ProcessBuilder extends BaseProcessBuilder |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Creates a Process instance and returns it. |
|
17
|
|
|
* |
|
18
|
|
|
* @return Process |
|
19
|
|
|
* |
|
20
|
|
|
* @throws LogicException In case no arguments have been provided |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getProcess() |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var array $this_prefix */ |
|
25
|
|
|
$this_prefix = \Closure::bind(function(ProcessBuilder $builder){return $builder->prefix;}, null, $this); |
|
|
|
|
|
|
26
|
|
|
/** @var array $this_arguments */ |
|
27
|
|
|
$this_arguments = \Closure::bind(function(ProcessBuilder $builder){return $builder->arguments;}, null, $this); |
|
|
|
|
|
|
28
|
|
|
/** @var array $this_options */ |
|
29
|
|
|
$this_options = \Closure::bind(function(ProcessBuilder $builder){return $builder->options;}, null, $this); |
|
|
|
|
|
|
30
|
|
|
$this_inheritEnv = \Closure::bind(function(ProcessBuilder $builder){return $builder->inheritEnv;}, null, $this); |
|
|
|
|
|
|
31
|
|
|
$this_env = \Closure::bind(function(ProcessBuilder $builder){return $builder->env;}, null, $this); |
|
|
|
|
|
|
32
|
|
|
$this_cwd = \Closure::bind(function(ProcessBuilder $builder){return $builder->cwd;}, null, $this); |
|
|
|
|
|
|
33
|
|
|
$this_input = \Closure::bind(function(ProcessBuilder $builder){return $builder->input;}, null, $this); |
|
|
|
|
|
|
34
|
|
|
$this_timeout = \Closure::bind(function(ProcessBuilder $builder){return $builder->timeout;}, null, $this); |
|
|
|
|
|
|
35
|
|
|
$this_outputDisabled = \Closure::bind(function(ProcessBuilder $builder){return $builder->outputDisabled;}, null, $this); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
if (0 === count($this_prefix) && 0 === count($this_arguments)) { |
|
38
|
|
|
throw new LogicException('You must add() command arguments before calling getProcess().'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$options = $this_options; |
|
42
|
|
|
|
|
43
|
|
|
$arguments = array_merge($this_prefix, $this_arguments); |
|
44
|
|
|
$script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments)); |
|
45
|
|
|
|
|
46
|
|
|
if ($this_inheritEnv) { |
|
|
|
|
|
|
47
|
|
|
// include $_ENV for BC purposes |
|
48
|
|
|
$env = array_replace($_ENV, $_SERVER, $this_env); |
|
|
|
|
|
|
49
|
|
|
} else { |
|
50
|
|
|
$env = $this_env; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$process = new Process($script, $this_cwd, $env, $this_input, $this_timeout, $options); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
if ($this_outputDisabled) { |
|
|
|
|
|
|
56
|
|
|
$process->disableOutput(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $process; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|