function XdebugHandler::writeTmpIni
Returns true if the tmp ini file was written
Parameters
non-empty-list<string> $iniFiles All ini files used in the current process:
1 call to XdebugHandler::writeTmpIni()
- XdebugHandler::prepareRestart in vendor/
composer/ xdebug-handler/ src/ XdebugHandler.php - Returns the command line array if everything was written for the restart
File
-
vendor/
composer/ xdebug-handler/ src/ XdebugHandler.php, line 389
Class
- XdebugHandler
- @author John Stevenson <john-stevenson@blueyonder.co.uk>
Namespace
Composer\XdebugHandlerCode
private function writeTmpIni(string $tmpFile, array $iniFiles, ?string &$error) : bool {
// $iniFiles has at least one item and it may be empty
if ($iniFiles[0] === '') {
array_shift($iniFiles);
}
$content = '';
$sectionRegex = '/^\\s*\\[(?:PATH|HOST)\\s*=/mi';
$xdebugRegex = '/^\\s*(zend_extension\\s*=.*xdebug.*)$/mi';
foreach ($iniFiles as $file) {
// Check for inaccessible ini files
if (($data = @file_get_contents($file)) === false) {
$error = 'Unable to read ini: ' . $file;
return false;
}
// Check and remove directives after HOST and PATH sections
if (Preg::isMatchWithOffsets($sectionRegex, $data, $matches)) {
$data = substr($data, 0, $matches[0][1]);
}
$content .= Preg::replace($xdebugRegex, ';$1', $data) . PHP_EOL;
}
// Merge loaded settings into our ini content, if it is valid
$config = parse_ini_string($content);
$loaded = ini_get_all(null, false);
if (false === $config || false === $loaded) {
$error = 'Unable to parse ini data';
return false;
}
$content .= $this->mergeLoadedConfig($loaded, $config);
// Work-around for https://bugs.php.net/bug.php?id=75932
$content .= 'opcache.enable_cli=0' . PHP_EOL;
return (bool) @file_put_contents($tmpFile, $content);
}