divide src in three subdirs, exploded FrontController into index.php and api/index.php
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
36051ebd83
commit
de75577f3d
@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Controller\Api;
|
namespace IQBall\Api;
|
||||||
|
|
||||||
use App\Controller\Control;
|
use IQBall\Core\Route\Control;
|
||||||
use App\Http\HttpRequest;
|
use IQBall\Core\Http\HttpRequest;
|
||||||
use App\Http\HttpResponse;
|
use IQBall\Core\Http\HttpResponse;
|
||||||
use App\Http\JsonHttpResponse;
|
use IQBall\Core\Http\JsonHttpResponse;
|
||||||
use App\Model\AuthModel;
|
use IQBall\Core\Model\AuthModel;
|
||||||
use App\Validation\Validators;
|
use IQBall\Core\Validation\Validators;
|
||||||
|
|
||||||
class APIAuthController {
|
class APIAuthController {
|
||||||
private AuthModel $model;
|
private AuthModel $model;
|
@ -1,15 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Controller\Api;
|
namespace IQBall\Api;
|
||||||
|
|
||||||
use App\Controller\Control;
|
use IQBall\Core\Route\Control;
|
||||||
use App\Data\Account;
|
use IQBall\Core\Data\Account;
|
||||||
use App\Http\HttpCodes;
|
use IQBall\Core\Http\HttpCodes;
|
||||||
use App\Http\HttpRequest;
|
use IQBall\Core\Http\HttpRequest;
|
||||||
use App\Http\HttpResponse;
|
use IQBall\Core\Http\HttpResponse;
|
||||||
use App\Http\JsonHttpResponse;
|
use IQBall\Core\Http\JsonHttpResponse;
|
||||||
use App\Model\TacticModel;
|
use IQBall\Core\Model\TacticModel;
|
||||||
use App\Validation\Validators;
|
use IQBall\Core\Validation\Validators;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API endpoint related to tactics
|
* API endpoint related to tactics
|
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IQBall\Api;
|
||||||
|
|
||||||
|
use IQBall\Core\Data\Account;
|
||||||
|
use IQBall\Core\Http\HttpResponse;
|
||||||
|
use IQBall\Core\Route\AbstractAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends AbstractAction<?Account>
|
||||||
|
*/
|
||||||
|
class ApiAction extends AbstractAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] $params
|
||||||
|
* @param ?Account $session
|
||||||
|
* @return HttpResponse
|
||||||
|
*/
|
||||||
|
public function run(array $params, $session): HttpResponse {
|
||||||
|
$params = array_values($params);
|
||||||
|
if ($this->isAuthRequired()) {
|
||||||
|
if ($session == null) {
|
||||||
|
throw new \Exception("action requires authorization.");
|
||||||
|
}
|
||||||
|
$params[] = $session;
|
||||||
|
}
|
||||||
|
|
||||||
|
return call_user_func_array($this->action, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param callable(mixed[]): HttpResponse $action
|
||||||
|
* @return ApiAction an action that does not require to have an authorization.
|
||||||
|
*/
|
||||||
|
public static function noAuth(callable $action): ApiAction {
|
||||||
|
return new ApiAction($action, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param callable(mixed[]): HttpResponse $action
|
||||||
|
* @return ApiAction an action that does require to have an authorization.
|
||||||
|
*/
|
||||||
|
public static function auth(callable $action): ApiAction {
|
||||||
|
return new ApiAction($action, true);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IQBall\App;
|
||||||
|
|
||||||
|
use IQBall\Core\Http\HttpResponse;
|
||||||
|
use IQBall\Core\Session\MutableSessionHandle;
|
||||||
|
use Exception;
|
||||||
|
use IQBall\Core\Route\AbstractAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Front controller action
|
||||||
|
* @extends AbstractAction<MutableSessionHandle>
|
||||||
|
*/
|
||||||
|
class AppAction extends AbstractAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] $params
|
||||||
|
* @param MutableSessionHandle $session
|
||||||
|
* @return HttpResponse
|
||||||
|
* @throws Exception <p>
|
||||||
|
* thrown if this action is required to be authenticated, but the given session does not contain a logged-in account.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Caller is supposed to ensure that the user is logged-in before, if `$this->isAuthRequired()` is true before
|
||||||
|
* running this action.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public function run(array $params, $session): HttpResponse {
|
||||||
|
$params = array_values($params);
|
||||||
|
if ($this->isAuthRequired()) {
|
||||||
|
if ($session->getAccount() == null) {
|
||||||
|
throw new Exception("action requires authorization.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$params[] = $session;
|
||||||
|
return call_user_func_array($this->action, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param callable(mixed[]): HttpResponse $action
|
||||||
|
* @return AppAction an action that does not require to have an authorization.
|
||||||
|
*/
|
||||||
|
public static function noAuth(callable $action): AppAction {
|
||||||
|
return new AppAction($action, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param callable(mixed[]): HttpResponse $action
|
||||||
|
* @return AppAction an action that does require to have an authorization.
|
||||||
|
*/
|
||||||
|
public static function auth(callable $action): AppAction {
|
||||||
|
return new AppAction($action, true);
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace IQBall\App\Controller;
|
||||||
|
|
||||||
use App\Http\HttpRequest;
|
use IQBall\Core\Http\HttpRequest;
|
||||||
use App\Http\HttpResponse;
|
use IQBall\Core\Http\HttpResponse;
|
||||||
use App\Http\ViewHttpResponse;
|
use IQBall\Core\Http\ViewHttpResponse;
|
||||||
use App\Model\AuthModel;
|
use IQBall\Core\Model\AuthModel;
|
||||||
use App\Session\MutableSessionHandle;
|
use IQBall\Core\Session\MutableSessionHandle;
|
||||||
use App\Validation\ValidationFail;
|
use IQBall\Core\Validation\ValidationFail;
|
||||||
use App\Validation\Validators;
|
use IQBall\Core\Validation\Validators;
|
||||||
|
|
||||||
class AuthController {
|
class AuthController {
|
||||||
private AuthModel $model;
|
private AuthModel $model;
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace IQBall\App\Controller;
|
||||||
|
|
||||||
use App\Data\TacticInfo;
|
use IQBall\Core\Data\TacticInfo;
|
||||||
use App\Http\HttpCodes;
|
use IQBall\Core\Http\HttpCodes;
|
||||||
use App\Http\HttpResponse;
|
use IQBall\Core\Http\HttpResponse;
|
||||||
use App\Http\ViewHttpResponse;
|
use IQBall\Core\Http\ViewHttpResponse;
|
||||||
use App\Model\TacticModel;
|
use IQBall\Core\Model\TacticModel;
|
||||||
use App\Session\SessionHandle;
|
use IQBall\Core\Session\SessionHandle;
|
||||||
use App\Validator\TacticValidator;
|
use IQBall\Core\Validator\TacticValidator;
|
||||||
|
|
||||||
class EditorController {
|
class EditorController {
|
||||||
private TacticModel $model;
|
private TacticModel $model;
|
@ -1,16 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace IQBall\App\Controller;
|
||||||
|
|
||||||
use App\Connexion;
|
use IQBall\Core\Http\HttpResponse;
|
||||||
use App\Gateway\TacticInfoGateway;
|
use IQBall\Core\Http\ViewHttpResponse;
|
||||||
use App\Http\HttpResponse;
|
use IQBall\Core\Model\TacticModel;
|
||||||
use App\Http\ViewHttpResponse;
|
use IQBall\Core\Session\SessionHandle;
|
||||||
use App\Model\TacticModel;
|
|
||||||
use App\Session\SessionHandle;
|
|
||||||
|
|
||||||
class UserController {
|
class UserController {
|
||||||
|
|
||||||
private TacticModel $tactics;
|
private TacticModel $tactics;
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace IQBall\App\Controller;
|
||||||
|
|
||||||
use App\Http\HttpCodes;
|
use IQBall\Core\Http\HttpCodes;
|
||||||
use App\Http\HttpResponse;
|
use IQBall\Core\Http\HttpResponse;
|
||||||
use App\Http\ViewHttpResponse;
|
use IQBall\Core\Http\ViewHttpResponse;
|
||||||
use App\Model\TacticModel;
|
use IQBall\Core\Model\TacticModel;
|
||||||
use App\Session\SessionHandle;
|
use IQBall\Core\Session\SessionHandle;
|
||||||
use App\Validator\TacticValidator;
|
use IQBall\Core\Validator\TacticValidator;
|
||||||
|
|
||||||
class VisualizerController {
|
class VisualizerController {
|
||||||
private TacticModel $tacticModel;
|
private TacticModel $tacticModel;
|
@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller\Route;
|
|
||||||
|
|
||||||
use App\Http\HttpResponse;
|
|
||||||
use App\Session\SessionHandle;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Front controller action
|
|
||||||
*/
|
|
||||||
class Action {
|
|
||||||
/**
|
|
||||||
* @var callable(mixed[]): HttpResponse $action action to call
|
|
||||||
*/
|
|
||||||
private $action;
|
|
||||||
|
|
||||||
private bool $isAuthRequired;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param callable(mixed[]): HttpResponse $action
|
|
||||||
*/
|
|
||||||
private function __construct(callable $action, bool $isAuthRequired) {
|
|
||||||
$this->action = $action;
|
|
||||||
$this->isAuthRequired = $isAuthRequired;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isAuthRequired(): bool {
|
|
||||||
return $this->isAuthRequired;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed[] $params
|
|
||||||
* @param SessionHandle $session
|
|
||||||
* @return HttpResponse
|
|
||||||
* @throws Exception <p>
|
|
||||||
* thrown if this action is required to be authenticated, but the given session does not contain a logged-in account.
|
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* Caller is supposed to ensure that the user is logged-in before, if `$this->isAuthRequired()` is true before
|
|
||||||
* running this action.
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public function run(array $params, SessionHandle $session): HttpResponse {
|
|
||||||
$params = array_values($params);
|
|
||||||
if ($this->isAuthRequired) {
|
|
||||||
if ($session->getAccount() == null) {
|
|
||||||
throw new Exception("action requires authorization.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$params[] = $session;
|
|
||||||
return call_user_func_array($this->action, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param callable(mixed[]): HttpResponse $action
|
|
||||||
* @return Action an action that does not require to have an authorization.
|
|
||||||
*/
|
|
||||||
public static function noAuth(callable $action): Action {
|
|
||||||
return new Action($action, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param callable(mixed[]): HttpResponse $action
|
|
||||||
* @return Action an action that does require to have an authorization.
|
|
||||||
*/
|
|
||||||
public static function auth(callable $action): Action {
|
|
||||||
return new Action($action, true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,143 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller\Route;
|
|
||||||
|
|
||||||
use AltoRouter;
|
|
||||||
use App\Http\HttpCodes;
|
|
||||||
use App\Http\HttpResponse;
|
|
||||||
use App\Http\JsonHttpResponse;
|
|
||||||
use App\Http\ViewHttpResponse;
|
|
||||||
use App\Session\MutableSessionHandle;
|
|
||||||
use App\Validation\ValidationFail;
|
|
||||||
use Twig\Environment;
|
|
||||||
use Twig\Error\LoaderError;
|
|
||||||
use Twig\Error\RuntimeError;
|
|
||||||
use Twig\Error\SyntaxError;
|
|
||||||
use Twig\Loader\FilesystemLoader;
|
|
||||||
|
|
||||||
class FrontController {
|
|
||||||
private AltoRouter $router;
|
|
||||||
private string $basePath;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(string $basePath) {
|
|
||||||
$this->router = $this->createRouter($basePath);
|
|
||||||
$this->basePath = $basePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addRoute(string $method, string $path, Action $action): void {
|
|
||||||
$this->router->map($method, $path, $action);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param MutableSessionHandle $session
|
|
||||||
* @return void
|
|
||||||
* @throws LoaderError
|
|
||||||
* @throws RuntimeError
|
|
||||||
* @throws SyntaxError
|
|
||||||
*/
|
|
||||||
public function run(MutableSessionHandle $session): void {
|
|
||||||
$match = $this->router->match();
|
|
||||||
if ($match) {
|
|
||||||
$this->handleMatch($match, $session);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->displayViewByKind(ViewHttpResponse::twig("error.html.twig", [
|
|
||||||
'failures' => [ValidationFail::notFound("Could not find page ${_SERVER['REQUEST_URI']}.")],
|
|
||||||
], HttpCodes::NOT_FOUND));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new instance of an AltoRouter
|
|
||||||
*
|
|
||||||
* @param string $basePath
|
|
||||||
* @return AltoRouter
|
|
||||||
*/
|
|
||||||
public function createRouter(string $basePath): AltoRouter {
|
|
||||||
$router = new AltoRouter();
|
|
||||||
$router->setBasePath($basePath);
|
|
||||||
return $router;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<string, mixed> $match
|
|
||||||
* @param MutableSessionHandle $session
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function handleMatch(array $match, MutableSessionHandle $session): void {
|
|
||||||
$action = $match['target'];
|
|
||||||
$params = array_values($match["params"]);
|
|
||||||
$this->handleResponseByType($this->tryToCall($action, $params, $session));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Action $action
|
|
||||||
* @param array<int, mixed> $params
|
|
||||||
* @param MutableSessionHandle $session
|
|
||||||
* @return HttpResponse
|
|
||||||
*/
|
|
||||||
private function tryToCall(Action $action, array $params, MutableSessionHandle $session): HttpResponse {
|
|
||||||
$account = null;
|
|
||||||
if ($action->isAuthRequired()) {
|
|
||||||
$account = $session->getAccount();
|
|
||||||
if ($account == null) {
|
|
||||||
// put in the session the initial url the user wanted to get
|
|
||||||
$session->setInitialTarget($_SERVER['REQUEST_URI']);
|
|
||||||
return HttpResponse::redirect($this->basePath . "/login");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $action->run($params, $session);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redirect the return by the response's type
|
|
||||||
*
|
|
||||||
* @param HttpResponse $response
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function handleResponseByType(HttpResponse $response): void {
|
|
||||||
http_response_code($response->getCode());
|
|
||||||
|
|
||||||
foreach ($response->getHeaders() as $header => $value) {
|
|
||||||
header("$header: $value");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($response instanceof ViewHttpResponse) {
|
|
||||||
$this->displayViewByKind($response);
|
|
||||||
} elseif ($response instanceof JsonHttpResponse) {
|
|
||||||
header('Content-type: application/json');
|
|
||||||
echo $response->getJson();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use the right method to display the response
|
|
||||||
*
|
|
||||||
* @param ViewHttpResponse $response
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function displayViewByKind(ViewHttpResponse $response): void {
|
|
||||||
$file = $response->getFile();
|
|
||||||
$args = $response->getArguments();
|
|
||||||
|
|
||||||
switch ($response->getViewKind()) {
|
|
||||||
case ViewHttpResponse::REACT_VIEW:
|
|
||||||
send_react_front($file, $args);
|
|
||||||
break;
|
|
||||||
case ViewHttpResponse::TWIG_VIEW:
|
|
||||||
try {
|
|
||||||
$loader = new FilesystemLoader('../src/Views/');
|
|
||||||
$twig = new Environment($loader);
|
|
||||||
$twig->display($file, $args);
|
|
||||||
} catch (RuntimeError|SyntaxError|LoaderError $e) {
|
|
||||||
http_response_code(500);
|
|
||||||
echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s");
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace IQBall\Core;
|
||||||
|
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
class Connexion {
|
class Connection {
|
||||||
private PDO $pdo;
|
private PDO $pdo;
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Data;
|
namespace IQBall\Core\Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class of a user account.
|
* Base class of a user account.
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Data;
|
namespace IQBall\Core\Data;
|
||||||
|
|
||||||
use http\Url;
|
use http\Url;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Data;
|
namespace IQBall\Core\Data;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Data;
|
namespace IQBall\Core\Data;
|
||||||
|
|
||||||
use http\Exception\InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration class workaround
|
* Enumeration class workaround
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Data;
|
namespace IQBall\Core\Data;
|
||||||
|
|
||||||
class TacticInfo implements \JsonSerializable {
|
class TacticInfo implements \JsonSerializable {
|
||||||
private int $id;
|
private int $id;
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Data;
|
namespace IQBall\Core\Data;
|
||||||
|
|
||||||
use http\Url;
|
use http\Url;
|
||||||
|
|
@ -1,18 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Gateway;
|
namespace IQBall\Core\Gateway;
|
||||||
|
|
||||||
use App\Connexion;
|
use IQBall\Core\Connection;
|
||||||
use App\Data\Account;
|
use IQBall\Core\Data\Account;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
class AccountGateway {
|
class AccountGateway {
|
||||||
private Connexion $con;
|
private Connection $con;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Connexion $con
|
* @param Connection $con
|
||||||
*/
|
*/
|
||||||
public function __construct(Connexion $con) {
|
public function __construct(Connection $con) {
|
||||||
$this->con = $con;
|
$this->con = $con;
|
||||||
}
|
}
|
||||||
|
|
@ -1,17 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Gateway;
|
namespace IQBall\Core\Gateway;
|
||||||
|
|
||||||
use App\Connexion;
|
use IQBall\Core\Connection;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
class AuthGateway {
|
class AuthGateway {
|
||||||
private Connexion $con;
|
private Connection $con;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Connexion $con
|
* @param Connection $con
|
||||||
*/
|
*/
|
||||||
public function __construct(Connexion $con) {
|
public function __construct(Connection $con) {
|
||||||
$this->con = $con;
|
$this->con = $con;
|
||||||
}
|
}
|
||||||
|
|
@ -1,18 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Gateway;
|
namespace IQBall\Core\Gateway;
|
||||||
|
|
||||||
use App\Connexion;
|
use IQBall\Core\Connection;
|
||||||
use App\Data\TacticInfo;
|
use IQBall\Core\Data\TacticInfo;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
class TacticInfoGateway {
|
class TacticInfoGateway {
|
||||||
private Connexion $con;
|
private Connection $con;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Connexion $con
|
* @param Connection $con
|
||||||
*/
|
*/
|
||||||
public function __construct(Connexion $con) {
|
public function __construct(Connection $con) {
|
||||||
$this->con = $con;
|
$this->con = $con;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http;
|
namespace IQBall\Core\Http;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class to define constants of used http codes
|
* Utility class to define constants of used http codes
|
@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http;
|
namespace IQBall\Core\Http;
|
||||||
|
|
||||||
use App\Validation\FieldValidationFail;
|
use IQBall\Core\Validation\FieldValidationFail;
|
||||||
use App\Validation\Validation;
|
use IQBall\Core\Validation\Validation;
|
||||||
use App\Validation\ValidationFail;
|
use IQBall\Core\Validation\ValidationFail;
|
||||||
use App\Validation\Validator;
|
use IQBall\Core\Validation\Validator;
|
||||||
use ArrayAccess;
|
use ArrayAccess;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http;
|
namespace IQBall\Core\Http;
|
||||||
|
|
||||||
class HttpResponse {
|
class HttpResponse {
|
||||||
/**
|
/**
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http;
|
namespace IQBall\Core\Http;
|
||||||
|
|
||||||
class JsonHttpResponse extends HttpResponse {
|
class JsonHttpResponse extends HttpResponse {
|
||||||
/**
|
/**
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http;
|
namespace IQBall\Core\Http;
|
||||||
|
|
||||||
class ViewHttpResponse extends HttpResponse {
|
class ViewHttpResponse extends HttpResponse {
|
||||||
public const TWIG_VIEW = 0;
|
public const TWIG_VIEW = 0;
|
@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Model;
|
namespace IQBall\Core\Model;
|
||||||
|
|
||||||
use App\Data\Account;
|
use IQBall\Core\Data\Account;
|
||||||
use App\Gateway\AccountGateway;
|
use IQBall\Core\Gateway\AccountGateway;
|
||||||
use App\Validation\FieldValidationFail;
|
use IQBall\Core\Validation\FieldValidationFail;
|
||||||
use App\Validation\ValidationFail;
|
use IQBall\Core\Validation\ValidationFail;
|
||||||
|
|
||||||
class AuthModel {
|
class AuthModel {
|
||||||
private AccountGateway $gateway;
|
private AccountGateway $gateway;
|
@ -1,11 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Model;
|
namespace IQBall\Core\Model;
|
||||||
|
|
||||||
use App\Data\Account;
|
use IQBall\Core\Gateway\TacticInfoGateway;
|
||||||
use App\Data\TacticInfo;
|
use IQBall\Core\Validation\ValidationFail;
|
||||||
use App\Gateway\TacticInfoGateway;
|
use IQBall\Core\Data\TacticInfo;
|
||||||
use App\Validation\ValidationFail;
|
|
||||||
|
|
||||||
class TacticModel {
|
class TacticModel {
|
||||||
public const TACTIC_DEFAULT_NAME = "Nouvelle tactique";
|
public const TACTIC_DEFAULT_NAME = "Nouvelle tactique";
|
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IQBall\Core\Route;
|
||||||
|
|
||||||
|
use IQBall\Core\Http\HttpResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template S session
|
||||||
|
*/
|
||||||
|
abstract class AbstractAction {
|
||||||
|
/**
|
||||||
|
* @var callable(mixed[]): HttpResponse $action action to call
|
||||||
|
*/
|
||||||
|
protected $action;
|
||||||
|
|
||||||
|
private bool $isAuthRequired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param callable(mixed[]): HttpResponse $action
|
||||||
|
*/
|
||||||
|
protected function __construct(callable $action, bool $isAuthRequired) {
|
||||||
|
$this->action = $action;
|
||||||
|
$this->isAuthRequired = $isAuthRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isAuthRequired(): bool {
|
||||||
|
return $this->isAuthRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] $params
|
||||||
|
* @param S $session
|
||||||
|
* @return HttpResponse
|
||||||
|
*/
|
||||||
|
public abstract function run(array $params, $session): HttpResponse;
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Session;
|
namespace IQBall\Core\Session;
|
||||||
|
|
||||||
use App\Data\Account;
|
use IQBall\Core\Data\Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mutable side of a session handle
|
* The mutable side of a session handle
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Session;
|
namespace IQBall\Core\Session;
|
||||||
|
|
||||||
use App\Data\Account;
|
use IQBall\Core\Data\Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A PHP session handle
|
* A PHP session handle
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Session;
|
namespace IQBall\Core\Session;
|
||||||
|
|
||||||
use App\Data\Account;
|
use IQBall\Core\Data\Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An immutable session handle
|
* An immutable session handle
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace IQBall\Core\Validation;
|
||||||
|
|
||||||
class ComposedValidator extends Validator {
|
class ComposedValidator extends Validator {
|
||||||
private Validator $first;
|
private Validator $first;
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace IQBall\Core\Validation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An error that concerns a field, with a bound message name
|
* An error that concerns a field, with a bound message name
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace IQBall\Core\Validation;
|
||||||
|
|
||||||
class FunctionValidator extends Validator {
|
class FunctionValidator extends Validator {
|
||||||
/**
|
/**
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace IQBall\Core\Validation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple validator that takes a predicate and an error factory
|
* A simple validator that takes a predicate and an error factory
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace IQBall\Core\Validation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for validation
|
* Utility class for validation
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace IQBall\Core\Validation;
|
||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace IQBall\Core\Validation;
|
||||||
|
|
||||||
abstract class Validator {
|
abstract class Validator {
|
||||||
/**
|
/**
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace IQBall\Core\Validation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of standard validators
|
* A collection of standard validators
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validator;
|
namespace IQBall\Core\Validator;
|
||||||
|
|
||||||
use App\Data\TacticInfo;
|
use IQBall\Core\Data\TacticInfo;
|
||||||
use App\Validation\ValidationFail;
|
use IQBall\Core\Validation\ValidationFail;
|
||||||
|
|
||||||
class TacticValidator {
|
class TacticValidator {
|
||||||
public static function validateAccess(?TacticInfo $tactic, int $tacticId, int $ownerId): ?ValidationFail {
|
public static function validateAccess(?TacticInfo $tactic, int $tacticId, int $ownerId): ?ValidationFail {
|
Loading…
Reference in new issue