Added proof of concept for controllers system

This commit is contained in:
Marcin Kurczewski 2014-08-30 13:04:52 +02:00
parent 10e6c9f11f
commit ebc4fbba61
4 changed files with 52 additions and 0 deletions

2
public_html/.htaccess Normal file
View file

@ -0,0 +1,2 @@
RewriteEngine On
RewriteRule ^/?api/(.*) api-dispatch.php?q=$1 [L]

View file

@ -0,0 +1,25 @@
<?php
require_once('..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'AutoLoader.php');
function injectControllers($router)
{
\Szurubooru\Controllers\AuthController::register($router);
}
$router = new \Szurubooru\Router;
injectControllers($router);
try
{
$json = $router->handle($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
}
catch (\Exception $e)
{
$json = [
'error' => $e->getMessage(),
'trace' => $e->getTrace(),
];
}
header('Content-Type: application/json');
echo json_encode($json);

View file

@ -0,0 +1,10 @@
<?php
namespace Szurubooru\Controllers;
abstract class AbstractController
{
public static function register(\Szurubooru\Router $router)
{
return new static($router);
}
}

View file

@ -0,0 +1,15 @@
<?php
namespace Szurubooru\Controllers;
final class AuthController extends AbstractController
{
public function __construct(\Szurubooru\Router $router)
{
$router->post('/api/login', [$this, 'login']);
$router->get('/api/login', [$this, 'login']);
}
public function login()
{
}
}