Source for file ethna_handle.php

Documentation is available at ethna_handle.php

  1. <?php
  2. /**
  3.  *  ethna_handle.php
  4.  *
  5.  *  Ethna Handle Gateway
  6.  *
  7.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  8.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  9.  *  @package    Ethna
  10.  *  @version    $Id: e735af381befc74577edecb7ff1a4ac02ee5ac1b $
  11.  */
  12. while (ob_get_level()) {
  13.     ob_end_clean();
  14. }
  15.  
  16. $base dirname(dirname(dirname(__FILE__)));
  17. ini_set('include_path'$base.PATH_SEPARATOR.ini_get('include_path'));
  18.  
  19. require_once 'Ethna/Ethna.php';
  20. require_once ETHNA_BASE '/class/Getopt.php';
  21.  
  22. // fetch arguments
  23. $opt new Ethna_Getopt();
  24. $arg_list $opt->readPHPArgv();
  25. if (Ethna::isError($arg_list)) {
  26.     echo $arg_list->getMessage()."\n";
  27.     exit(2);
  28. }
  29. array_shift($arg_list);  // remove "ethna_handle.php"
  30.  
  31. $eh new Ethna_Handle();
  32. if ($dot_ethna getenv('DOT_ETHNA')) {
  33.     $app_controller Ethna_Handle::getAppController(dirname($dot_ethna));
  34. }
  35.  
  36.  
  37. //  はじめの引数に - が含まれていればそれを分離する
  38. //  含まれていた場合、それは -v|--version でなければならない
  39. list($my_arg_list$arg_list_Ethna_HandleGateway_SeparateArgList($arg_list);
  40. $r $opt->getopt($my_arg_list"v"array("version"));
  41. if (Ethna::isError($r)) {
  42.     $id 'help';
  43. else {
  44.     // ad-hoc:(
  45.     foreach ($r[0as $opt{
  46.         if ($opt[0== "v" || $opt[0== "--version"{
  47.             _Ethna_HandleGateway_ShowVersion();
  48.             exit(2);
  49.         }
  50.     }
  51. }
  52.  
  53. if (count($arg_list== 0{
  54.     $id 'help';
  55. else {
  56.     $id array_shift($arg_list);
  57. }
  58.  
  59. $handler =$eh->getHandler($id);
  60. $handler->eh =$eh;
  61. if (Ethna::isError($handler)) {
  62.     printf("no such command: %s\n\n"$id);
  63.     $id 'help';
  64.     $handler =$eh->getHandler($id);
  65.     $handler->eh =$eh;
  66.     if (Ethna::isError($handler)) {
  67.        exit(1);  //  should not happen.
  68.     
  69. }
  70.  
  71. // don't know what will happen:)
  72. $handler->setArgList($arg_list);
  73. $r $handler->perform();
  74. if (Ethna::isError($r)) {
  75.     printf("error occured w/ command [%s]\n  -> %s\n\n"$id$r->getMessage());
  76.     if ($r->getCode(== 'usage'{
  77.         $handler->usage();
  78.     }
  79.     exit(1);
  80. }
  81.  
  82. /**
  83.  *  fetch options for myself
  84.  */
  85. {
  86.     $my_arg_list array();
  87.  
  88.     //  はじめの引数に - が含まれていたら、
  89.     //  それを $my_arg_list に入れる
  90.     //  これは --version 判定のため 
  91.     for ($i 0$i count($arg_list)$i++{
  92.         if ($arg_list[$i]{0== '-'{
  93.             // assume this should be an option for myself
  94.             $my_arg_list[$arg_list[$i];
  95.         else {
  96.             break;
  97.         }
  98.     }
  99.     $arg_list array_slice($arg_list$i);
  100.  
  101.     return array($my_arg_list$arg_list);
  102. }
  103.  
  104. /**
  105.  *  show version
  106.  */
  107. {
  108.     $version = <<<EOD
  109. Ethna %s (using PHP %s)
  110.  
  111. Copyright (c) 2004-%s,
  112.   Masaki Fujimoto <fujimoto@php.net>
  113.   halt feits <halt.feits@gmail.com>
  114.   Takuya Ookubo <sfio@sakura.ai.to>
  115.   nozzzzz <nozzzzz@gmail.com>
  116.   cocoitiban <cocoiti@comio.info>
  117.   Yoshinari Takaoka <takaoka@beatcraft.com>
  118.   Sotaro Karasawa <sotaro.k@gmail.com>
  119.  
  120. http://ethna.jp/
  121.  
  122. EOD;
  123.     printf($versionETHNA_VERSIONPHP_VERSIONdate('Y'));
  124. }

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