Esempio n. 1
0
 /**
  *  setup PEAR_Config and so on.
  *
  *  @param  string      $target     whether 'master' or 'local'
  *  @param  string|null $app_dir    local application directory.
  *  @param  string|null $channel    channel for the package repository.
  *  @return true|Ethna_Error
  */
 public function init($target, $app_dir = null, $channel = null)
 {
     $true = true;
     if ($target == 'master') {
         $this->target = 'master';
     } else {
         // default target is 'local'.
         $this->target = 'local';
     }
     // setup PEAR_Frontend
     PEAR_Command::setFrontendType('CLI');
     $this->ui = PEAR_Command::getFrontendObject();
     // set PEAR's error handling
     // TODO: if PEAR/Command/Install.php is newer than 1.117, displayError goes well.
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$this->ui, 'displayFatalError'));
     // set channel
     $master_setting = Ethna_Handle::getMasterSetting('repositry');
     if ($channel !== null) {
         $this->channel = $channel;
     } else {
         if (isset($master_setting["channel_{$target}"])) {
             $this->channel = $master_setting["channel_{$target}"];
         } else {
             $this->channel = 'pear.ethna.jp';
         }
     }
     // set target controller
     if ($target == 'master') {
         $this->target_ctl = Ethna_Handle::getEthnaController();
     } else {
         $this->target_ctl = Ethna_Handle::getAppController($app_dir);
     }
     if (Ethna::isError($this->target_ctl)) {
         return $this->target_ctl;
     }
     // setup PEAR_Config
     if ($target == 'master') {
         $ret = $this->_setMasterConfig();
     } else {
         $ret = $this->_setLocalConfig();
     }
     if (Ethna::isError($ret)) {
         return $ret;
     }
     $this->ui->setConfig($this->config);
     // setup PEAR_Registry
     $this->registry = $this->config->getRegistry();
     return $true;
 }
$pear_system_config = '';
$store_user_config = false;
$store_system_config = false;
$verbose = 1;
foreach ($opts as $opt) {
    switch ($opt[0]) {
        case 'c':
            $pear_user_config = $opt[1];
            break;
        case 'C':
            $pear_system_config = $opt[1];
            break;
    }
}
PEAR_Command::setFrontendType($fetype);
$ui =& PEAR_Command::getFrontendObject();
$config =& PEAR_Config::singleton($pear_user_config, $pear_system_config);
if (PEAR::isError($config)) {
    $_file = '';
    if ($pear_user_config !== false) {
        $_file .= $pear_user_config;
    }
    if ($pear_system_config !== false) {
        $_file .= '/' . $pear_system_config;
    }
    if ($_file == '/') {
        $_file = 'The default config file';
    }
    $config->getMessage();
    $ui->outputData("ERROR: {$_file} is not a valid config file or is corrupted.");
    // We stop, we have no idea where we are :)
Esempio n. 3
0
 function &getObject($command)
 {
     $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
     if (!class_exists($class)) {
         require_once $GLOBALS['_PEAR_Command_objects'][$class];
     }
     if (!class_exists($class)) {
         return PEAR::raiseError("unknown command `{$command}'");
     }
     $ui =& PEAR_Command::getFrontendObject();
     $config =& PEAR_Config::singleton();
     $obj =& new $class($ui, $config);
     return $obj;
 }
Esempio n. 4
0
 /**
  * Get the right object for executing a command.
  *
  * @param string $command The name of the command
  * @param object $config  Instance of PEAR_Config object
  *
  * @return object the command object or a PEAR error
  *
  * @access public
  * @static
  */
 function factory($command, &$config)
 {
     if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
         PEAR_Command::registerCommands();
     }
     if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
         $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
     }
     if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
         return PEAR::raiseError("unknown command `{$command}'");
     }
     $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
     if (!class_exists($class)) {
         return PEAR::raiseError("unknown command `{$command}'");
     }
     $ui =& PEAR_Command::getFrontendObject();
     $obj =& new $class($ui, $config);
     return $obj;
 }
