PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/setup/util/SetupCli.php

http://rhaco.googlecode.com/
PHP | 190 lines | 181 code | 3 blank | 6 comment | 15 complexity | 70abe74b5b328544b180fd9d72371053 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. Rhaco::import("io.Stream");
  3. Rhaco::import("util.DocTest");
  4. Rhaco::import("util.DocUtil");
  5. Rhaco::import("lang.ArrayUtil");
  6. Rhaco::import("lang.Variable");
  7. Rhaco::import("network.http.Http");
  8. Rhaco::import("tag.model.SimpleTag");
  9. Rhaco::import("io.FileUtil");
  10. Rhaco::import("setup.util.SetupUtil");
  11. Rhaco::import("network.Repository");
  12. /**
  13. * CLI????????????????
  14. * @author Kazutaka Tokushima
  15. * @license New BSD License
  16. * @copyright Copyright rhaco project. All rights reserved.
  17. */
  18. class SetupCli{
  19. var $projectModel;
  20. var $rhacopath;
  21. function SetupCli($projectModel,$rhacopath){
  22. Logger::disableDisplay();
  23. $this->projectModel = $projectModel;
  24. $this->rhacopath = $rhacopath;
  25. $multi = 0;
  26. $store = "";
  27. while(true){
  28. print(">> ");
  29. $in = Stream::stdin();
  30. if($in != ""){
  31. if($in == "." || $in == "q"){
  32. break;
  33. }else if(preg_match("/^test (.+)$/",$in,$match)){
  34. $this->_doctest(trim($match[1]));
  35. }else if(preg_match("/^doc (.+)$/",$in,$match)){
  36. $this->_doc(trim($match[1]));
  37. }else if(preg_match("/^ls (.+)$/",$in,$match)){
  38. $this->_ls(trim($match[1]));
  39. }else if(preg_match("/create[\s]+(.+)$/",$in,$match)){
  40. $this->_create($match[1]);
  41. }else if($in == "generate"){
  42. $this->_generate();
  43. }else if($in == "init"){
  44. $this->_init();
  45. }else if(preg_match("/import[\s]+(.+)$/",$in,$match)){
  46. $package = trim($match[1]);
  47. switch(trim($match[1])){
  48. case "lib":
  49. print($package." ".(Repository::download($package,Rhaco::lib()) ? "installed" : "not found")."\n");
  50. break;
  51. }
  52. }else{
  53. $check = preg_replace("/([\"\']).+?\\1/","",$in);
  54. $multi = $multi + substr_count($check,"{") - substr_count($check,"}");
  55. $store .= $in;
  56. if($multi == 0){
  57. if(trim($store) != ""){
  58. ob_start();
  59. eval($store);
  60. $store = "";
  61. $print = ob_get_clean();
  62. if($print !== ""){
  63. print($print."\n");
  64. }
  65. }
  66. }
  67. }
  68. }
  69. if(ExceptionTrigger::isException()){
  70. foreach(ExceptionTrigger::get() as $name => $exception){
  71. print("!!warning!! ".$exception->getDetail()."\n");
  72. }
  73. ExceptionTrigger::clear();
  74. }
  75. }
  76. Rhaco::end();
  77. }
  78. function _ls($path){
  79. foreach(FileUtil::ls($path) as $file){
  80. print($file->getFullname()."\n");
  81. }
  82. }
  83. function _doctest($path){
  84. if(!is_file($path) && !is_dir($path)){
  85. if(Rhaco::import($path)){
  86. $fullpath = Rhaco::importpath($path);
  87. if($fullpath !== null) $path = $fullpath;
  88. }
  89. }
  90. DocTest::execute($path,Rhaco::path());
  91. }
  92. function _doc($path){
  93. $method = "";
  94. if(strpos($path,"::") !== false){
  95. list($path,$method) = explode("::",$path);
  96. }
  97. if(Rhaco::import($path)){
  98. $result = DocUtil::parse(Rhaco::importpath($path));
  99. foreach($result as $d){
  100. if(!empty($method)){
  101. $bool = false;
  102. foreach($d->function as $f){
  103. if(Variable::iequal($f->name,$method)){
  104. print("name:\n\t".$d->name."::".$f->name."\n");
  105. print("\n");
  106. print("description:\n\t".str_replace("\n","\n\t",$f->description));
  107. print("\n");
  108. $bool = true;
  109. break;
  110. }
  111. }
  112. if(!$bool){
  113. print("undefined method\n");
  114. }
  115. }else{
  116. print("name:\n\t".$d->name."\n");
  117. print("\n");
  118. if($d->isSubclass()){
  119. print("extends:\n\t".$d->extends."\n");
  120. print("\n");
  121. }
  122. print("description:\n\t".str_replace("\n","\n\t",$d->description));
  123. print("\n");
  124. print("functions:\n");
  125. foreach($d->function as $f){
  126. print("\t".$f->name."\n");
  127. }
  128. }
  129. }
  130. }else{
  131. $func = str_replace("_","-",strtolower($path));
  132. $result = array();
  133. $body = Http::body("http://jp2.php.net/manual/ja/function.".$func.".php");
  134. if(SimpleTag::setof($tag,$body,"body")){
  135. foreach($tag->getIn("div") as $div){
  136. if($div->param("id") == "layout_2"){
  137. foreach($div->getIn("div") as $di){
  138. if($di->param("id") == "content"){
  139. foreach($di->getIn("div") as $d){
  140. if($d->param("id") == "function.".$func){
  141. $result["verinfo"] = $d->f("div[0].p[0].value()");
  142. $result["refpurpose"] = $d->f("div[0].p[1].value()");
  143. $description = $d->f("div[1]");
  144. $description->f("h3.save()",null);
  145. $result["desc"] = trim(strip_tags($description->getValue()));
  146. $result["desc"] = preg_replace("/\n[\s]*\n/","\n\n",$result["desc"]);
  147. $result["desc"] = str_replace(array("\n\n","\n","__ENTER__"),array("__ENTER__","","\n"),$result["desc"]);
  148. print("verinfo:\n\t".$result["verinfo"]."\n");
  149. print("\n");
  150. print("refpurpose:\n\t".$result["refpurpose"]."\n");
  151. print("\n");
  152. print("description:\n\t".str_replace("\n","\n\t",$result["desc"]));
  153. print("\n");
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. if(empty($result)) print("undefined\n");
  162. }
  163. }
  164. function _create($dbname){
  165. print((($this->projectModel->createTable($dbname)) ? "creata table ".$dbname : "failure")."\n");
  166. }
  167. function _generate(){
  168. $request = new Request();
  169. $request->setVariable("rhacopath",$this->rhacopath);
  170. print((($this->projectModel->generate($request)) ? "setting completion" : "failure")."\n");
  171. }
  172. function _init(){
  173. print((($projectModel->appInit()) ? "initializing of project is executed" : "failure")."\n");
  174. }
  175. }
  176. ?>