test_foreach(); return Dever::render('example/render', $data); } public function test_display_data() { return 12323234; } public function test_foreach() { $config = array ( array ( 'id' => 1, 'name' => '1111', 'child' => array ( array ( 'id' => 3, 'name' => '3333', 'child' => array ( array ( 'id' => 9, 'name' => '9999', ), array ( 'id' => 10, 'name' => '10101010', ), ), ), array ( 'id' => 4, 'name' => '4444', ), ), ), array ( 'id' => 2, 'name' => '2222', 'child' => array ( array ( 'id' => 5, 'name' => '5555', ), array ( 'id' => 6, 'name' => '6666', ), ), ), ); return $config; } /** * 测试接口定义 * * @return array */ public function test_api() { $data = Dever::load('module/data.test'); print_r($data);die; } /** * 测试逻辑验证步骤,必须包含step * * @return array */ public function test_step_1() { print_r(Dever::input('type')); # 传给下一步的数据 Dever::setStep('test'); $url = Dever::url('api.test_step_2?' . http_build_query(Dever::$global['step'][1])); print_r($url);die; #ok echo 11;die; } /** * 测试逻辑验证步骤,必须包含step * * @return array */ public function test_step_2() { $data = Dever::getStep(); print_r($data);die; echo 22;die; } /** * 从数据库中得到所有接口,如果为空,则从项目中读取一次 * * @return array */ private function get($auth = '') { $data = Dever::load('manage/api-all'); if ($data) { foreach ($data as $k => $v) { } } else { # 数据为空,读取一次,后续就得手动读取了 $this->load(); $data = $this->get(); } return $data; } /** * 更新接口 * * @return array */ public function update_api() { $this->load(); Dever::out('yes'); } /** * 载入从项目中定义好的接口 * * @return array */ public function load() { $project = Dever::load('manage/project.get'); foreach ($project as $k => $v) { $data = Base::config($v['path']); if ($data) { foreach ($data as $i => $j) { $j['order'] = isset($j['order']) ? $j['order'] : 1; $this->updateApi($i, $j['name'], $j['type'], $k, $j['request'], $j['response'], $j['order']); } } } } private function updateApi($site, $name, $type, $project, $request, $response, $reorder, $state = true) { $info = Dever::db('manage/api')->site(array('where_site' => $site, 'where_project' => $project)); if (!$info) { $update['add_site'] = $site; $update['add_name'] = $name; $update['add_type'] = $type; $update['add_project'] = $project; $update['add_reorder'] = $reorder; $info['id'] = Dever::db('manage/api')->insert($update); } elseif ($state) { $update['set_site'] = $site; $update['set_name'] = $name; $update['set_type'] = $type; $update['set_project'] = $project; $update['set_reorder'] = $reorder; $update['where_id'] = $info['id']; Dever::db('manage/api')->update($update); } if ($info['id'] > 0) { $this->updateApiData(array($response, $request), $info['id']); } return true; } private function updateApiData($data, $id) { $this->api_response = $this->api_request = array(); foreach($data as $k => $v) { if ($v && is_array($v)) { if ($k == 0) { $api = 'api_response'; } else { $api = 'api_request'; } $this->insertApiData($api, $v, $id, -1, 0); } } } private function insertApiData($api, $data, $aid, $id = -1, $num = 0) { foreach($data as $k => $v) { $value = $v; if (is_array($value)) { $value = 'array:' . $k; if (isset($v[0][0])) { $v = $v[0][0]; } if (isset($v[0])) { $v = $v[0]; } } if (isset($this->{$api}[$num][$k])) { //continue; } $this->{$api}[$num][$k] = $value; $insertId = $this->insertApiDataOne($api, $k, $value, $aid, $id); if ($insertId > 0 && is_array($v)) { $this->insertApiData($api, $v, $aid, $insertId, $num+1); } } } private function insertApiDataOne($api, $name, $data, $aid, $id = -1) { if (is_array($data)) { $type = $data[0]; $desc = $data[1]; } else { $type = 'string'; if (is_numeric($name)) { $type = 'int'; } elseif (strpos($name, 'id') !== false) { $type = 'int'; } $desc = $data; } if (strlen($desc) > 100) { $desc = '{long}'; } $update['add_api_id'] = $aid; $update['add_name'] = $name; $update['add_type'] = $type; $update['add_desc'] = $desc; $update['add_parent_id'] = $id; $update['add_desc'] = $desc; $one = array ( 'option_parent_id' => $id, 'option_api_id' => $aid, 'option_name' => $name, ); $info = Dever::db('manage/' . $api)->one($one); if (!$info) { return Dever::db('manage/' . $api)->insert($update); } return $info['id']; } public function showTable($data, $url = '', $api = '') { $result = '