|
@@ -256,15 +256,16 @@ class MySQL_CRUD_API {
|
256
|
256
|
}
|
257
|
257
|
|
258
|
258
|
private function getParameters($method, $request, $database, $whitelist, $blacklist, $mysqli) {
|
259
|
|
- $action = $this->mapMethodToAction($method, $request);
|
260
|
|
- $table = $this->parseRequestParameter($request, 0, 'a-zA-Z0-9\-_*,', '*');
|
261
|
|
- $key = $this->parseRequestParameter($request, 1, 'a-zA-Z0-9\-,', false); // auto-increment or uuid
|
262
|
|
- $callback = $this->parseGetParameter('callback', 'a-zA-Z0-9\-_', false);
|
263
|
|
- $page = $this->parseGetParameter('page', '0-9,', false);
|
264
|
|
- $filter = $this->parseGetParameter('filter', false, 'exact');
|
265
|
|
- $match = $this->parseGetParameter('match', 'a-z', false);
|
266
|
|
- $order = $this->parseGetParameter('order', 'a-zA-Z0-9\-_*,', false);
|
267
|
|
-
|
|
259
|
+ $action = $this->mapMethodToAction($method, $request);
|
|
260
|
+ $table = $this->parseRequestParameter($request, 0, 'a-zA-Z0-9\-_*,', '*');
|
|
261
|
+ $key = $this->parseRequestParameter($request, 1, 'a-zA-Z0-9\-,', false); // auto-increment or uuid
|
|
262
|
+ $callback = $this->parseGetParameter('callback', 'a-zA-Z0-9\-_', false);
|
|
263
|
+ $page = $this->parseGetParameter('page', '0-9,', false);
|
|
264
|
+ $filter = $this->parseGetParameter('filter', false, 'exact');
|
|
265
|
+ $match = $this->parseGetParameter('match', 'a-z', false);
|
|
266
|
+ $order = $this->parseGetParameter('order', 'a-zA-Z0-9\-_*,', false);
|
|
267
|
+ $transform = $this->parseGetParameter('transform', '1', false);
|
|
268
|
+
|
268
|
269
|
$table = $this->processTableParameter($table,$database,$mysqli);
|
269
|
270
|
$key = $this->processKeyParameter($key,$table,$database,$mysqli);
|
270
|
271
|
$filter = $this->processFilterParameter($filter,$match,$mysqli);
|
|
@@ -278,7 +279,7 @@ class MySQL_CRUD_API {
|
278
|
279
|
|
279
|
280
|
list($collect,$select) = $this->findRelations($action,$table,$database,$mysqli);
|
280
|
281
|
|
281
|
|
- return compact('action','table','key','callback','page','filter','match','order','mysqli','object','input','collect','select');
|
|
282
|
+ return compact('action','table','key','callback','page','filter','match','order','transform','mysqli','object','input','collect','select');
|
282
|
283
|
}
|
283
|
284
|
|
284
|
285
|
private function listCommand($parameters) {
|
|
@@ -408,6 +409,18 @@ class MySQL_CRUD_API {
|
408
|
409
|
$this->endOutput($callback);
|
409
|
410
|
}
|
410
|
411
|
|
|
412
|
+ private function listCommandTransform($parameters) {
|
|
413
|
+ if ($parameters['transform']) {
|
|
414
|
+ ob_start();
|
|
415
|
+ }
|
|
416
|
+ $this->listCommand($parameters);
|
|
417
|
+ if ($parameters['transform']) {
|
|
418
|
+ $content = ob_get_contents();
|
|
419
|
+ ob_end_clean();
|
|
420
|
+ echo json_encode(self::mysql_crud_api_transform(json_decode($content,true)));
|
|
421
|
+ }
|
|
422
|
+ }
|
|
423
|
+
|
411
|
424
|
public function __construct($hostname,$username,$password,$database,$whitelist,$blacklist) {
|
412
|
425
|
$this->method = isset($_SERVER['REQUEST_METHOD'])?$_SERVER['REQUEST_METHOD']:'';
|
413
|
426
|
$this->request = explode("/", isset($_SERVER['PATH_INFO'])?$_SERVER['PATH_INFO']:'', 1);
|
|
@@ -419,17 +432,6 @@ class MySQL_CRUD_API {
|
419
|
432
|
$this->blacklist = $blacklist;
|
420
|
433
|
}
|
421
|
434
|
|
422
|
|
- private function execute() {
|
423
|
|
- $parameters = $this->getParameters($this->method, $this->request, $this->database, $this->whitelist, $this->blacklist, $this->mysqli);
|
424
|
|
- switch($parameters['action']){
|
425
|
|
- case 'list': $this->listCommand($parameters); break;
|
426
|
|
- case 'read': $this->readCommand($parameters); break;
|
427
|
|
- case 'create': $this->readCommand($parameters); break;
|
428
|
|
- case 'update': $this->readCommand($parameters); break;
|
429
|
|
- case 'delete': $this->readCommand($parameters); break;
|
430
|
|
- }
|
431
|
|
- }
|
432
|
|
-
|
433
|
435
|
public static function mysql_crud_api_transform(&$tables) {
|
434
|
436
|
$get_objects = function (&$tables,$table_name,$where_index=false,$match_value=false) use (&$get_objects) {
|
435
|
437
|
$objects = array();
|
|
@@ -462,17 +464,16 @@ class MySQL_CRUD_API {
|
462
|
464
|
}
|
463
|
465
|
|
464
|
466
|
public function executeCommand() {
|
465
|
|
- if (isset($_GET['transform']) && $_GET['transform']) {
|
466
|
|
- ob_start();
|
467
|
|
- $this->execute();
|
468
|
|
- $content = ob_get_contents();
|
469
|
|
- ob_end_clean();
|
470
|
|
- echo json_encode(self::mysql_crud_api_transform(json_decode($content,true)));
|
471
|
|
- } else {
|
472
|
|
- $this->execute();
|
473
|
|
- }
|
474
|
|
- }
|
475
|
|
-
|
|
467
|
+ $parameters = $this->getParameters($this->method, $this->request, $this->database, $this->whitelist, $this->blacklist, $this->mysqli);
|
|
468
|
+ switch($parameters['action']){
|
|
469
|
+ case 'list': $this->listCommandTransform($parameters); break;
|
|
470
|
+ case 'read': $this->readCommand($parameters); break;
|
|
471
|
+ case 'create': $this->readCommand($parameters); break;
|
|
472
|
+ case 'update': $this->readCommand($parameters); break;
|
|
473
|
+ case 'delete': $this->readCommand($parameters); break;
|
|
474
|
+ }
|
|
475
|
+ }
|
|
476
|
+
|
476
|
477
|
}
|
477
|
478
|
|
478
|
479
|
// only execute this when running in stand-alone mode
|