2022-03-19 00:00:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace brain\controller;
|
|
|
|
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
|
|
|
class RouteControl
|
|
|
|
{
|
2024-02-29 17:37:40 +01:00
|
|
|
// TODO: Add additional HTTP Methods to better organize API control paths
|
2022-03-19 00:00:51 +01:00
|
|
|
public function get(
|
|
|
|
ServerRequestInterface $request,
|
|
|
|
ResponseInterface $response,
|
|
|
|
array $args
|
|
|
|
): ResponseInterface {
|
2022-05-17 02:41:15 +02:00
|
|
|
switch (isset($args['first']) ? $args['first'] : 'index') {
|
|
|
|
case 'dashboard':
|
2022-03-19 00:00:51 +01:00
|
|
|
return DashControl::start($request, $response, $args);
|
|
|
|
break;
|
2022-05-17 02:41:15 +02:00
|
|
|
case 'api':
|
2022-03-19 00:00:51 +01:00
|
|
|
return APIControl::get($request, $response, $args);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return IndexControl::start($request, $response, $args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-05-17 04:14:38 +02:00
|
|
|
|
2022-03-19 00:00:51 +01:00
|
|
|
public function post(
|
|
|
|
ServerRequestInterface $request,
|
|
|
|
ResponseInterface $response,
|
|
|
|
array $args
|
|
|
|
): ResponseInterface {
|
2022-05-17 02:41:15 +02:00
|
|
|
switch (isset($args['first']) ? $args['first'] : 'index') {
|
|
|
|
case 'api':
|
2022-03-19 00:00:51 +01:00
|
|
|
return APIControl::post($request, $response, $args);
|
|
|
|
break;
|
|
|
|
default:
|
2023-03-23 21:55:34 +01:00
|
|
|
$result = [
|
|
|
|
'message' => "Nothing matches this route. That's unfortunate",
|
|
|
|
'type' => 'TASK_NONE',
|
|
|
|
];
|
|
|
|
$response->getBody()->write(json_encode($result));
|
2024-02-29 17:37:40 +01:00
|
|
|
|
2023-03-23 21:55:34 +01:00
|
|
|
return $response->withHeader('Content-Type', 'application/json');
|
2022-03-19 00:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|