Skip to content

Commit 03d2bff

Browse files
minor symfony#57550 [Lock][Process] Replace strtok calls (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- [Lock][Process] Replace `strtok` calls | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | symfony#57542 | License | MIT I targeted 5.4, I think this is a good thing in order to be future-proof and help potential fixes upmerges, strtok being deprecated or not. Rebasing on 7.2 is not a big deal though if needed, as I only found 1 more occurrence on the latest branch. Commits ------- c76ba0d [Lock][Process] Replace `strtok` calls
2 parents f35780f + c76ba0d commit 03d2bff

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private function filterDsn(#[\SensitiveParameter] string $dsn): string
268268
}
269269

270270
[$scheme, $rest] = explode(':', $dsn, 2);
271-
$driver = strtok($scheme, '+');
271+
$driver = substr($scheme, 0, strpos($scheme, '+') ?: null);
272272
if (!\in_array($driver, ['pgsql', 'postgres', 'postgresql'])) {
273273
throw new InvalidArgumentException(\sprintf('The adapter "%s" does not support the "%s" driver.', __CLASS__, $driver));
274274
}

src/Symfony/Component/Process/ExecutableFinder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,14 @@ public function find(string $name, ?string $default = null, array $extraDirs = [
7979
}
8080
}
8181

82+
if (!\function_exists('exec')) {
83+
return $default;
84+
}
85+
8286
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
83-
if (\function_exists('exec') && ($executablePath = strtok(@exec($command.' '.escapeshellarg($name)), \PHP_EOL)) && @is_executable($executablePath)) {
87+
$execResult = @exec($command.' '.escapeshellarg($name));
88+
89+
if (($executablePath = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) && @is_executable($executablePath)) {
8490
return $executablePath;
8591
}
8692

src/Symfony/Component/Process/PhpExecutableFinder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public function find(bool $includeArgs = true): string|false
3333
{
3434
if ($php = getenv('PHP_BINARY')) {
3535
if (!is_executable($php)) {
36+
if (!\function_exists('exec')) {
37+
return false;
38+
}
39+
3640
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
37-
if (\function_exists('exec') && $php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
41+
$execResult = exec($command.' '.escapeshellarg($php));
42+
if ($php = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) {
3843
if (!is_executable($php)) {
3944
return false;
4045
}

0 commit comments

Comments
 (0)