Skip to content

Commit

Permalink
support multiple PHP_INI_SCAN_DIR's
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Nov 11, 2024
1 parent 7b487bd commit 6479b61
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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

0 comments on commit 6479b61

Please sign in to comment.