From 2bbdda87a0524dc6c344a84cb81ac6a2ff6333ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20JEAN?= Date: Fri, 31 May 2019 16:07:58 +0200 Subject: [PATCH] Add custom endpoints --- src/Tqdev/PhpCrudApi/Api.php | 10 ++++++++ .../Controller/CustomController.php | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/Tqdev/PhpCrudApi/Controller/CustomController.php diff --git a/src/Tqdev/PhpCrudApi/Api.php b/src/Tqdev/PhpCrudApi/Api.php index bb29206e..08c07867 100644 --- a/src/Tqdev/PhpCrudApi/Api.php +++ b/src/Tqdev/PhpCrudApi/Api.php @@ -119,6 +119,16 @@ public function __construct(Config $config) $geoJson = new GeoJsonService($reflection, $records); new GeoJsonController($router, $responder, $geoJson); break; + default: + $controllerChunks = explode(':', $controller); + if (count($controllerChunks) === 2 && $controllerChunks[0] === 'custom') { + $className = $controllerChunks[1]; + if (class_exists($className)) { + $records = new RecordService($db, $reflection); + new $className($router, $responder, $records); + } + } + break; } } $this->router = $router; diff --git a/src/Tqdev/PhpCrudApi/Controller/CustomController.php b/src/Tqdev/PhpCrudApi/Controller/CustomController.php new file mode 100644 index 00000000..59005a6d --- /dev/null +++ b/src/Tqdev/PhpCrudApi/Controller/CustomController.php @@ -0,0 +1,23 @@ +registerRoutes($router); + + $this->service = $service; + $this->responder = $responder; + } + + protected function registerRoutes(Router $router) + { + } +}