From cb82416f2786770f6ba8f0c75454a6846e9e3876 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 31 Aug 2014 13:34:31 +0200 Subject: [PATCH] Simplified controller repository --- di.php | 9 ++++++ src/ControllerRepository.php | 5 ++-- src/Controllers/UserController.php | 46 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/Controllers/UserController.php diff --git a/di.php b/di.php index b40b06bf..90325b9b 100644 --- a/di.php +++ b/di.php @@ -3,4 +3,13 @@ return [ \Szurubooru\Config::class => DI\object()->constructor([ __DIR__ . DS . 'config.ini', __DIR__ . DS . 'local.ini']), + + \Szurubooru\ControllerRepository::class => DI\object()->constructor(DI\link('controllers')), + + 'controllers' => DI\factory(function (DI\container $c) { + return [ + $c->get(\Szurubooru\Controllers\AuthController::class), + $c->get(\Szurubooru\Controllers\UserController::class), + ]; + }), ]; diff --git a/src/ControllerRepository.php b/src/ControllerRepository.php index dfbf819c..faafff63 100644 --- a/src/ControllerRepository.php +++ b/src/ControllerRepository.php @@ -5,10 +5,9 @@ final class ControllerRepository { private $controllers = []; - public function __construct( - \Szurubooru\Controllers\AuthController $auth) + public function __construct(array $controllers) { - $this->controllers = func_get_args(); + $this->controllers = $controllers; } public function getControllers() diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php new file mode 100644 index 00000000..15d3ea43 --- /dev/null +++ b/src/Controllers/UserController.php @@ -0,0 +1,46 @@ +userService = $userService; + } + + public function registerRoutes(\Szurubooru\Router $router) + { + $router->post('/api/users', [$this, 'create']); + $router->get('/api/users', [$this, 'getAll']); + $router->get('/api/users/:id', [$this, 'getById']); + $router->put('/api/users/:id', [$this, 'update']); + $router->delete('/api/users/:id', [$this, 'delete']); + } + + public function create() + { + throw new \BadMethodCallException('Not implemented'); + } + + public function update($id) + { + throw new \BadMethodCallException('Not implemented'); + } + + public function getAll() + { + throw new \BadMethodCallException('Not implemented'); + } + + public function getById($id) + { + throw new \BadMethodCallException('Not implemented'); + } + + public function delete($id) + { + throw new \BadMethodCallException('Not implemented'); + } +}