|
31 | 31 | use jsonDB\Validate; |
32 | 32 | use jsonDB\dbException; |
33 | 33 |
|
| 34 | +// Проверяем папки DB, если нет создаем |
| 35 | +if (!file_exists($_db)){mkdir($_db);} |
| 36 | +if (!file_exists($_db . 'core')){mkdir($_db . 'core');} |
| 37 | + |
34 | 38 | // Создаем ключ доступа |
35 | 39 | if (!file_exists($_db . 'core/key_db.txt')){ |
36 | | - |
37 | 40 | $ajax_key = Key::createNewRandomKey(); |
38 | 41 | $key_db = $ajax_key->saveToAsciiSafeString(); |
39 | 42 | file_put_contents($_db . 'core/key_db.txt', $key_db); |
40 | | - |
41 | 43 | } |
42 | 44 |
|
43 | 45 | // Конфигурация |
|
82 | 84 | $param_key = (isset($param['key'])) ? Db::clean($param['key']) : null; |
83 | 85 |
|
84 | 86 | if ($param_key == $this->get('settings')['db']["key"]) { |
85 | | - $resp["status"] = "OK"; |
| 87 | + $resp["status"] = "200 OK"; |
86 | 88 | $resp["code"] = 200; |
87 | | - $resp["message"] = 'db_json_api works! To work, you need a key.'; |
| 89 | + $resp["message"] = "RESTfull API json DB works! works! To work, you need a key."; |
88 | 90 | echo json_encode($resp, JSON_PRETTY_PRINT); |
89 | 91 | } else { |
90 | | - $resp["status"] = "OK"; |
| 92 | + $resp["status"] = "200 OK"; |
91 | 93 | $resp["code"] = 200; |
92 | | - $resp["message"] = 'db_json_api works!'; |
| 94 | + $resp["message"] = "RESTfull API json DB works!"; |
93 | 95 | echo json_encode($resp, JSON_PRETTY_PRINT); |
94 | 96 | } |
95 | 97 |
|
96 | 98 | return $response->withStatus(200)->withHeader('Content-Type','application/json'); |
97 | 99 |
|
98 | 100 | }); |
99 | 101 |
|
100 | | -$app->get('/test', function (Request $request, Response $response, array $args) { |
101 | | - |
102 | | - /* |
103 | | - $res->with('property'); |
104 | | - $res->with('product_view'); |
105 | | - */ |
106 | | - |
107 | | - $res = jsonDb::table("product")->where("id", ">=", 61456)->orderBy('id')->limit(15)->findAll()->asArray(); |
108 | | - |
109 | | - /* |
110 | | - foreach($res AS $key => $unit){ |
111 | | - if (isset($key) && isset($unit)) { |
112 | | - $item[$key] = $unit; |
113 | | - $items["item"] = $item; |
114 | | - } |
115 | | - } |
116 | | - */ |
117 | | - |
118 | | - $resp = array(); |
119 | | - $resp["headers"]["status"] = "200 OK"; |
120 | | - $resp["headers"]["code"] = 200; |
121 | | - $resp["headers"]["message"] = 'Access is denied'; |
122 | | - |
123 | | - $resp["body"]["items"] = $res; |
124 | | - |
125 | | - print_r($resp); |
126 | | - |
127 | | - echo json_encode($resp, JSON_PRETTY_PRINT); |
128 | | - |
129 | | - return $response->withStatus(200)->withHeader('Content-Type','application/json'); |
130 | | - |
131 | | -}); |
132 | | - |
133 | 102 | $app->get('/{table:[\w]+}[/{id:[0-9]+}]', function (Request $request, Response $response, array $args) { |
134 | 103 |
|
135 | 104 | $table_name = $request->getAttribute('table'); |
|
0 commit comments