Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51e1cf6

Browse files
Merge branch '6.4' into 7.0
* 6.4: (31 commits) [HttpKernel] Strip exception file paths from log messages [Validator] Add ability to validate time without seconds [Process] Fix test case [Process] Support finding executables independently of open_basedir [Mime] Update mimetypes Add some PHPDoc [Workflow] Add a profiler [Form] Removing self-closing slash from `<input>` [FrameworkBundle][Serializer] Add TranslatableNormalizer [Uid] Fix example [HttpKernel] Add `reset()` implementation in DataCollector [Uid] Add more PHP doc to "export" functions [HttpKernel] RequestPayloadValueResolver Add support for custom http status code [Serializer] Add support for seld/jsonlint in order to enhance error messages [Workflow] fix MermaidDumper when place contains special char [Translation] Phrase translation provider [Workflow] Add support for storing the marking in a property [Crawler] Fix regression where cdata nodes will return empty string [Scheduler] make `ScheduledStamp` "send-able" [Serializer] Groups annotation/attribute on class ...
2 parents b7004dc + 8d552f7 commit 51e1cf6

File tree

6 files changed

+27
-40
lines changed

6 files changed

+27
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `RunProcessMessage` and `RunProcessMessageHandler`
8+
* Support using `Process::findExecutable()` independently of `open_basedir`
89

910
5.2.0
1011
-----

ExecutableFinder.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,10 @@ public function addSuffix(string $suffix): void
4646
*/
4747
public function find(string $name, string $default = null, array $extraDirs = []): ?string
4848
{
49-
if (\ini_get('open_basedir')) {
50-
$searchPath = array_merge(explode(\PATH_SEPARATOR, \ini_get('open_basedir')), $extraDirs);
51-
$dirs = [];
52-
foreach ($searchPath as $path) {
53-
// Silencing against https://bugs.php.net/69240
54-
if (@is_dir($path)) {
55-
$dirs[] = $path;
56-
} else {
57-
if (basename($path) == $name && @is_executable($path)) {
58-
return $path;
59-
}
60-
}
61-
}
62-
} else {
63-
$dirs = array_merge(
64-
explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
65-
$extraDirs
66-
);
67-
}
49+
$dirs = array_merge(
50+
explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
51+
$extraDirs
52+
);
6853

6954
$suffixes = [''];
7055
if ('\\' === \DIRECTORY_SEPARATOR) {
@@ -76,9 +61,18 @@ public function find(string $name, string $default = null, array $extraDirs = []
7661
if (@is_file($file = $dir.\DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) {
7762
return $file;
7863
}
64+
65+
if (!@is_dir($dir) && basename($dir) === $name.$suffix && @is_executable($dir)) {
66+
return $dir;
67+
}
7968
}
8069
}
8170

71+
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v';
72+
if (\function_exists('exec') && ($executablePath = strtok(@exec($command.' '.escapeshellarg($name)), \PHP_EOL)) && is_executable($executablePath)) {
73+
return $executablePath;
74+
}
75+
8276
return $default;
8377
}
8478
}

PhpExecutableFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function find(bool $includeArgs = true): string|false
3434
if ($php = getenv('PHP_BINARY')) {
3535
if (!is_executable($php)) {
3636
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v';
37-
if ($php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
37+
if (\function_exists('exec') && $php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
3838
if (!is_executable($php)) {
3939
return false;
4040
}

Tests/ErrorProcessInitiator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
use Symfony\Component\Process\Exception\ProcessTimedOutException;
1515
use Symfony\Component\Process\Process;
1616

17-
require \dirname(__DIR__).'/vendor/autoload.php';
17+
require is_file(\dirname(__DIR__).'/vendor/autoload.php') ? \dirname(__DIR__).'/vendor/autoload.php' : \dirname(__DIR__, 5).'/vendor/autoload.php';
1818

1919
['e' => $php] = getopt('e:') + ['e' => 'php'];
2020

2121
try {
22-
$process = new Process("exec $php -r \"echo 'ready'; trigger_error('error', E_USER_ERROR);\"");
22+
$process = new Process([$php, '-r', "echo 'ready'; trigger_error('error', E_USER_ERROR);"]);
2323
$process->start();
2424
$process->setTimeout(0.5);
2525
while (!str_contains($process->getOutput(), 'ready')) {

Tests/ExecutableFinderTest.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,9 @@
1919
*/
2020
class ExecutableFinderTest extends TestCase
2121
{
22-
private string|false $path = false;
23-
2422
protected function tearDown(): void
2523
{
26-
if ($this->path) {
27-
// Restore path if it was changed.
28-
putenv('PATH='.$this->path);
29-
}
30-
}
31-
32-
private function setPath($path)
33-
{
34-
$this->path = getenv('PATH');
35-
putenv('PATH='.$path);
24+
putenv('PATH='.($_SERVER['PATH'] ?? $_SERVER['Path']));
3625
}
3726

3827
public function testFind()
@@ -41,7 +30,7 @@ public function testFind()
4130
$this->markTestSkipped('Cannot test when open_basedir is set');
4231
}
4332

44-
$this->setPath(\dirname(\PHP_BINARY));
33+
putenv('PATH='.\dirname(\PHP_BINARY));
4534

4635
$finder = new ExecutableFinder();
4736
$result = $finder->find($this->getPhpBinaryName());
@@ -57,7 +46,7 @@ public function testFindWithDefault()
5746

5847
$expected = 'defaultValue';
5948

60-
$this->setPath('');
49+
putenv('PATH=');
6150

6251
$finder = new ExecutableFinder();
6352
$result = $finder->find('foo', $expected);
@@ -71,7 +60,7 @@ public function testFindWithNullAsDefault()
7160
$this->markTestSkipped('Cannot test when open_basedir is set');
7261
}
7362

74-
$this->setPath('');
63+
putenv('PATH=');
7564

7665
$finder = new ExecutableFinder();
7766

@@ -86,7 +75,7 @@ public function testFindWithExtraDirs()
8675
$this->markTestSkipped('Cannot test when open_basedir is set');
8776
}
8877

89-
$this->setPath('');
78+
putenv('PATH=');
9079

9180
$extraDirs = [\dirname(\PHP_BINARY)];
9281

@@ -129,7 +118,6 @@ public function testFindProcessInOpenBasedir()
129118
$this->markTestSkipped('Cannot run test on windows');
130119
}
131120

132-
$this->setPath('');
133121
$this->iniSet('open_basedir', \PHP_BINARY.\PATH_SEPARATOR.'/');
134122

135123
$finder = new ExecutableFinder();
@@ -154,7 +142,7 @@ public function testFindBatchExecutableOnWindows()
154142

155143
$this->assertFalse(is_executable($target));
156144

157-
$this->setPath(sys_get_temp_dir());
145+
putenv('PATH='.sys_get_temp_dir());
158146

159147
$finder = new ExecutableFinder();
160148
$result = $finder->find(basename($target), false);

Tests/ProcessTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,10 @@ public function testWaitStoppedDeadProcess()
15211521
$process->setTimeout(2);
15221522
$process->wait();
15231523
$this->assertFalse($process->isRunning());
1524+
1525+
if ('\\' !== \DIRECTORY_SEPARATOR) {
1526+
$this->assertSame(0, $process->getExitCode());
1527+
}
15241528
}
15251529

15261530
public function testEnvCaseInsensitiveOnWindows()

0 commit comments

Comments
 (0)