PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/ethna_handle.php

http://github.com/ethna/ethna
PHP | 126 lines | 85 code | 16 blank | 25 comment | 21 complexity | 6e97ec466e72e278fcf87891886f3101 MD5 | raw file
Possible License(s): BSD-3-Clause
  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. $base = dirname(dirname(dirname(__FILE__)));
  16. ini_set('include_path', $base.PATH_SEPARATOR.ini_get('include_path'));
  17. require_once 'Ethna/Ethna.php';
  18. require_once ETHNA_BASE . '/class/Getopt.php';
  19. // fetch arguments
  20. $opt = new Ethna_Getopt();
  21. $arg_list = $opt->readPHPArgv();
  22. if (Ethna::isError($arg_list)) {
  23. echo $arg_list->getMessage()."\n";
  24. exit(2);
  25. }
  26. array_shift($arg_list); // remove "ethna_handle.php"
  27. $eh = new Ethna_Handle();
  28. if ($dot_ethna = getenv('DOT_ETHNA')) {
  29. $app_controller = Ethna_Handle::getAppController(dirname($dot_ethna));
  30. }
  31. // ??????? - ???????????????
  32. // ???????????? -v|--version ?????????
  33. list($my_arg_list, $arg_list) = _Ethna_HandleGateway_SeparateArgList($arg_list);
  34. $r = $opt->getopt($my_arg_list, "v", array("version"));
  35. if (Ethna::isError($r)) {
  36. $id = 'help';
  37. } else {
  38. // ad-hoc:(
  39. foreach ($r[0] as $opt) {
  40. if ($opt[0] == "v" || $opt[0] == "--version") {
  41. _Ethna_HandleGateway_ShowVersion();
  42. exit(2);
  43. }
  44. }
  45. }
  46. if (count($arg_list) == 0) {
  47. $id = 'help';
  48. } else {
  49. $id = array_shift($arg_list);
  50. }
  51. $handler =& $eh->getHandler($id);
  52. $handler->eh =& $eh;
  53. if (Ethna::isError($handler)) {
  54. printf("no such command: %s\n\n", $id);
  55. $id = 'help';
  56. $handler =& $eh->getHandler($id);
  57. $handler->eh =& $eh;
  58. if (Ethna::isError($handler)) {
  59. exit(1); // should not happen.
  60. }
  61. }
  62. // don't know what will happen:)
  63. $handler->setArgList($arg_list);
  64. $r = $handler->perform();
  65. if (Ethna::isError($r)) {
  66. printf("error occured w/ command [%s]\n -> %s\n\n", $id, $r->getMessage());
  67. if ($r->getCode() == 'usage') {
  68. $handler->usage();
  69. }
  70. exit(1);
  71. }
  72. /**
  73. * fetch options for myself
  74. */
  75. function _Ethna_HandleGateway_SeparateArgList($arg_list)
  76. {
  77. $my_arg_list = array();
  78. // ??????? - ?????????
  79. // ??? $my_arg_list ????
  80. // ??? --version ?????
  81. for ($i = 0; $i < count($arg_list); $i++) {
  82. if ($arg_list[$i]{0} == '-') {
  83. // assume this should be an option for myself
  84. $my_arg_list[] = $arg_list[$i];
  85. } else {
  86. break;
  87. }
  88. }
  89. $arg_list = array_slice($arg_list, $i);
  90. return array($my_arg_list, $arg_list);
  91. }
  92. /**
  93. * show version
  94. */
  95. function _Ethna_HandleGateway_ShowVersion()
  96. {
  97. $version = <<<EOD
  98. Ethna %s (using PHP %s)
  99. Copyright (c) 2004-%s,
  100. Masaki Fujimoto <fujimoto@php.net>
  101. halt feits <halt.feits@gmail.com>
  102. Takuya Ookubo <sfio@sakura.ai.to>
  103. nozzzzz <nozzzzz@gmail.com>
  104. cocoitiban <cocoiti@comio.info>
  105. Yoshinari Takaoka <takaoka@beatcraft.com>
  106. Sotaro Karasawa <sotaro.k@gmail.com>
  107. http://ethna.jp/
  108. EOD;
  109. printf($version, ETHNA_VERSION, PHP_VERSION, date('Y'));
  110. }