Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit95aa236

Browse files
weaverryanfabpot
authored andcommitted
[Process] Fix bug where $this->callback is never null, resulting in bad argument
1 parent62e115f commit95aa236

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

‎src/Symfony/Component/Process/Process.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function start(callable $callback = null, array $env = [])
304304
$this->resetProcessData();
305305
$this->starttime =$this->lastOutputTime =microtime(true);
306306
$this->callback =$this->buildCallback($callback);
307-
$descriptors =$this->getDescriptors();
307+
$descriptors =$this->getDescriptors(null !==$callback);
308308

309309
if ($this->env) {
310310
$env +='\\' === \DIRECTORY_SEPARATOR ?array_diff_ukey($this->env,$env,'strcasecmp') :$this->env;
@@ -1240,15 +1240,15 @@ public static function isPtySupported(): bool
12401240
/**
12411241
* Creates the descriptors needed by the proc_open.
12421242
*/
1243-
privatefunctiongetDescriptors():array
1243+
privatefunctiongetDescriptors(bool$hasCallback):array
12441244
{
12451245
if ($this->inputinstanceof \Iterator) {
12461246
$this->input->rewind();
12471247
}
12481248
if ('\\' === \DIRECTORY_SEPARATOR) {
1249-
$this->processPipes =newWindowsPipes($this->input, !$this->outputDisabled ||$this->callback);
1249+
$this->processPipes =newWindowsPipes($this->input, !$this->outputDisabled ||$hasCallback);
12501250
}else {
1251-
$this->processPipes =newUnixPipes($this->isTty(),$this->isPty(),$this->input, !$this->outputDisabled ||$this->callback);
1251+
$this->processPipes =newUnixPipes($this->isTty(),$this->isPty(),$this->input, !$this->outputDisabled ||$hasCallback);
12521252
}
12531253

12541254
return$this->processPipes->getDescriptors();

‎src/Symfony/Component/Process/Tests/ProcessTest.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ public function testCallbacksAreExecutedWithStart()
200200
$this->assertSame('foo'.\PHP_EOL,$data);
201201
}
202202

203+
publicfunctiontestReadSupportIsDisabledWithoutCallback()
204+
{
205+
$this->expectException(LogicException::class);
206+
$this->expectExceptionMessage('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::wait".');
207+
208+
$process =$this->getProcess('echo foo');
209+
// disabling output + not passing a callback to start() => read support disabled
210+
$process->disableOutput();
211+
$process->start();
212+
$process->wait(function ($type,$buffer)use (&$data) {
213+
$data .=$buffer;
214+
});
215+
}
216+
203217
/**
204218
* tests results from sub processes.
205219
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp