apidoc.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * 给apidoc项目增加顺序编号
  4. */
  5. error_reporting(E_ALL & ~E_NOTICE);
  6. $path = dirname(__FILE__). '/';
  7. $lists = scandir($path);
  8. //
  9. foreach ($lists AS $item) {
  10. $fillPath = $path . $item;
  11. if (substr($fillPath, -14) == 'Controller.php') {
  12. $content = file_get_contents($fillPath);
  13. preg_match_all("/\* @api \{(.+?)\} (.*?)\n/i", $content, $matchs);
  14. $i = 1;
  15. foreach ($matchs[2] AS $key=>$text) {
  16. if (in_array(strtolower($matchs[1][$key]), array('get', 'post'))) {
  17. $expl = explode(" ", __sRemove($text));
  18. $end = $expl[1];
  19. if ($expl[2]) {
  20. $end = '';
  21. foreach ($expl AS $k=>$v) { if ($k >= 2) { $end.= " ".$v; } }
  22. }
  23. $newtext = "* @api {".$matchs[1][$key]."} ".$expl[0]." ".__zeroFill($i, 2).". ".trim($end);
  24. $content = str_replace("* @api {".$matchs[1][$key]."} ".$text, $newtext, $content);
  25. $i++;
  26. //
  27. echo $newtext;
  28. echo "\r\n";
  29. }
  30. }
  31. if ($i > 1) {
  32. file_put_contents($fillPath, $content);
  33. }
  34. }
  35. }
  36. echo "Success \n";
  37. /** ************************************************************** */
  38. /** ************************************************************** */
  39. /** ************************************************************** */
  40. /**
  41. * 替换所有空格
  42. * @param $str
  43. * @return mixed
  44. */
  45. function __sRemove($str) {
  46. $str = str_replace(" ", " ", $str);
  47. if (__strExists($str, " ")) {
  48. return __sRemove($str);
  49. }
  50. return $str;
  51. }
  52. /**
  53. * 是否包含字符
  54. * @param $string
  55. * @param $find
  56. * @return bool
  57. */
  58. function __strExists($string, $find)
  59. {
  60. return !(strpos($string, $find) === FALSE);
  61. }
  62. /**
  63. * @param string $str 补零
  64. * @param int $length
  65. * @param int $after
  66. * @return bool|string
  67. */
  68. function __zeroFill($str, $length = 0, $after = 1) {
  69. if (strlen($str) >= $length) {
  70. return $str;
  71. }
  72. $_str = '';
  73. for ($i = 0; $i < $length; $i++) {
  74. $_str .= '0';
  75. }
  76. if ($after) {
  77. $_ret = substr($_str . $str, $length * -1);
  78. } else {
  79. $_ret = substr($str . $_str, 0, $length);
  80. }
  81. return $_ret;
  82. }