Skip to content

Commit 1805f29

Browse files
committed
[Console] Remove exec from console component
1 parent 6166fc4 commit 1805f29

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,11 @@ private function isInteractiveInput($inputStream): bool
500500
return self::$stdinIsInteractive = @posix_isatty(fopen('php://stdin', 'r'));
501501
}
502502

503-
if (!\function_exists('exec')) {
503+
if (!\function_exists('shell_exec')) {
504504
return self::$stdinIsInteractive = true;
505505
}
506506

507-
exec('stty 2> /dev/null', $output, $status);
508-
509-
return self::$stdinIsInteractive = 1 !== $status;
507+
return self::$stdinIsInteractive = !is_string(shell_exec('stty 2> /dev/null'));
510508
}
511509

512510
/**

src/Symfony/Component/Console/Terminal.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ public static function hasSttyAvailable(): bool
6464
return self::$stty;
6565
}
6666

67-
// skip check if exec function is disabled
68-
if (!\function_exists('exec')) {
67+
// skip check if shell_exec function is disabled
68+
if (!\function_exists('shell_exec')) {
6969
return false;
7070
}
7171

72-
exec('stty 2>&1', $output, $exitcode);
73-
74-
return self::$stty = 0 === $exitcode;
72+
return self::$stty = is_string(shell_exec('stty 2>&1'));
7573
}
7674

7775
private static function initDimensions()

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public function testAskHiddenResponse()
430430
$this->assertEquals('8AM', $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream("8AM\n")), $this->createOutputInterface(), $question));
431431
}
432432

433-
public function testAskHiddenResponseTrimmed()
433+
public function testAskHiddenResponseNotTrimmed()
434434
{
435435
if ('\\' === \DIRECTORY_SEPARATOR) {
436436
$this->markTestSkipped('This test is not supported on Windows');
@@ -442,7 +442,7 @@ public function testAskHiddenResponseTrimmed()
442442
$question->setHidden(true);
443443
$question->setTrimmable(false);
444444

445-
$this->assertEquals(' 8AM', $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream(' 8AM')), $this->createOutputInterface(), $question));
445+
$this->assertEquals(' 8AM'.\PHP_EOL, $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream(' 8AM'.\PHP_EOL)), $this->createOutputInterface(), $question));
446446
}
447447

448448
public function testAskMultilineResponseWithEOF()

src/Symfony/Component/Console/Tests/TerminalTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public function testSttyOnWindows()
7777
$this->markTestSkipped('Must be on windows');
7878
}
7979

80-
$sttyString = exec('(stty -a | grep columns) 2>&1', $output, $exitcode);
81-
if (0 !== $exitcode) {
80+
$sttyString = shell_exec('(stty -a | grep columns) 2>&1');
81+
if (!is_string($sttyString)) {
8282
$this->markTestSkipped('Must have stty support');
8383
}
8484

0 commit comments

Comments
 (0)