Source for file PearLocal.php

Documentation is available at PearLocal.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  PearLocal.php
  5.  *
  6.  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: 2e7f8297207f5f96d5f3903a30ed9a94c8f6ffc9 $
  10.  */
  11.  
  12. require_once 'PEAR/Config.php';
  13. require_once ETHNA_BASE '/class/PearWrapper.php';
  14.  
  15. // {{{ Ethna_PearConfig_Local
  16. /**
  17.  *  Special Class for Pear Install Handler.
  18.  *  This class should be instantiated by ONLY Ethna_Plugin_Handle_PearLocal.
  19.  *
  20.  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
  21.  *  @access     private
  22.  *  @package    Ethna
  23.  */
  24. class Ethna_PearConfig_Local extends Ethna_PearWrapper
  25. {
  26.  
  27.     // {{{ _setLocalConfig 
  28.     /**
  29.      *  config for local.
  30.      *
  31.      *  @return true|Ethna_Error
  32.      *  @access private
  33.      */
  34.     protected function _setLocalConfig()
  35.     {
  36.         $true true;
  37.  
  38.         // determine dirs
  39.         $base $this->target_ctl->getBaseDir();
  40.         $bin  $this->target_ctl->getDirectory('bin');
  41.         $tmp  $this->target_ctl->getDirectory('tmp');
  42.         $lib  "{$base}/lib";
  43.         $dirs array(
  44.                 'php_dir'       => "$lib",
  45.                 'bin_dir'       => "{$base}/bin",
  46.                 'cache_dir'     => "{$tmp}/.pear/cache",
  47.                 'download_dir'  => "{$lib}/.pear/download",
  48.                 'temp_dir'      => "{$lib}/.pear/temp",
  49.                 'doc_dir'       => "{$lib}/.pear/doc",
  50.                 'ext_dir'       => "{$lib}/.pear/ext",
  51.                 'data_dir'      => "{$lib}/.pear/data",
  52.                 'test_dir'      => "{$lib}/.pear/test",
  53.                 );
  54.  
  55.         $default_pearrc "{$base}"
  56.                         . DIRECTORY_SEPARATOR
  57.                         . "lib"
  58.                         . DIRECTORY_SEPARATOR
  59.                         . "pear.conf";
  60.         $app_config $this->target_ctl->getConfig();
  61.         $app_pearrc $app_config->get('app_pear_local_config');
  62.         $pearrc (empty($app_pearrc))
  63.                 ? $default_pearrc
  64.                 : "{$base}/$app_pearrc";
  65.         $this->conf_file $pearrc;
  66.         $this->config PEAR_Config::singleton($pearrc);
  67.  
  68.         // read local .pearrc if exists.
  69.         if (is_file($pearrc&& is_readable($pearrc)) {
  70.             $this->config->readConfigFile($pearrc);
  71.         }
  72.  
  73.         // set dirs to config
  74.         foreach ($dirs as $key => $dir{
  75.             $_dir $this->config->get($key'user');
  76.             if (!isset($_dir)) {
  77.                 if (is_dir($dir== false{
  78.                     Ethna_Util::mkdir($dir0755);
  79.                 }
  80.                 $this->config->set($key$dir);
  81.             }
  82.         }
  83.  
  84.         if ($this->channel == 'dummy'{
  85.             $default_channel $this->config->get('default_channel''user');
  86.             $this->channel (empty($default_channel))
  87.                            ? 'pear.php.net'
  88.                            : $default_channel;
  89.         }
  90.  
  91.         // setup channel
  92.         $reg $this->config->getRegistry();
  93.         if ($reg->channelExists($this->channel== false{
  94.             $ret $this->doChannelDiscover();
  95.             if (Ethna::isError($ret)) {
  96.                 return $ret;
  97.             }
  98.         }
  99.         $this->config->set('default_channel'$this->channel);
  100.  
  101.         // write local .pearrc
  102.         $this->config->writeConfigFile($pearrc);
  103.  
  104.         return $true;
  105.     }
  106.     // }}}
  107.  
  108.     // {{{ getConfFile 
  109.     /**
  110.      *    return local config filename.
  111.      */
  112.      function getConfFile()
  113.      {
  114.          return $this->conf_file;
  115.  
  116.      }
  117.      // }}}
  118. }
  119. // }}}
  120.  
  121. // {{{ Ethna_Plugin_Handle_PearLocal
  122. /**
  123.  *  pear package install handler
  124.  *
  125.  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
  126.  *  @access     public
  127.  *  @package    Ethna
  128.  */
  129. {
  130.     // {{{ _parseArgList() 
  131.     /**
  132.      * @access private
  133.      */
  134.     function _parseArgList()
  135.     {
  136.         $r $this->_getopt(array('basedir=''channel='));
  137.         if (Ethna::isError($r)) {
  138.             return $r;
  139.         }
  140.  
  141.         list($opt_list$arg_list$r;
  142.         $ret array();
  143.  
  144.         // options
  145.         if (isset($opt_list['basedir'])) {
  146.             $ret['basedir'end($opt_list['basedir']);
  147.         }
  148.         if (isset($opt_list['channel'])) {
  149.             $ret['channel'end($opt_list['channel']);
  150.         }
  151.  
  152.         // arguments
  153.         $ret['pear_args'$arg_list;
  154.  
  155.         return $ret;
  156.     }
  157.     // }}}
  158.  
  159.     // {{{ perform()
  160.     /**
  161.      *  @access public
  162.      *  @todo   deal with the package including some plugins.
  163.      */
  164.     public function perform()
  165.     {
  166.         $true true;
  167.  
  168.         //   check arguments.
  169.         $args $this->_parseArgList();
  170.         if (Ethna::isError($args)) {
  171.             return Ethna::raiseError(
  172.                 $args->getMessage(),
  173.                 'usage'
  174.             );
  175.         }
  176.  
  177.         $basedir = isset($args['basedir']realpath($args['basedir']getcwd();
  178.         $channel = isset($args['channel']$args['channel''dummy';
  179.  
  180.         $pear_local new Ethna_PearConfig_Local();
  181.         $r $pear_local->init('local'$basedir$channel);
  182.         if (Ethna::isError($r)) {
  183.             return $r;
  184.         }
  185.  
  186.         //    build command string.
  187.         $pear_cmds $args['pear_args'];
  188.         $pear_bin (ETHNA_OS_WINDOWS)
  189.                   ? getenv('PHP_PEAR_BIN_DIR'DIRECTORY_SEPARATOR 'pear.bat'
  190.                   : (PHP_BINDIR DIRECTORY_SEPARATOR 'pear');
  191.         $local_conf_file $pear_local->getConfFile();
  192.         array_unshift(
  193.             $pear_cmds,
  194.             $pear_bin,
  195.             '-c',
  196.             $local_conf_file
  197.         );
  198.         if (ETHNA_OS_WINDOWS{
  199.             foreach($pear_cmds as $key => $value{
  200.                 $pear_cmds[$key(strpos($value' '!== false)
  201.                                  ? ('"' $value '"')
  202.                                  : $value;
  203.             }
  204.         }
  205.         $command_str implode(' '$pear_cmds);
  206.  
  207.         //   finally exec pear command.
  208.         if (ETHNA_OS_WINDOWS{
  209.             $tmp_dir_name ="ethna_tmp_dir";
  210.             Ethna_Util::mkdir($tmp_dir_name0777);
  211.             $tmpnam tempnam($tmp_dir_name"temp".'.bat';
  212.             $fp fopen($tmpnam'w');
  213.             fwrite($fp"@echo off\r\n");
  214.             fwrite($fp$command_str " 2>&1");
  215.             fclose ($fp);
  216.             system($tmpnam);
  217.             Ethna_Util::purgeDir($tmp_dir_name);
  218.         else {
  219.             system($command_str);
  220.         }
  221.  
  222.         return $true;
  223.     }
  224.     // }}}
  225.  
  226.     // {{{ getDescription()
  227.     /**
  228.      *  @access public
  229.      */
  230.     public function getDescription()
  231.     {
  232.         return <<<EOS
  233. install pear package to {base_dir}/lib, {base_dir}/bin ... :
  234.     {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [pear command ...]
  235.     for more pear command information, see "pear help"
  236.  
  237. EOS;
  238.     }
  239.     // }}}
  240.  
  241.     // {{{ getUsage()
  242.     /**
  243.      *  @access public
  244.      */
  245.     public function getUsage()
  246.     {
  247.         return <<<EOS
  248. ethna {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [pear command ...]
  249.     for more pear command information, see "pear help"
  250.  
  251. EOS;
  252.     }
  253.     // }}}
  254. }
  255. // }}}

Documentation generated on Fri, 11 Nov 2011 03:58:50 +0900 by phpDocumentor 1.4.3