diff --git a/src/Composer/XdebugHandler.php b/src/Composer/XdebugHandler.php index be04dec55..a55d37368 100644 --- a/src/Composer/XdebugHandler.php +++ b/src/Composer/XdebugHandler.php @@ -136,9 +136,13 @@ class XdebugHandler { $this->tmpIni = ''; $iniPaths = IniHelper::getAll(); - $files = $this->getWorkingSet($iniPaths, $replace); - if ($this->writeTmpIni($files, $replace)) { + if (empty($iniPaths[0])) { + // There is no loaded ini + array_shift($iniPaths); + } + + if ($this->writeTmpIni($iniPaths)) { return $this->setEnvironment($iniPaths); } @@ -151,24 +155,21 @@ class XdebugHandler * The filename is passed as the -c option when the process restarts. * * @param array $iniFiles The php.ini locations - * @param bool $replace Whether the files need modifying * * @return bool */ - private function writeTmpIni(array $iniFiles, $replace) + private function writeTmpIni(array $iniFiles) { - if (empty($iniFiles)) { - // Unlikely, maybe xdebug was loaded through a command line option. - return true; - } - if (!$this->tmpIni = tempnam(sys_get_temp_dir(), '')) { return false; } $content = ''; + $regex = '/^\s*(zend_extension\s*=.*xdebug.*)$/mi'; + foreach ($iniFiles as $file) { - $content .= $this->getIniData($file, $replace); + $data = preg_replace($regex, ';$1', file_get_contents($file)); + $content .= $data.PHP_EOL; } $content .= PHP_EOL.'memory_limit='.ini_get('memory_limit').PHP_EOL; @@ -176,60 +177,6 @@ class XdebugHandler return @file_put_contents($this->tmpIni, $content); } - /** - * Returns an array of ini files to use - * - * @param array $iniPaths Locations used by the current prcoess - * @param null|bool $replace Whether the files need modifying, set by method - * - * @return array - */ - private function getWorkingSet(array $iniPaths, &$replace) - { - $replace = true; - $result = array(); - - if (empty($iniPaths[0])) { - // There is no loaded ini - array_shift($iniPaths); - } - - foreach ($iniPaths as $file) { - if (preg_match('/xdebug.ini$/', $file)) { - // Skip the file, no need for regex replacing - $replace = false; - } else { - $result[] = $file; - } - } - - return $result; - } - - /** - * Returns formatted ini file data - * - * @param string $iniFile The location of the ini file - * @param bool $replace Whether to regex replace content - * - * @return string The ini data - */ - private function getIniData($iniFile, $replace) - { - $contents = file_get_contents($iniFile); - $data = PHP_EOL; - - if ($replace) { - // Comment out xdebug config - $regex = '/^\s*(zend_extension\s*=.*xdebug.*)$/mi'; - $data .= preg_replace($regex, ';$1', $contents); - } else { - $data .= $contents; - } - - return $data; - } - /** * Returns the restart command line *