microserviciile de register, login finalizate

This commit is contained in:
Cerbu Andrei Mihnea
2023-06-15 22:21:53 +03:00
parent a739a66ae4
commit 4e585ba278
159 changed files with 4775 additions and 1747 deletions
Regular → Executable
+47 -49
View File
@@ -1,50 +1,48 @@
<?php
namespace app\core;
use app\core\exceptions\NotFoundException;
class Router
{
public Request $request;
public Response $response;
protected array $routes = [];
public function __construct(Request $request, Response $response)
{
$this->request = $request;
$this->response = $response;
}
public function get($path, $callback)
{
$this->routes['get'][$path] = $callback;
}
public function post($path, $callback)
{
$this->routes['post'][$path] = $callback;
}
public function resolve()
{
$path = $this->request->getPath();
$method = $this->request->method();
$callback = $this->routes[$method][$path] ?? false;
if (!$callback) {
throw new NotFoundException();
}
$controller = new $callback[0]();
Application::$app->controller = $controller;
$controller->action = $callback[1];
$callback[0] = $controller;
foreach ($controller->getMiddlewares() as $middleware) {
$middleware->execute();
}
return call_user_func($callback, $this->request, $this->response);
}
<?php
namespace app\core;
use app\exceptions\PageNotFoundException;
class Router
{
public Request $request;
protected array $routes = [];
public function __construct(Request $request)
{
$this->request = $request;
}
public function get($path, $callback): void
{
$this->routes['GET'][$path] = $callback;
}
public function post($path, $callback): void
{
$this->routes['POST'][$path] = $callback;
}
/**
* @throws PageNotFoundException
*/
public function resolve()
{
$path = $this->request->getPath();
$method = $this->request->method();
$callback = $this->routes[$method][$path] ?? false;
if (!$callback) {
throw new PageNotFoundException();
}
Application::$app->controller = new $callback[0]();
/*
* TODO:
* de adaugat aici middleware urile asociate unui controller
*/
return call_user_func($callback, $this->request);
}
}