Source for file Ethna_Plugin_Handle_InstallPlugin.php

Documentation is available at Ethna_Plugin_Handle_InstallPlugin.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Plugin_Handle_InstallPlugin.php
  5.  *
  6.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id$
  10.  */
  11.  
  12. require_once ETHNA_BASE . '/class/Ethna_PearWrapper.php';
  13.  
  14. // {{{ Ethna_Plugin_Handle_InstallPlugin
  15. /**
  16.  *  install-plugin handler
  17.  *
  18.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  19.  *  @access     public
  20.  *  @package    Ethna
  21.  */
  22. {
  23.     // {{{ _parseArgList()
  24.     /**
  25.      * @access private
  26.      */
  27.     function &_parseArgList()
  28.     {
  29.         $r =& $this->_getopt(array('local', 'master', 'state=',
  30.                                    'basedir=', 'channel=', 'pearopt='));
  31.         if (Ethna::isError($r)) {
  32.             return $r;
  33.         }
  34.         list($opt_list, $arg_list) = $r;
  35.         $ret = array();
  36.  
  37.         // options
  38.         $ret['target'] = isset($opt_list['master']) ? 'master' : 'local';
  39.         if (isset($opt_list['basedir'])) {
  40.             $ret['basedir'] = end($opt_list['basedir']);
  41.         }
  42.         if (isset($opt_list['channel'])) {
  43.             $ret['channel'] = end($opt_list['channel']);
  44.         }
  45.         if (isset($opt_list['state'])) {
  46.             $ret['state'] = end($opt_list['state']);
  47.         }
  48.         if (isset($opt_list['pearopt'])) {
  49.             $ret['pearopt'] = $opt_list['pearopt'];
  50.         }
  51.  
  52.         // arguments
  53.         if (count($arg_list) == 2) {
  54.             $ret['type'] = $arg_list[0];
  55.             $ret['name'] = $arg_list[1];
  56.         } else if (count($arg_list) == 1) {
  57.             $ret['pkg_file_or_url'] = $arg_list[0];
  58.         }
  59.  
  60.         return $ret;
  61.     }
  62.     // }}}
  63.  
  64.     // {{{ perform()
  65.     /**
  66.      *  @access public
  67.      *  @todo   deal with the package including some plugins.
  68.      */
  69.     function perform()
  70.     {
  71.         $args =& $this->_parseArgList();
  72.         if (Ethna::isError($args)) {
  73.             return $args;
  74.         }
  75.  
  76.         $pear =& new Ethna_PearWrapper();
  77.         if (isset($args['pearopt'])) {
  78.             $pear->setPearOpt($args['pearopt']);
  79.         }
  80.  
  81.         if (isset($args['pkg_file_or_url'])) {
  82.             // install from local tgz.
  83.             $pkg_file_or_url = $args['pkg_file_or_url'];
  84.             $pkg_name =& Ethna_PearWrapper::getPackageNameFromTgz($pkg_file_or_url);
  85.             if (Ethna::isError($pkg_name)) {
  86.                 return $pkg_name;
  87.             }
  88.             list($appid,, $ctype, $cname) = explode('_', $pkg_name, 4);
  89.             $target = isset($args['target']) ? $args['target'] : null;
  90.             if ($target == 'master') {
  91.                 if ($appid != 'Ethna') {
  92.                     return Ethna::raiseError("this package is not for master.");
  93.                 }
  94.             } else {
  95.                 if ($appid == 'Ethna') {
  96.                     return Ethna::raiseError("this package is not for local.");
  97.                 }
  98.             }
  99.             $channel = isset($args['channel']) ? $args['channel'] : null;
  100.             $basedir = isset($args['basedir']) ? realpath($args['basedir']) : getcwd();
  101.  
  102.             $r =& $pear->init($target, $basedir, $channel);
  103.             if (Ethna::isError($r)) {
  104.                 return $r;
  105.             }
  106.             $r =& $pear->doInstallFromTgz($pkg_file_or_url, $pkg_name);
  107.             if (Ethna::isError($r)) {
  108.                 return $r;
  109.             }
  110.  
  111.         } else if (isset($args['type']) && isset($args['name'])) {
  112.             // install from repository.
  113.             $target = isset($args['target']) ? $args['target'] : null;
  114.             $channel = isset($args['channel']) ? $args['channel'] : null;
  115.             $basedir = isset($args['basedir']) ? realpath($args['basedir']) : getcwd();
  116.             $state = isset($args['state']) ? $args['state'] : null;
  117.             if ($target == 'master') {
  118.                 $pkg_name = sprintf('Ethna_Plugin_%s_%s', $args['type'], $args['name']);
  119.             } else {
  120.                 $pkg_name = sprintf('App_Plugin_%s_%s', $args['type'], $args['name']);
  121.             }
  122.  
  123.             $r =& $pear->init($target, $basedir, $channel);
  124.             if (Ethna::isError($r)) {
  125.                 return $r;
  126.             }
  127.             $r =& $pear->doInstall($pkg_name, $state);
  128.             if (Ethna::isError($r)) {
  129.                 return $r;
  130.             }
  131.  
  132.             $pkg_name = $pear->getCanonicalPackageName($pkg_name);
  133.             if (Ethna::isError($pkg_name)) {
  134.                 return $pkg_name;
  135.             }
  136.  
  137.         } else {
  138.             return Ethna::raiseError('invalid number of arguments', 'usage');
  139.         }
  140.  
  141.         if ($target != 'master') {
  142.             list(,, $ctype, $cname) = explode('_', $pkg_name, 4);
  143.             $r = Ethna_Generator::generate('Plugin', $basedir, $ctype, $cname, true);
  144.             if (Ethna::isError($r)) {
  145.                 return $r;
  146.             }
  147.         }
  148.  
  149.         return true;
  150.     }
  151.     // }}}
  152.  
  153.     // {{{ getDescription()
  154.     /**
  155.      *  @access public
  156.      */
  157.     function getDescription()
  158.     {
  159.         return <<<EOS
  160. install plugin:
  161.     {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [-l|--local] [-m|--master] [type name|packagefile|packageurl]
  162.  
  163. EOS;
  164.     }
  165.     // }}}
  166.  
  167.     // {{{
  168.     /**
  169.      *  @access public
  170.      */
  171.     function getUsage()
  172.     {
  173.         return <<<EOS
  174. ethna {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [-l|--local] [-m|--master] [type name|packagefile|packageurl]
  175. EOS;
  176.     }
  177.     // }}}
  178. }
  179. // }}}
  180. ?>

Documentation generated on Fri, 11 Nov 2011 04:00:28 +0900 by phpDocumentor 1.4.3