791f50c9c692cf02c03c354e1b3a7b40ff441619.svn-base 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | menu.php 后台管理 左侧菜单管理
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace MazeApp\Manage;
  8. use Maze;
  9. use MazeApp\Manage\Lib\Input as Html;
  10. use Maze\Security\Api as Base;
  11. Maze::load('manage/auth.init');
  12. class Api
  13. {
  14. /**
  15. * fast
  16. *
  17. * @var array
  18. */
  19. private $fast = array();
  20. /**
  21. * data
  22. *
  23. * @var array
  24. */
  25. private $data = array();
  26. /**
  27. * 从数据库中得到所有接口,如果为空,则从项目中读取一次
  28. *
  29. * @return array
  30. */
  31. private function get($auth = '')
  32. {
  33. $data = Maze::load('manage/api-all');
  34. if($data)
  35. {
  36. foreach($data as $k => $v)
  37. {
  38. }
  39. }
  40. else
  41. {
  42. # 数据为空,读取一次,后续就得手动读取了
  43. $this->load();
  44. $data = $this->get();
  45. }
  46. return $data;
  47. }
  48. /**
  49. * 更新接口
  50. *
  51. * @return array
  52. */
  53. public function update()
  54. {
  55. $this->load();
  56. Maze::out('yes');
  57. }
  58. /**
  59. * 载入从项目中定义好的接口
  60. *
  61. * @return array
  62. */
  63. public function load()
  64. {
  65. $project = Maze::load('manage/project.get');
  66. foreach($project as $k => $v)
  67. {
  68. $data = Base::init($v['path']);
  69. if($data)
  70. {
  71. foreach($data as $i => $j)
  72. {
  73. $j['order'] = isset($j['order']) ? $j['order'] : 1;
  74. $this->updateApi($v['url'] . $i, $j['name'], $j['type'], $k, $j['request'], $j['response'], $j['order']);
  75. }
  76. }
  77. }
  78. }
  79. private function updateApi($site, $name, $type, $project, $request, $response, $reorder)
  80. {
  81. $request = Maze::table($request);
  82. $response = Maze::table($response);
  83. $info = Maze::load('manage/api-site', array('where_site' => $site));
  84. if(!$info)
  85. {
  86. $update['add_site'] = $site;
  87. $update['add_name'] = $name;
  88. $update['add_type'] = $type;
  89. $update['add_project'] = $project;
  90. $update['add_reorder'] = $reorder;
  91. $update['add_request'] = $request;
  92. $update['add_response'] = $response;
  93. $info['id'] = Maze::load('manage/api-insert', $update);
  94. }
  95. else
  96. {
  97. $update['set_interface'] = $site;
  98. $update['set_name'] = $name;
  99. $update['set_type'] = $type;
  100. $update['set_project'] = $project;
  101. $update['set_reorder'] = $reorder;
  102. $update['set_request'] = $request;
  103. $update['set_response'] = $response;
  104. $update['where_id'] = $info['id'];
  105. Maze::load('manage/api-update', $update);
  106. }
  107. return $info['id'];
  108. }
  109. }