Esempio n. 5
0
 /**
  * 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"));
 }
Esempio n. 6
0
function _pear_init()
{
    // Remove E_STRICT from error_reporting
    error_reporting(error_reporting() & ~E_STRICT);
    require_once 'PEAR.php';
    require_once 'PEAR/Frontend.php';
    require_once 'PEAR/Config.php';
    require_once 'PEAR/Registry.php';
    require_once 'PEAR/Command.php';
    require_once 'PEAR/Remote.php';
    // current symfony release
    $sf_version = preg_replace('/\\-\\w+$/', '', file_get_contents(sfConfig::get('sf_symfony_lib_dir') . '/VERSION'));
    // PEAR
    PEAR_Command::setFrontendType('CLI');
    $ui =& PEAR_Command::getFrontendObject();
    // read user/system configuration (don't use the singleton)
    $config = new PEAR_Config();
    $config_file = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . '.pearrc';
    // change the configuration for symfony use
    $config->set('php_dir', sfConfig::get('sf_plugins_dir'));
    $config->set('data_dir', sfConfig::get('sf_plugins_dir'));
    $config->set('test_dir', sfConfig::get('sf_plugins_dir'));
    $config->set('doc_dir', sfConfig::get('sf_plugins_dir'));
    $config->set('bin_dir', sfConfig::get('sf_plugins_dir'));
    // change the PEAR temp dir
    $config->set('cache_dir', sfConfig::get('sf_cache_dir'));
    $config->set('download_dir', sfConfig::get('sf_cache_dir'));
    $config->set('tmp_dir', sfConfig::get('sf_cache_dir'));
    // save out configuration file
    $config->writeConfigFile($config_file, 'user');
    // use our configuration file
    $config =& PEAR_Config::singleton($config_file);
    $config->set('verbose', 1);
    $ui->setConfig($config);
    date_default_timezone_set('UTC');
    // register our channel
    $symfony_channel = array('attribs' => array('version' => '1.0', 'xmlns' => 'http://pear.php.net/channel-1.0', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'http://pear.php.net/dtd/channel-1.0 http://pear.php.net/dtd/channel-1.0.xsd'), 'name' => 'pear.symfony-project.com', 'summary' => 'symfony project PEAR channel', 'suggestedalias' => 'symfony', 'servers' => array('primary' => array('rest' => array('baseurl' => array(array('attribs' => array('type' => 'REST1.0'), '_content' => 'http://pear.symfony-project.com/Chiara_PEAR_Server_REST/'), array('attribs' => array('type' => 'REST1.1'), '_content' => 'http://pear.symfony-project.com/Chiara_PEAR_Server_REST/'))))), '_lastmodified' => array('ETag' => "113845-297-dc93f000", 'Last-Modified' => date('r')));
    pake_mkdirs(sfConfig::get('sf_plugins_dir') . '/.channels/.alias');
    file_put_contents(sfConfig::get('sf_plugins_dir') . '/.channels/pear.symfony-project.com.reg', serialize($symfony_channel));
    file_put_contents(sfConfig::get('sf_plugins_dir') . '/.channels/.alias/symfony.txt', 'pear.symfony-project.com');
    // register symfony for dependencies
    $symfony = array('name' => 'symfony', 'channel' => 'pear.symfony-project.com', 'date' => date('Y-m-d'), 'time' => date('H:i:s'), 'version' => array('release' => $sf_version, 'api' => '1.0.0'), 'stability' => array('release' => 'stable', 'api' => 'stable'), 'xsdversion' => '2.0', '_lastmodified' => time(), 'old' => array('version' => $sf_version, 'release_state' => 'stable'));
    $dir = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . '.registry' . DIRECTORY_SEPARATOR . '.channel.pear.symfony-project.com';
    pake_mkdirs($dir);
    file_put_contents($dir . DIRECTORY_SEPARATOR . 'symfony.reg', serialize($symfony));
    return $config;
}
Esempio n. 7
0
 public function __construct($config)
 {
     $this->config = $config;
     \PEAR_Command::setFrontendType('CLI');
     \PEAR_Command::getFrontendObject()->setConfig($this->config);
 }
Esempio n. 8
0
 public function run($argv)
 {
     //        $old = error_reporting(0);
     if (!defined('PEAR_RUNTYPE')) {
         define('PEAR_RUNTYPE', 'pear');
     }
     if (!defined('PEAR_IGNORE_BACKTRACE')) {
         define('PEAR_IGNORE_BACKTRACE', 1);
     }
     @ini_set('allow_url_fopen', true);
     if (!ini_get('safe_mode')) {
         @set_time_limit(0);
     }
     ob_implicit_flush(true);
     @ini_set('track_errors', true);
     @ini_set('html_errors', false);
     @ini_set('magic_quotes_runtime', false);
     $pear_package_version = "1.9.0";
     PEAR_Command::setFrontendType('CLI');
     $this->_allCommands = PEAR_Command::getCommands();
     $progname = PEAR_RUNTYPE;
     array_shift($argv);
     $options = Console_Getopt::getopt2($argv, "c:C:d:D:Gh?sSqu:vV");
     if (PEAR::isError($options)) {
         $this->usage($options);
     }
     $opts = $options[0];
     $store_user_config = false;
     $verbose = 1;
     $config = PEAR_Config::singleton($this->_pearConfigFile, "#no#system#config#");
     if ($config instanceof PEAR_Error) {
         echo $config, "\n";
         exit(1);
     }
     $config->set('verbose', 1);
     //        $config->set('verbose', -1); // supress all kind of annoying stuff.
     $ui = PEAR_Command::getFrontendObject();
     $ui->setConfig($config);
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, "throwException"));
     if (ini_get('safe_mode')) {
         $ui->outputData('WARNING: running in safe mode requires that all files created ' . 'be the same uid as the current script. PHP reports this script is uid: ' . @getmyuid() . ', and current user is: ' . @get_current_user());
     }
     $verbose = $config->get("verbose");
     $cmdopts = array();
     foreach ($opts as $opt) {
         $param = !empty($opt[1]) ? $opt[1] : true;
         switch ($opt[0]) {
             case 'd':
                 if ($param === true) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, ' . 'received "-d"' . "\n");
                 }
                 $possible = explode('=', $param);
                 if (count($possible) != 2) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, received "' . $param . '"' . "\n");
                 }
                 list($key, $value) = explode('=', $param);
                 $config->set($key, $value, 'user');
                 break;
             case 'D':
                 if ($param === true) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, ' . 'received "-d"' . "\n");
                 }
                 $possible = explode('=', $param);
                 if (count($possible) != 2) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, received "' . $param . '"' . "\n");
                 }
                 list($key, $value) = explode('=', $param);
                 $config->set($key, $value, 'system');
                 break;
             case 's':
                 $store_user_config = true;
                 break;
             case 'u':
                 $config->remove($param, 'user');
                 break;
             case 'v':
                 $config->set('verbose', $config->get('verbose') + 1);
                 break;
             case 'q':
                 $config->set('verbose', $config->get('verbose') - 1);
                 break;
             case 'V':
                 $this->usage(null, 'version');
             case 'c':
             case 'C':
                 break;
             default:
                 // all non pear params goes to the command
                 $cmdopts[$opt[0]] = $param;
                 break;
         }
     }
     if ($store_user_config) {
         $config->store('user');
     }
     $command = isset($options[1][0]) ? $options[1][0] : null;
     if (empty($command) && $store_user_config) {
         exit;
     }
     if ($command == 'help') {
         $this->usage(null, @$options[1][1]);
     }
     if (!$config->validConfiguration()) {
         PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files found');
     }
     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
     $cmd = PEAR_Command::factory($command, $config);
     PEAR::popErrorHandling();
     if (PEAR::isError($cmd)) {
         $this->usage(null, @$options[1][0]);
     }
     $short_args = $long_args = null;
     PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
     array_shift($options[1]);
     $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
     if (PEAR::isError($tmp)) {
         break;
     }
     list($tmpopt, $params) = $tmp;
     $opts = array();
     foreach ($tmpopt as $foo => $tmp2) {
         list($opt, $value) = $tmp2;
         if ($value === null) {
             $value = true;
             // options without args
         }
         if (strlen($opt) == 1) {
             $cmdoptions = $cmd->getOptions($command);
             foreach ($cmdoptions as $o => $d) {
                 if (isset($d['shortopt']) && $d['shortopt'] == $opt) {
                     $opts[$o] = $value;
                 }
             }
         } else {
             if (substr($opt, 0, 2) == '--') {
                 $opts[substr($opt, 2)] = $value;
             }
         }
     }
     $ok = $cmd->run($command, $opts, $params);
     if ($ok === false) {
         PEAR::raiseError("unknown command `{$command}'");
     }
     //        error_reporting($old);
 }
Esempio n. 9
0
 /**
  * @access private
  */
 function &_makePackage($setting, $workdir)
 {
     // package.xml を作る
     $pkgconfig = array('packagedirectory' => $workdir, 'outputdirectory' => $workdir, 'ignore' => array('CVS/', '.cvsignore', '.svn/', 'package.xml', '*.ini', $setting['pkgname'] . '-*.tgz'), 'filelistgenerator' => 'file', 'changelogoldtonew' => false);
     $packagexml = new PEAR_PackageFileManager2();
     $pkgconfig = array_merge($pkgconfig, $setting['config']);
     $packagexml->setOptions($pkgconfig);
     $packagexml->setPackage($setting['pkgname']);
     $packagexml->setSummary($setting['summary']);
     $packagexml->setNotes($setting['notes']);
     $packagexml->setDescription($setting['description']);
     $packagexml->setChannel($setting['channel']);
     $packagexml->setAPIVersion($setting['version']);
     $packagexml->setReleaseVersion($setting['version']);
     $packagexml->setReleaseStability($setting['state']);
     $packagexml->setAPIStability($setting['state']);
     $packagexml->setPackageType('php');
     foreach ($setting['maintainers'] as $m) {
         $packagexml->addMaintainer($m['role'], $m['user'], $m['name'], $m['email'], $m['active']);
     }
     $packagexml->setLicense($setting['license']['name'], $setting['license']['uri']);
     $packagexml->addRole('css', 'php');
     $packagexml->addRole('tpl', 'php');
     $packagexml->addRole('ethna', 'php');
     $packagexml->addRole('sh', 'script');
     $packagexml->addRole('bat', 'script');
     $packagexml->setPhpDep('4.3.0');
     $packagexml->setPearinstallerDep('1.3.5');
     $packagexml->generateContents();
     foreach ($setting['callback'] as $method => $params) {
         $r = call_user_func_array(array(&$packagexml, $method), $params);
     }
     $r = $packagexml->writePackageFile();
     if (PEAR::isError($r)) {
         return Ethna::raiseError($r->getMessage, $r->getCode());
     }
     //  finally make package
     PEAR_Command::setFrontendType('CLI');
     $ui = PEAR_Command::getFrontendObject();
     $config = PEAR_Config::singleton();
     $ui->setConfig($config);
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$ui, 'displayFatalError'));
     $cmd = PEAR_Command::factory('package', $config);
     if (PEAR::isError($cmd)) {
         return Ethna::raiseError($cmd->getMessage, $cmd->getCode());
     }
     $r = $cmd->run('package', array(), array("{$workdir}/package.xml"));
     if (PEAR::isError($r)) {
         return Ethna::raiseError($r->getMessage, $r->getCode());
     }
 }