Source for file Ethna_Plugin_Handle_ListPlugin.php

Documentation is available at Ethna_Plugin_Handle_ListPlugin.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Plugin_Handle_ListPlugin.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_ListPlugin
  15. /**
  16.  *  list-plugin handler
  17.  *
  18.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  19.  *  @access     public
  20.  *  @package    Ethna
  21.  */
  22. {
  23.     // {{{ perform()
  24.     /**
  25.      *  @access public
  26.      */
  27.     function perform()
  28.     {
  29.         $r =$this->_getopt(array('local''master',  'type=',
  30.                                    'basedir=''channel=''verbose'));
  31.         if (Ethna::isError($r)) {
  32.             return $r;
  33.         }
  34.         list($args,$r;
  35.  
  36.         $target = isset($args['master']'master' 'local';
  37.         $channel = isset($args['channel']end($args['channel']null;
  38.         $basedir = isset($args['basedir']realpath(end($args['basedir'])) getcwd();
  39.         $verbose = isset($args['verbose']);
  40.         $type = isset($args['type']end($args['type']null;
  41.  
  42.         // prepare PearWrapper object.
  43.         $pear =new Ethna_PearWrapper();
  44.         $r =$pear->init($target$basedir$channel);
  45.         if (Ethna::isError($r)) {
  46.             return $r;
  47.         }
  48.  
  49.         // get plugin list.
  50.         $plugins_found $this->_getFoundPluginList($pear$type);
  51.         if (Ethna::isError($plugins_found)) {
  52.             return $plugins_found;
  53.         }
  54.         $plugins_installed $this->_getInstalledPluginList($pear$type);
  55.         if (Ethna::isError($plugins_installed)) {
  56.             return $plugins_installed;
  57.         }
  58.  
  59.         // create table data.
  60.         $data array();
  61.         $class_list array_merge(array_keys($plugins_found)array_keys($plugins_installed));
  62.         sort($class_list);
  63.         $class_list array_unique($class_list);
  64.         foreach ($class_list as $class_name{
  65.             $tmp array();
  66.  
  67.             // check found plugin.
  68.             if (isset($plugins_found[$class_name])) {
  69.                 list($type$name$plugins_found[$class_name];
  70.                 $tmp[0$type;
  71.                 $tmp[1$name;
  72.                 $tmp[2$class_name;
  73.                 $tmp[3'-';
  74.                 if ($verbose{
  75.                     $tmp[4'-';
  76.                     $tmp[5'-';
  77.                 }
  78.             }
  79.  
  80.             // check installed plugin.
  81.             if (isset($plugins_installed[$class_name])) {
  82.                 list($type$name$pkg_name$pkg_version$pkg_state)
  83.                     = $plugins_installed[$class_name];
  84.                 if (isset($tmp[0])) {
  85.                     $tmp[3$pkg_name;
  86.                     if ($verbose{
  87.                         $tmp[4$pkg_version;
  88.                         $tmp[5$pkg_state;
  89.                     }
  90.                 else {
  91.                     // this plugin is only in skelton
  92.                     $tmp[0$type;
  93.                     $tmp[1$name;
  94.                     $tmp[2'-';
  95.                     $tmp[3$pkg_name;
  96.                     if ($verbose{
  97.                         $tmp[4$pkg_version;
  98.                         $tmp[5$pkg_state;
  99.                     }
  100.                 }
  101.             }
  102.  
  103.             if (isset($tmp[0])) {
  104.                 $data[$tmp;
  105.             }
  106.         }
  107.  
  108.         usort($dataarray(&$this'_sort'));
  109.         if ($verbose{
  110.             $pear->displayTable('installed plugins',
  111.                 array('type''name''class''package''version''state'),
  112.                 $data);
  113.         else {
  114.             $pear->displayTable('installed plugins',
  115.                 array('type''name''class''package'),
  116.                 $data);
  117.         }
  118.         return true;
  119.     }
  120.     // }}}
  121.  
  122.     // {{{ _getInstalledPluginList()
  123.     /**
  124.      *  get a list of plugins under pear installation management.
  125.      *
  126.      *  @param  object  $pear   Ethna_PearWrapper object.
  127.      *  @param  string  $_type   plugin type
  128.      *  @return array   package list
  129.      *  @access private
  130.      *  @todo   deal with the package including some plugins.
  131.      */
  132.     function &_getInstalledPluginList(&$pear$_type null)
  133.     {
  134.         $pkg_list =$pear->getInstalledPackageList();
  135.         if (Ethna::isError($pkg_list)) {
  136.             return $pkg_list;
  137.         }
  138.  
  139.         $ret array();
  140.  
  141.         $plugin =$pear->target_ctl->getPlugin();
  142.         $appid $pear->target_ctl->getAppId();
  143.         $test_prefix $pear->target == 'master' 'Ethna' 'App';
  144.  
  145.         foreach ($pkg_list as $pkg_name{
  146.             list($prefix,, $type$nameexplode('_'$pkg_name4);
  147.             if (($_type === null || $_type == $type&& $prefix == $test_prefix{
  148.                 list($class_name,,$plugin->getPluginNaming($type$name$appid);
  149.                 $pkg_version $pear->getVersion($pkg_name);
  150.                 $pkg_state $pear->getState($pkg_name);
  151.                 $ret[$class_namearray($type$name$pkg_name,
  152.                                           $pkg_version$pkg_state);
  153.             }
  154.         }
  155.         return $ret;
  156.     }
  157.     // }}}
  158.  
  159.     // {{{ _getFoundPluginList()
  160.     /**
  161.      *  get a list of plugins found from controller.
  162.      *  (a local plugin might be installed but still in only skelton.)
  163.      *
  164.      *  @param  object  $pear   Ethna_PearWrapper object.
  165.      *  @param  string  $_type   plugin type
  166.      *  @return array   package list
  167.      *  @access private
  168.      */
  169.     function &_getFoundPluginList(&$pear$_type null)
  170.     {
  171.         $ret array();
  172.  
  173.         $plugin =$pear->target_ctl->getPlugin();
  174.         $type_list $_type === null $plugin->searchAllPluginType(array($_type);
  175.  
  176.         foreach ($type_list as $type{
  177.             $plugin->searchAllPluginSrc($type);
  178.             if (isset($plugin->src_registry[$type]=== false{
  179.                 continue;
  180.             }
  181.             foreach ($plugin->src_registry[$typeas $name => $src{
  182.                 if (empty($src)) {
  183.                     continue;
  184.                 }
  185.                 list($appid,, $type$nameexplode('_'$src[0]4);
  186.                 if (($pear->target == 'master' && $appid == 'Ethna'|| $appid != 'Ethna'{
  187.                     // XXX: src is private! ([0] is class name)
  188.                     $ret[$src[0]] array($type$name);
  189.                 }
  190.             }
  191.         }
  192.         return $ret;
  193.     }
  194.     // }}}
  195.  
  196.     // {{{ _sort
  197.     /**
  198.      *  sort callback method
  199.      */
  200.     function _sort($a$b)
  201.     {
  202.         $cmp_type strcmp($a[0]$b[0]);
  203.         if ($cmp_type !== 0{
  204.             return $cmp_type;
  205.         }
  206.         $cmp_name strcmp($a[1]$b[1]);
  207.         if ($cmp_name !== 0{
  208.             return $cmp_name;
  209.         }
  210.         return 0;
  211.     }
  212.     // }}}
  213.  
  214.     // {{{ getDescription()
  215.     /**
  216.      *  @access public
  217.      */
  218.     function getDescription()
  219.     {
  220.         return <<<EOS
  221. list local or master plugins. if type (case sensitive) not specified, list all plugins:
  222.     {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [-l|--local] [-m|--master] [-t|--type=type] [-v|--verbose]
  223.  
  224. EOS;
  225.     }
  226.     // }}}
  227.  
  228.     // {{{ getUsage()
  229.     /**
  230.      *  @access public
  231.      */
  232.     function getUsage()
  233.     {
  234.         return <<<EOS
  235. ethna {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [-l|--local] [-m|--master] [-t|--type=type] [-v|--verbose]
  236. EOS;
  237.     }
  238.     // }}}
  239. }
  240. // }}}
  241.  
  242. ?>

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