@@ -60,7 +60,7 @@ class Command
60
60
public $ locale ;
61
61
62
62
/**
63
- * @var string to pipe to standard input
63
+ * @var null| string|resource to pipe to standard input
64
64
*/
65
65
protected $ _stdIn ;
66
66
@@ -159,7 +159,7 @@ public function setCommand($command)
159
159
} elseif (isset ($ command [2 ]) && $ command [2 ]===': ' ) {
160
160
$ position = 2 ;
161
161
} else {
162
- $ position = false ;
162
+ $ position = false ;
163
163
}
164
164
165
165
// Absolute path. If it's a relative path, let it slide.
@@ -172,8 +172,10 @@ public function setCommand($command)
172
172
}
173
173
174
174
/**
175
- * @param string $stdIn If set, the string will be piped to the command via standard input.
175
+ * @param string|resource $stdIn If set, the string will be piped to the command via standard input.
176
176
* This enables the same functionality as piping on the command line.
177
+ * It can also be a resource like a file handle or a stream in which case its content will be piped
178
+ * into the command like an input redirection.
177
179
* @return static for method chaining
178
180
*/
179
181
public function setStdIn ($ stdIn ) {
@@ -345,8 +347,13 @@ public function execute()
345
347
346
348
if (is_resource ($ process )) {
347
349
348
- if ($ this ->_stdIn !==null ) {
349
- fwrite ($ pipes [0 ], $ this ->_stdIn );
350
+ if ($ this ->_stdIn !==null ) {
351
+ if (is_resource ($ this ->_stdIn ) &&
352
+ in_array (get_resource_type ($ this ->_stdIn ), array ('file ' , 'stream ' ), true )) {
353
+ stream_copy_to_stream ($ this ->_stdIn , $ pipes [0 ]);
354
+ } else {
355
+ fwrite ($ pipes [0 ], $ this ->_stdIn );
356
+ }
350
357
fclose ($ pipes [0 ]);
351
358
}
352
359
$ this ->_stdOut = stream_get_contents ($ pipes [1 ]);
0 commit comments