Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple PHP_INI_SCAN_DIR's #2941

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions datadog-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,13 @@ function find_all_ini_files(array $phpProperties)
function find_main_ini_files(array $phpProperties)
{
if (isset($phpProperties[INI_SCANDIR])) {

$pos = strpos($phpProperties[INI_SCANDIR], \PATH_SEPARATOR);
if ($pos !== false) {
// https://www.php.net/manual/en/configuration.file.php#configuration.file.scandir
$phpProperties[INI_SCANDIR] = current(array_filter(explode(':', $phpProperties[INI_SCANDIR])));
}

$iniFileName = '98-ddtrace.ini';
// Search for pre-existing files with extension = ddtrace.so to avoid conflicts
// See issue https://github.com/DataDog/dd-trace-php/issues/1833
Expand Down
46 changes: 45 additions & 1 deletion tests/Integration/PHPInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function testUpdateIniSetting(string $before, string $after, bool $promot
$tempFile = tempnam(sys_get_temp_dir(), 'test');
file_put_contents($tempFile, $before);

$count = update_ini_setting(['foo.bar', 'Off'], $tempFile, $promoteComment);
$count = \update_ini_setting(['foo.bar', 'Off'], $tempFile, $promoteComment);

$output = file_get_contents($tempFile);
$this->assertSame($after, $output);
Expand All @@ -293,6 +293,50 @@ public function testUpdateIniSetting(string $before, string $after, bool $promot
unlink($tempFile);
}

public function iniFilePathsProvider()
{
return [
[
[
'Scan this dir for additional .ini files' => '/opt/php/8.4/etc/conf.d',
'Loaded Configuration File' => '',
], [
'/opt/php/8.4/etc/conf.d/98-ddtrace.ini',
]
], [
[
'Scan this dir for additional .ini files' => '/opt/php/8.4/etc/conf.d'.\PATH_SEPARATOR.'/opt/php/8.4/etc/override-conf.d',
'Loaded Configuration File' => '',
], [
'/opt/php/8.4/etc/conf.d/98-ddtrace.ini',
]
], [
[
'Scan this dir for additional .ini files' => \PATH_SEPARATOR.'/opt/php/8.4/etc/override-conf.d',
'Loaded Configuration File' => '',
], [
'/opt/php/8.4/etc/override-conf.d/98-ddtrace.ini',
]
], [
[
'Scan this dir for additional .ini files' => '/opt/php/8.4/etc/override-conf.d'.\PATH_SEPARATOR,
'Loaded Configuration File' => '',
], [
'/opt/php/8.4/etc/override-conf.d/98-ddtrace.ini',
]
]
];
}

/**
* @dataProvider iniFilePathsProvider
*/
public function testFindIniFilePath($props, $expected)
{
$dirs = \find_main_ini_files($props);
$this->assertSame($expected, $dirs);
}

private static function getTmpRootPath()
{
return sys_get_temp_dir() . '/dd-php-setup-tests';
Expand Down
Loading