Source for file Ethna_PearWrapper.php
Documentation is available at Ethna_PearWrapper.php
- // vim: foldmethod=marker 
-  *  @author     ICHII Takashi <ichii386@schweetheart.jp> 
-  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License 
- require_once 'PEAR/Config.php'; 
- require_once 'PEAR/Command.php'; 
- require_once 'PEAR/PackageFile.php'; 
-  *  wrapper class for PEAR_Command 
-  *  This class should be instantiated in ethna handler. 
-  *  @author     ICHII Takashi <ichii386@schweetheart.jp> 
-     /** @var    string  channel url of ethna repositry */ 
-     /** @var    string  target, 'master' or 'local' */ 
-     /** @var    object  controller object collesponding to the target */ 
-     /** @var    object  PEAR_Config     PEAR_Config object */ 
-     /** @var    object  PEAR_Registry   PEAR_Registry object */ 
-     /** @var    object  PEAR_Frontend   PEAR_Frontend(_CLI) object */ 
-     /** @var    array   options for pearcmd */ 
-     // {{{ constructor, initializer 
-      *  Ethna_PearWrapper constructor 
-         $this->target_ctl - =  null;
 
-      *  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 
-     function &init($target, $app_dir - =  null, $channel- =  null)
 
-         if ($target - ==  'master') {
 
-             $this->target - =  'master';
 
-             // default target is 'local'. 
-         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')); 
-             $this->channel - =  $channel;
 
-         } else if (- isset ($master_setting["channel_{$target}"])) {
 
-             $this->channel - =  $master_setting["channel_{$target}"];
 
-             $this->channel - =  'pear.ethna.jp';
 
-         if ($target - ==  'master') {
 
-             return $this->target_ctl; 
-         if ($target - ==  'master') {
 
-             $ret - = & $this->_setMasterConfig();
 
-             $ret - = & $this->_setLocalConfig();
 
-         $this->ui->setConfig($this->config); 
-         $this->registry - = & $this->config->getRegistry();
 
-      *  @return true|Ethna_Error 
-     function &_setMasterConfig() 
-         $this->config - = & PEAR_Config::singleton();
 
-         $reg - = & $this->config->getRegistry();
 
-         if ($reg->channelExists($this->channel) - ==  false) {
 
-      *  @return true|Ethna_Error 
-     function &_setLocalConfig() 
-         $base - =  $this->target_ctl->getBaseDir();
 
-         $bin  - =  $this->target_ctl->getDirectory('bin');
 
-         $tmp  - =  $this->target_ctl->getDirectory('tmp');
 
-                 'php_dir'       - =>  "- { $base}- /skel ",
 
-                 'cache_dir'     - =>  "- { $tmp}- /.pear/cache ",
 
-                 'download_dir'  - =>  "- { $tmp}- /.pear/download ",
 
-                 'temp_dir'      - =>  "- { $tmp}- /.pear/temp ",
 
-                 'doc_dir'       - =>  "- { $tmp}- /.pear/doc ",
 
-                 'ext_dir'       - =>  "- { $tmp}- /.pear/ext ",
 
-                 'data_dir'      - =>  "- { $tmp}- /.pear/data ",
 
-                 'test_dir'      - =>  "- { $tmp}- /.pear/test ",
 
-         foreach ($dirs as $key - =>  $dir) {
 
-         $pearrc - =  "- { $base}- /skel/.pearrc ";
 
-         $this->config - = & PEAR_Config::singleton($pearrc);
 
-         // read local .pearrc if exists. 
-             $this->config->readConfigFile($pearrc); 
-         foreach ($dirs as $key - =>  $dir) {
 
-             $this->config->set($key, $dir); 
-         $reg - = & $this->config->getRegistry();
 
-         if ($reg->channelExists($this->channel) - ==  false) {
 
-         $this->config->set('default_channel', $this->channel); 
-         $this->config->writeConfigFile(); 
-      *  @return true|Ethna_Error 
-         $r - = & $this->_run('clear-cache', array(), array());
 
-      *  @return true|Ethna_Error 
-         $r - = & $this->_run('channel-discover', array(), array($this->channel));
 
-      *  whether channel discovered or not 
-         return $this->registry->channelExists($this->channel); 
-      *  @return true|Ethna_Error 
-         $r - = & $this->_run('channel-update', array(), array($this->channel));
 
-     // {{{ _doInstallOrUpgrade 
-      *  @param  string  $command    'install' or 'upgrade' 
-      *  @param  string  $package    package string 
-      *  @return true|Ethna_Error 
-     function &_doInstallOrUpgrade($command, $package) 
-         $r - = & $this->_run($command, array(), array($package));
 
-      *  @param  string  $pkg_name   package name. 
-      *  @param  string  $state      package state. 
-      *  @return true|Ethna_Error 
-     function &doInstall($pkg_name, $state - =  null)
 
-         $pkg - =  "- { $this->channel}- /{ $pkg_name}";
 
-             $pkg = "- { $pkg}- -{ $state}";
 
-         $r =& $this->_doInstallOrUpgrade('install', $pkg);  
-      *  do install from local tgz file 
-      *  @param  string  $pkg_file   package filename 
-      *  @return true|Ethna_Error 
-     function &doInstallFromTgz($pkg_file) 
-         $r =& $this->_doInstallOrUpgrade('install', $pkg_file);  
-      *  @param  string  $pkg_name   package name. 
-      *  @param  string  $state      package state. 
-      *  @return true|Ethna_Error 
-     function &doUpgrade($pkg_name, $state = null) 
-         $pkg = "- { $this->channel}- /{ $pkg_name}";
 
-             $pkg = "- { $pkg}- -{ $state}";
 
-         $r =& $this->_doInstallOrUpgrade('upgrade', $pkg); 
-      *  do upgrade from local tgz file 
-      *  @param  string  $pkg_file   package filename 
-      *  @return true|Ethna_Error 
-     function &doUpgradeFromTgz($pkg_file) 
-         $r =& $this->_doInstallOrUpgrade('upgrade', $pkg_file);  
-      *  check package installed 
-      *  @param  string  $package package name 
-     function isInstalled($package) 
-         return $this->registry->packageExists($package, $this->channel); 
-      *  @param  string  $package package name 
-      *  @return string  version string 
-     function getVersion($package) 
-         $pobj =& $this->registry->getPackage($package, $this->channel); 
-         return $pobj->getVersion(); 
-      *  @param  string  $package package name 
-      *  @return string  version string 
-     function getState($package) 
-         $pobj =& $this->registry->getPackage($package, $this->channel); 
-         return $pobj->getState(); 
-      *  do uninstall (packages installed with ethna command) 
-      *  @return true|Ethna_Error 
-     function &doUninstall($package) 
-             return Ethna::raiseNotice("- { $this->channel}- /{ $package}-  is not installed. ");
 
-         $r =& $this->_run('uninstall', array(), array("- { $this->channel}- /{ $package}"));
 
-             return Ethna::raiseNotice("uninstall failed: - { $this->channel}- /{ $package}");
 
-     // {{{ getPackageNameFromTgz 
-      *  get package info from tar/tgz file. 
-      *  @param  string  $filename   package file name. 
-      *  @return string  package name 
-     function &getPackageNameFromTgz($filename) 
-         $config =& PEAR_Config::singleton(); 
-         $packagefile =& new PEAR_PackageFile($config); 
-         $info =& $packagefile->fromTgzFile($filename, PEAR_VALIDATE_NORMAL); 
-         if (PEAR::isError($info)) { 
-         $info_array = $info->toArray(); 
-         return $info_array['name']; 
-     // {{{ getCanonicalPackageName 
-      *  get canonical package name (case sensitive) 
-      *  @param  string  $package    package name. 
-      *  @return string  canonical name 
-     function &getCanonicalPackageName($package) 
-             return Ethna::raiseNotice("- { $this->channel}- /{ $package}-  is not installed. ");
 
-         $pobj =& $this->registry->getPackage($package, $this->channel); 
-         $cname - =  $pobj->getName();
 
-     // {{{ getInstalledPackageList 
-      *  get installed package list 
-      *  @return array   installed package list 
-     function &getInstalledPackageList() 
-         foreach ($this->registry->listPackages($this->channel) as $pkg) { 
-      *  do info (packages installed with ethna command) 
-      *  @param  string  $package    package name. 
-      *  @return true|Ethna_Error 
-     function &doInfo($package) 
-         return $this->_run('info', array(), array("- { $this->channel}- /{ $package}"));
 
-      *  do info (packages installable with ethna command) 
-      *  @param  string  $package    package name. 
-      *  @return true|Ethna_Error 
-     function &doRemoteInfo($package) 
-         return $this->_run('remote-info', array(), array("- { $this->channel}- /{ $package}"));
 
-      *  @return true|Ethna_Error 
-         return $this->_run('upgrade-all', array('channel' - =>  "- { $this->channel}"), array());
 
-      *  do list (packages installed with ethna command) 
-      *  @return true|Ethna_Error 
-         return $this->_run('list', array('channel' - =>  $this->channel), array());
 
-      *  do remote-list (packages installable with ethna command) 
-      *  @return true|Ethna_Error 
-         return $this->_run('remote-list', array('channel' - =>  $this->channel), array());
 
-      *  @param  string  $command    command name 
-      *  @param  array   $options    options 
-      *  @param  array   $params     parameters 
-      *  @return true|Ethna_Error 
-      *  @see PEAR_Command_Common::run, etc. 
-     function &_run($command, $options, $params) 
-         if ($this->config - ===  null) {
 
-             return Ethna::raiseError('configuration not initialized.'); 
-         $cmd =& PEAR_Command::factory($command, $this->config); 
-         if (PEAR::isError($cmd)) { 
-         if (is_array($this->_pearopt) - &&  count($this->_pearopt)- >  0) {
 
-             $pearopts = $this->_getPearOpt($cmd, $command, $this->_pearopt); 
-             $options - =  array_merge($pearopts, $options);
 
-         $ret = $cmd->run($command, $options, $params); 
-         if (PEAR::isError($ret)) { 
-      *  provide yes-or-no dialog. 
-     function confirmDialog($message, $default = 'yes') 
-         $ret = $this->ui->userConfirm($message); 
-      *  @param  array   $headline   headline 
-      *  @param  array   $rows       rows which have the same size as headline's. 
-     function displayTable($caption, $headline, $rows) 
-         foreach (array_keys($headline) as $k) { 
-             $headline[$k] = sprintf('% -8s', $headline[$k]); 
-         $data = array('caption'  => $caption, 
-         $this->ui->outputData($data); 
-     function setPearOpt($pearopt) 
-         $this->_pearopt - =  $pearopt;
 
-     function _getPearOpt(&$cmd_obj, $cmd_str, $opt_array) 
-         $short_args = $long_args = null; 
-         PEAR_Command::getGetOptArgs($cmd_str, $short_args, $long_args); 
-         $opt = new Ethna_Getopt(); 
-         $opt_arg = $opt->getopt($opt_array, $short_args, $long_args); 
-         if (Ethna::isError($opt_arg)) return array(); 
-         foreach ($opt_arg[0] as $tmp) { 
-             if ($val === null) $val = true; 
-                 $cmd_opts = $cmd_obj->getOptions($cmd_str); 
-                 foreach ($cmd_opts as $o - =>  $d) {
 
-                     if (isset($d['shortopt']) && $d['shortopt'] == $opt) { 
-                 if (substr($opt, 0, 2) == '--') $opts[substr($opt, 2)] = $val; 
 
	
		Documentation generated on Fri, 11 Nov 2011 03:59:59 +0900 by phpDocumentor 1.4.3