/**
  * 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"));
 }