Added proof of concept for controllers system
This commit is contained in:
parent
10e6c9f11f
commit
ebc4fbba61
4 changed files with 52 additions and 0 deletions
2
public_html/.htaccess
Normal file
2
public_html/.htaccess
Normal file
|
@ -0,0 +1,2 @@
|
|||
RewriteEngine On
|
||||
RewriteRule ^/?api/(.*) api-dispatch.php?q=$1 [L]
|
25
public_html/api-dispatch.php
Normal file
25
public_html/api-dispatch.php
Normal 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);
|
10
src/Controllers/AbstractController.php
Normal file
10
src/Controllers/AbstractController.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Controllers;
|
||||
|
||||
abstract class AbstractController
|
||||
{
|
||||
public static function register(\Szurubooru\Router $router)
|
||||
{
|
||||
return new static($router);
|
||||
}
|
||||
}
|
15
src/Controllers/AuthController.php
Normal file
15
src/Controllers/AuthController.php
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue