getConfig();
}
public function getInstance()
{
if (!self::$_instance) {
self::$_instance = new self;
}
return self::$_instance;
}
public function isSystemPackage($pkg)
{
return in_array($pkg, array('Archive_Tar', 'Console_Getopt', 'PEAR', 'Structures_Graph'));
}
public function getBaseDir()
{
return dirname(dirname(dirname(__FILE__)));
}
public function getPearDir()
{
return dirname(dirname(__FILE__)).DS.'pearlib';
}
public function getConfig()
{
if (!$this->_config) {
$pear_dir = $this->getPearDir();
$config = PEAR_Config::singleton($pear_dir.DS.'pear.ini', '-');
//$config = PEAR_Config::singleton();
$config->set('auto_discover', 1);
$config->set('cache_ttl', 60);
#$config->set('preferred_state', 'beta');
$config->set('bin_dir', $pear_dir);
$config->set('php_dir', $pear_dir.DS.'php');
$config->set('download_dir', $pear_dir.DS.'download');
$config->set('temp_dir', $pear_dir.DS.'temp');
$config->set('data_dir', $pear_dir.DS.'data');
$config->set('cache_dir', $pear_dir.DS.'cache');
$config->set('test_dir', $pear_dir.DS.'tests');
$config->set('doc_dir', $pear_dir.DS.'docs');
foreach ($config->getKeys() as $key) {
if (!(substr($key, 0, 5)==='mage_' && substr($key, -4)==='_dir')) {
continue;
}
$config->set($key, preg_replace('#^\.#', $this->getBaseDir(), $config->get($key)));
//echo $key.' : '.$config->get($key).'
';
}
$reg = $this->getRegistry();
$config->setRegistry($reg);
PEAR_DependencyDB::singleton($config, $pear_dir.DS.'php'.DS.'.depdb');
PEAR_Frontend::setFrontendObject($this->getFrontend());
PEAR_Command::registerCommands(false, $pear_dir.DS.'php'.DS.'PEAR'.DS.'Command'.DS);
$this->_config = $config;
}
return $this->_config;
}
public function getMagentoChannels()
{
return array(
'connect.magentocommerce.com/core' => 'Core Team Extensions',
'connect.magentocommerce.com/community' => 'Community Extensions',
);
}
public function getRegistry()
{
// return $this->getConfig()->getRegistry();
if (!$this->_registry) {
$this->_registry = new Maged_Pear_Registry($this->getPearDir().DS.'php');
$changed = false;
foreach ($this->getMagentoChannels() as $channel=>$channelName) {
if (!$this->getRegistry()->channelExists($channel)) {
$this->run('channel-discover', array(), array($channel));
$changed = true;
}
}
if ($changed && empty($_GET['pear_registry'])) {
//TODO:refresh registry in memory to reflect discovered channels without redirect
header("Location: ".$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'].'&pear_registry=1');
exit;
}
}
return $this->_registry;
}
public function getFrontend()
{
if (!$this->_frontend) {
$this->_frontend = new Maged_Pear_Frontend;
}
return $this->_frontend;
}
public function getLog()
{
return $this->getFrontend()->getLog();
}
public function getOutput()
{
return $this->getFrontend()->getOutput();
}
public function cleanRegistry()
{
$oldDir = @getcwd();
@chdir($this->getPearDir().DIRECTORY_SEPARATOR.'php');
$this->delTree('.registry');
@chdir($oldDir);
return $this;
}
public function delTree($path) {
if (@is_dir($path)) {
$entries = @scandir($path);
foreach ($entries as $entry) {
if ($entry != '.' && $entry != '..') {
$this->delTree($path.DS.$entry);
}
}
@rmdir($path);
} else {
@unlink($path);
}
return $this;
}
public function run($command, $options=array(), $params=array())
{
@set_time_limit(0);
@ini_set('memory_limit', '256M');
if (empty($this->_cmdCache[$command])) {
$cmd = PEAR_Command::factory($command, $this->getConfig());
if ($cmd instanceof PEAR_Error) {
return $cmd;
}
$this->_cmdCache[$command] = $cmd;
} else {
$cmd = $this->_cmdCache[$command];
}
#$cmd = PEAR_Command::factory($command, $this->getConfig());
$result = $cmd->run($command, $options, $params);
return $result;
}
public function setRemoteConfig($uri) #$host, $user, $password, $path='', $port=null)
{
#$uri = 'ftp://' . $user . ':' . $password . '@' . $host . (is_numeric($port) ? ':' . $port : '') . '/' . trim($path, '/') . '/';
$this->run('config-set', array(), array('remote_config', $uri));
return $this;
}
/**
* Run PEAR command with html output console style
*
* @param array|Maged_Model $runParams command, options, params,
* comment, success_callback, failure_callback
*/
public function runHtmlConsole($runParams)
{
ob_implicit_flush();
$fe = $this->getFrontend();
$oldLogStream = $fe->getLogStream();
$fe->setLogStream('stdout');
if ($runParams instanceof Maged_Model) {
$run = $runParams;
} elseif (is_array($runParams)) {
$run = new Maged_Model_Pear_Request($runParams);
} elseif (is_string($runParams)) {
$run = new Maged_Model_Pear_Request(array('comment'=>$runParams));
} else {
throw Maged_Exception("Invalid run parameters");
}
if (!$run->get('no-header')) {
?>