/** * Private constructor to initialize the instance * with the necessary data. * * @param string $baseDir The Magento base directory * @return void */ public function __construct($baseDir) { // check if the passed Magento base directory exists if (!is_dir($baseDir)) { throw new Exception('Magento base directory ' . $baseDir . ' doesn\'t exists'); } // load the PEAR directory for the Magento channel $pearDir = $baseDir . DS . 'downloader' . DS . 'pearlib'; // check if the Magento PEAR directory exists if (!is_dir($pearDir)) { throw new Exception('Magento PEAR base directory ' . $pearDir . ' doesn\'t exists'); } // load the registry $this->_registry = new PEAR_Registry($pearDir . DS . 'php'); // initialize the configuration with the channels configuration file $this->_config = PEAR_Config::singleton($pearDir . DS . 'pear.ini', '-'); // overwrite the configuration values $this->_config->set('auto_discover', 1); $this->_config->set('cache_ttl', 60); $this->_config->set('preferred_state', 'alpha'); $this->_config->set('bin_dir', $pearDir); $this->_config->set('php_dir', $pearDir . DS . 'php'); $this->_config->set('download_dir', $pearDir . DS . 'download'); $this->_config->set('temp_dir', $pearDir . DS . 'temp'); $this->_config->set('data_dir', $pearDir . DS . 'data'); $this->_config->set('cache_dir', $pearDir . DS . 'cache'); $this->_config->set('test_dir', $pearDir . DS . 'tests'); $this->_config->set('doc_dir', $pearDir . DS . 'docs'); // initialize the Magento specific settings foreach ($this->_config->getKeys() as $key) { if (!(substr($key, 0, 5) === 'mage_' && substr($key, -4) === '_dir')) { continue; } $this->_config->set($key, preg_replace('#^\\.#', addslashes(Mage::getBaseDir()), $this->_config->get($key))); } // set the registry $this->_config->setRegistry($this->_registry); // initialize the dependeny database PEAR_DependencyDB::singleton($this->_config, $pearDir . DS . 'php' . DS . '.depdb'); // register the commands, including the one for Magento PEAR_Command::registerCommands(true, $pearDir . DS . 'php' . DS . 'PEAR' . DS . 'Command' . DS); // initialize the PEAR frontend PEAR_Frontend::setFrontendClass('Faett_Core_Frontend_PEAR'); $this->_ui = PEAR_Command::getFrontendObject(); $this->_ui->setConfig($this->_config); // set the callback for rendering the messages PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this->_ui, "log")); }
function _initializeDepDB() { if (!isset($this->_dependencyDB)) { static $initializing = false; if (!$initializing) { $initializing = true; if (!$this->_config) { // never used? $file = OS_WINDOWS ? 'pear.ini' : '.pearrc'; $this->_config =& new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR . $file); $this->_config->setRegistry($this); $this->_config->set('php_dir', $this->install_dir); } $this->_dependencyDB =& PEAR_DependencyDB::singleton($this->_config); if (PEAR::isError($this->_dependencyDB)) { // attempt to recover by removing the dep db if (file_exists($this->_config->get('php_dir', null, 'pear.php.net') . DIRECTORY_SEPARATOR . '.depdb')) { @unlink($this->_config->get('php_dir', null, 'pear.php.net') . DIRECTORY_SEPARATOR . '.depdb'); } $this->_dependencyDB =& PEAR_DependencyDB::singleton($this->_config); if (PEAR::isError($this->_dependencyDB)) { echo $this->_dependencyDB->getMessage(); echo 'Unrecoverable error'; exit(1); } } $initializing = false; } } }