@@ -23,23 +23,30 @@ class ProcessBuilder
23
23
{
24
24
private $ arguments ;
25
25
private $ cwd ;
26
- private $ env ;
26
+ private $ env = array () ;
27
27
private $ stdin ;
28
- private $ timeout ;
29
- private $ options ;
30
- private $ inheritEnv ;
28
+ private $ timeout = 60 ;
29
+ private $ options = array () ;
30
+ private $ inheritEnv = true ;
31
31
private $ prefix ;
32
32
33
+ /**
34
+ * Constructor
35
+ *
36
+ * @param string[] $arguments An array of arguments
37
+ */
33
38
public function __construct (array $ arguments = array ())
34
39
{
35
40
$ this ->arguments = $ arguments ;
36
-
37
- $ this ->timeout = 60 ;
38
- $ this ->options = array ();
39
- $ this ->env = array ();
40
- $ this ->inheritEnv = true ;
41
41
}
42
42
43
+ /**
44
+ * Creates a process builder instance.
45
+ *
46
+ * @param string[] $arguments An array of arguments
47
+ *
48
+ * @return ProcessBuilder
49
+ */
43
50
public static function create (array $ arguments = array ())
44
51
{
45
52
return new static ($ arguments );
@@ -62,7 +69,7 @@ public function add($argument)
62
69
/**
63
70
* Adds an unescaped prefix to the command string.
64
71
*
65
- * The prefix is preserved when reseting arguments.
72
+ * The prefix is preserved when resetting arguments.
66
73
*
67
74
* @param string $prefix A command prefix
68
75
*
@@ -76,7 +83,12 @@ public function setPrefix($prefix)
76
83
}
77
84
78
85
/**
79
- * @param array $arguments
86
+ * Sets the arguments of the process.
87
+ *
88
+ * Arguments must not be escaped.
89
+ * Previous arguments are removed.
90
+ *
91
+ * @param string[] $arguments
80
92
*
81
93
* @return ProcessBuilder
82
94
*/
@@ -87,27 +99,59 @@ public function setArguments(array $arguments)
87
99
return $ this ;
88
100
}
89
101
102
+ /**
103
+ * Sets the working directory.
104
+ *
105
+ * @param null|string $cwd The working directory
106
+ *
107
+ * @return ProcessBuilder
108
+ */
90
109
public function setWorkingDirectory ($ cwd )
91
110
{
92
111
$ this ->cwd = $ cwd ;
93
112
94
113
return $ this ;
95
114
}
96
115
116
+ /**
117
+ * Sets whether environment variables will be inherited or not.
118
+ *
119
+ * @param bool $inheritEnv
120
+ *
121
+ * @return ProcessBuilder
122
+ */
97
123
public function inheritEnvironmentVariables ($ inheritEnv = true )
98
124
{
99
125
$ this ->inheritEnv = $ inheritEnv ;
100
126
101
127
return $ this ;
102
128
}
103
129
130
+ /**
131
+ * Sets an environment variable
132
+ *
133
+ * Setting a variable overrides its previous value. Use `null` to unset a
134
+ * defined environment variable.
135
+ *
136
+ * @param string $name The variable name
137
+ * @param null|string $value The variable value
138
+ *
139
+ * @return ProcessBuilder
140
+ */
104
141
public function setEnv ($ name , $ value )
105
142
{
106
143
$ this ->env [$ name ] = $ value ;
107
144
108
145
return $ this ;
109
146
}
110
147
148
+ /**
149
+ * Sets the input of the process.
150
+ *
151
+ * @param string $stdin The input as a string
152
+ *
153
+ * @return ProcessBuilder
154
+ */
111
155
public function setInput ($ stdin )
112
156
{
113
157
$ this ->stdin = $ stdin ;
@@ -145,13 +189,28 @@ public function setTimeout($timeout)
145
189
return $ this ;
146
190
}
147
191
192
+ /**
193
+ * Adds a proc_open option.
194
+ *
195
+ * @param string $name The option name
196
+ * @param string $value The option value
197
+ *
198
+ * @return ProcessBuilder
199
+ */
148
200
public function setOption ($ name , $ value )
149
201
{
150
202
$ this ->options [$ name ] = $ value ;
151
203
152
204
return $ this ;
153
205
}
154
206
207
+ /**
208
+ * Creates a Process instance and returns it.
209
+ *
210
+ * @return Process
211
+ *
212
+ * @throws LogicException In case no arguments have been provided
213
+ */
155
214
public function getProcess ()
156
215
{
157
216
if (!$ this ->prefix && !count ($ this ->arguments )) {
0 commit comments