This commit is contained in:
Malte Schulze Hobeling 2022-12-15 14:55:00 +01:00
parent e3a7e4ea57
commit 26b0cd04bd
3 changed files with 52 additions and 0 deletions

View File

@ -8,6 +8,7 @@ class Response
* @param string $data * @param string $data
* @param int? $status * @param int? $status
* @return void * @return void
* @author Johannes Kantz
*/ */
public function send(string $data, int $status = null) public function send(string $data, int $status = null)
{ {
@ -22,6 +23,7 @@ class Response
* @param array $data * @param array $data
* @param int? $status * @param int? $status
* @return void * @return void
* @author Johannes Kantz
*/ */
public function json(array $data, int $status = null) public function json(array $data, int $status = null)
{ {
@ -36,6 +38,7 @@ class Response
* Set the status code * Set the status code
* @param int $status * @param int $status
* @return void * @return void
* @author Johannes Kantz
*/ */
public function status(int $status) public function status(int $status)
{ {

View File

@ -5,6 +5,11 @@ class Route
{ {
private array $methods = []; private array $methods = [];
/**
* @param string|null $method
* @param $controller
* @author Johannes Kantz
*/
public function __construct(string $method = null, $controller = null) public function __construct(string $method = null, $controller = null)
{ {
if ($method != null && $controller != null) { if ($method != null && $controller != null) {
@ -12,36 +17,66 @@ class Route
} }
} }
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
public function get($controller) public function get($controller)
{ {
$this->methods["GET"] = $controller; $this->methods["GET"] = $controller;
return $this; return $this;
} }
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
public function post($controller) public function post($controller)
{ {
$this->methods["POST"] = $controller; $this->methods["POST"] = $controller;
return $this; return $this;
} }
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
public function put($controller) public function put($controller)
{ {
$this->methods["PUT"] = $controller; $this->methods["PUT"] = $controller;
return $this; return $this;
} }
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
public function delete($controller) public function delete($controller)
{ {
$this->methods["DELETE"] = $controller; $this->methods["DELETE"] = $controller;
return $this; return $this;
} }
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
public function all($controller) public function all($controller)
{ {
$this->methods["ALL"] = $controller; $this->methods["ALL"] = $controller;
return $this; return $this;
} }
/**
* @param string $method
* @return mixed
* @author Johannes Kantz
*/
public function getController(string $method) public function getController(string $method)
{ {
return $this->methods[$method] ?? $this->methods["ALL"]; return $this->methods[$method] ?? $this->methods["ALL"];

View File

@ -16,6 +16,7 @@ class Router
/** /**
* Router * Router
* @author Johannes Kantz
*/ */
public function __construct(string $pathname) public function __construct(string $pathname)
{ {
@ -44,6 +45,7 @@ class Router
* @param string $uri * @param string $uri
* @param $middleware * @param $middleware
* @return void * @return void
* @author Johannes Kantz
*/ */
public function use(string $uri, callable $middleware): void public function use(string $uri, callable $middleware): void
{ {
@ -54,6 +56,7 @@ class Router
* get Middleware for uri * get Middleware for uri
* @param string $uri * @param string $uri
* @return array * @return array
* @author Johannes Kantz
*/ */
private function getMiddleware(): array private function getMiddleware(): array
{ {
@ -70,6 +73,7 @@ class Router
* Calls the middleware * Calls the middleware
* @param array $middleware * @param array $middleware
* @return void * @return void
* @author Johannes Kantz
*/ */
private function callMiddleware(array $middleware): void private function callMiddleware(array $middleware): void
{ {
@ -83,6 +87,7 @@ class Router
* @param string $uri * @param string $uri
* @param $controller * @param $controller
* @return void * @return void
* @author Johannes Kantz
*/ */
public function get(string $uri, callable $controller): void public function get(string $uri, callable $controller): void
{ {
@ -94,6 +99,7 @@ class Router
* @param string $uri * @param string $uri
* @param $controller * @param $controller
* @return void * @return void
* @author Johannes Kantz
*/ */
public function post(string $uri, callable $controller): void public function post(string $uri, callable $controller): void
{ {
@ -105,6 +111,7 @@ class Router
* @param string $uri * @param string $uri
* @param $controller * @param $controller
* @return void * @return void
* @author Johannes Kantz
*/ */
public function put(string $uri, callable $controller): void public function put(string $uri, callable $controller): void
{ {
@ -116,6 +123,7 @@ class Router
* @param string $uri * @param string $uri
* @param $controller * @param $controller
* @return void * @return void
* @author Johannes Kantz
*/ */
public function delete(string $uri, callable $controller): void public function delete(string $uri, callable $controller): void
{ {
@ -127,6 +135,7 @@ class Router
* @param string $uri * @param string $uri
* @param $controller * @param $controller
* @return void * @return void
* @author Johannes Kantz
*/ */
public function all(string $uri, callable $controller): void public function all(string $uri, callable $controller): void
{ {
@ -137,6 +146,7 @@ class Router
* Route * Route
* @param string $uri * @param string $uri
* @return void * @return void
* @author Johannes Kantz
*/ */
public function route(string $uri): Route public function route(string $uri): Route
{ {
@ -149,6 +159,7 @@ class Router
* @param string $uri * @param string $uri
* @param array $params * @param array $params
* @return string * @return string
* @author Johannes Kantz
*/ */
private function routeMatches(string $route, string $uri): bool private function routeMatches(string $route, string $uri): bool
{ {
@ -175,6 +186,7 @@ class Router
* @param string $uri * @param string $uri
* @param array $params * @param array $params
* @return array * @return array
* @author Johannes Kantz
*/ */
private function getParams(string $route, string $uri): array private function getParams(string $route, string $uri): array
{ {
@ -193,6 +205,7 @@ class Router
/** /**
* gets the controller for the given uri * gets the controller for the given uri
* @param array $routes * @param array $routes
* @author Johannes Kantz
*/ */
private function getController(): callable|bool private function getController(): callable|bool
{ {
@ -211,6 +224,7 @@ class Router
/** /**
* Starts the router * Starts the router
* @return void * @return void
* @author Johannes Kantz
*/ */
public function start(): void public function start(): void
{ {