예제 #1
0
 /**
  * Extract configuration from system + user configuration files
  *
  * Configuration is stored in XML format, in two locations.
  *
  * The system configuration contains all of the important directory
  * configuration variables like data_dir, and the location of php.ini and
  * the php executable php.exe or php.  This configuration is tightly bound
  * to the repository, and cannot be moved.  As such, php_dir is auto-defined
  * as dirname(/path/to/pear/.config), or /path/to/pear.
  *
  * Only 1 user configuration file is allowed, and contains user-specific
  * settings, including the locations where to download package releases
  * and where to cache files downloaded from the internet.  If false is passed
  * in, \PEAR2\Pyrus\Config will attempt to guess at the config file location as
  * documented in the class docblock {@link \PEAR2\Pyrus\Config}.
  * @param string $pearDirectory
  * @param string|false $userfile
  */
 protected function loadConfigFile($pearDirectory, $snapshot = null)
 {
     if (!file_exists($pearDirectory . DIRECTORY_SEPARATOR . '.configsnapshots')) {
         // no configurations - this may be an extracted-from-disk install.
         // in this case, we use the defaults, as this is intended
         return;
     }
     $snapshotdir = $pearDirectory . DIRECTORY_SEPARATOR . '.configsnapshots';
     $snapshotfile = $snapshotdir . DIRECTORY_SEPARATOR . $snapshot;
     if (!file_exists($snapshotfile)) {
         if (preg_match('/^\\d{4}\\-\\d{2}\\-\\d{2} \\d{2}[-:]\\d{2}[-:]\\d{2}$/', $snapshot)) {
             // passed a date, locate a matching snapshot
             if (!strpos($snapshot, ':')) {
                 // change YYYY-MM-DD HH-MM-SS to YYYY-MM-DD HH:MM:SS
                 $snapshot = explode(' ', $snapshot);
                 $snapshot[1] = str_replace('-', ':', $snapshot[1]);
                 $snapshot = implode(' ', $snapshot);
             }
             $us = new \DateTime($snapshot);
             $dir = new \RegexIterator(new \RecursiveDirectoryIterator($snapshotdir), '/configsnapshot\\-\\d{4}\\-\\d{2}\\-\\d{2} \\d{2}\\-\\d{2}\\-\\d{2}.xml/', \RegexIterator::MATCH, \RegexIterator::USE_KEY);
             foreach ($dir as $match) {
                 $matches[] = $match;
             }
             usort($matches, array($this, 'datediff'));
             unset($match);
             $found = false;
             foreach ($matches as $match) {
                 $match = substr($match->getFileName(), strlen('configsnapshot-'));
                 $match = str_replace('.xml', '', $match);
                 $match = explode(' ', $match);
                 $match[1] = str_replace('-', ':', $match[1]);
                 $match = implode(' ', $match);
                 $testdate = new \DateTime($match);
                 if ($testdate > $us) {
                     continue;
                 }
                 if ($testdate == $us) {
                     // found a snapshot match
                     $found = true;
                     break;
                 }
                 if ($us > $testdate) {
                     // we fall between these two snapshots, so use this one
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 // no config snapshots
                 return parent::loadConfigFile($pearDirectory);
             }
             $snapshotfile = $snapshotdir . DIRECTORY_SEPARATOR . 'configsnapshot-' . str_replace(':', '-', $match) . '.xml';
         }
     }
     \PEAR2\Pyrus\Logger::log(5, 'Loading configuration snapshot ' . $snapshotfile . ' for ' . $pearDirectory);
     try {
         $this->helperLoadConfigFile($pearDirectory, $snapshotfile, 'snapshot');
     } catch (\Exception $e) {
         // no config snapshots found, so simply load the existing config
         return parent::loadConfigFile($pearDirectory);
     }
 }