Simplified controller repository
This commit is contained in:
parent
1f6017aae7
commit
cb82416f27
3 changed files with 57 additions and 3 deletions
9
di.php
9
di.php
|
@ -3,4 +3,13 @@ return [
|
||||||
\Szurubooru\Config::class => DI\object()->constructor([
|
\Szurubooru\Config::class => DI\object()->constructor([
|
||||||
__DIR__ . DS . 'config.ini',
|
__DIR__ . DS . 'config.ini',
|
||||||
__DIR__ . DS . 'local.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),
|
||||||
|
];
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
|
@ -5,10 +5,9 @@ final class ControllerRepository
|
||||||
{
|
{
|
||||||
private $controllers = [];
|
private $controllers = [];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(array $controllers)
|
||||||
\Szurubooru\Controllers\AuthController $auth)
|
|
||||||
{
|
{
|
||||||
$this->controllers = func_get_args();
|
$this->controllers = $controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getControllers()
|
public function getControllers()
|
||||||
|
|
46
src/Controllers/UserController.php
Normal file
46
src/Controllers/UserController.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Controllers;
|
||||||
|
|
||||||
|
final class UserController extends AbstractController
|
||||||
|
{
|
||||||
|
private $userService;
|
||||||
|
|
||||||
|
public function __construct(\Szurubooru\Services\UserService $userService)
|
||||||
|
{
|
||||||
|
$this->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');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue