Skip to content

Commit a518fde

Browse files
[10.x] Standard Input can be applied to PendingProcess (#46119)
* StdInput can be applied to PendingProcess * Change test * PHPdoc tags * clean up * added space for doc tag * Fix styles * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent d327eb9 commit a518fde

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Illuminate/Process/PendingProcess.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ class PendingProcess
5454
*/
5555
public $environment = [];
5656

57+
/**
58+
* The standard input data that should be piped into the command.
59+
*
60+
* @var string|int|float|bool|resource|\Traversable|null
61+
*/
62+
public $input;
63+
5764
/**
5865
* Indicates whether output should be disabled for the process.
5966
*
@@ -170,6 +177,19 @@ public function env(array $environment)
170177
return $this;
171178
}
172179

180+
/**
181+
* Set the standard input that should be provided when invoking the process.
182+
*
183+
* @param \Traversable|resource|string|int|float|bool|null $input
184+
* @return $this
185+
*/
186+
public function input($input)
187+
{
188+
$this->input = $input;
189+
190+
return $this;
191+
}
192+
173193
/**
174194
* Disable output for the process.
175195
*
@@ -281,6 +301,10 @@ protected function toSymfonyProcess(array|string|null $command)
281301
$process->setIdleTimeout($this->idleTimeout);
282302
}
283303

304+
if ($this->input) {
305+
$process->setInput($this->input);
306+
}
307+
284308
if ($this->quietly) {
285309
$process->disableOutput();
286310
}

src/Illuminate/Support/Facades/Process.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @method static \Illuminate\Process\PendingProcess quietly()
1616
* @method static \Illuminate\Process\PendingProcess tty(bool $tty = true)
1717
* @method static \Illuminate\Process\PendingProcess options(array $options)
18+
* @method static \Illuminate\Process\PendingProcess input(\Traversable|resource|string|int|float|bool|null $input)
1819
* @method static \Illuminate\Contracts\Process\ProcessResult run(array|string|null $command = null, callable|null $output = null)
1920
* @method static \Illuminate\Process\InvokedProcess start(array|string|null $command = null, callable $output = null)
2021
* @method static \Illuminate\Process\PendingProcess withFakeHandlers(array $fakeHandlers)

tests/Process/ProcessTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,18 @@ public function testRealProcessesDoesntThrowIfFalse()
470470
$this->assertTrue(true);
471471
}
472472

473+
public function testRealProcessesCanUseStandardInput()
474+
{
475+
if (windows_os()) {
476+
$this->markTestSkipped('Requires Linux.');
477+
}
478+
479+
$factory = new Factory();
480+
$result = $factory->input('foobar')->run('cat');
481+
482+
$this->assertSame('foobar', $result->output());
483+
}
484+
473485
public function testFakeInvokedProcessOutputWithLatestOutput()
474486
{
475487
$factory = new Factory;

0 commit comments

Comments
 (0)