add: Router

This commit is contained in:
Johannes Kantz
2022-12-08 14:43:05 +01:00
parent 86f2c5e91e
commit 63f7ef5eee
4 changed files with 335 additions and 0 deletions

49
Router/Route.php Normal file
View File

@@ -0,0 +1,49 @@
<?php namespace Router;
class Route
{
private array $methods = [];
public function __construct(string $method = null, $controller = null)
{
if ($method != null && $controller != null) {
$this->methods[$method] = $controller;
}
}
public function get($controller)
{
$this->methods["GET"] = $controller;
return $this;
}
public function post($controller)
{
$this->methods["POST"] = $controller;
return $this;
}
public function put($controller)
{
$this->methods["PUT"] = $controller;
return $this;
}
public function delete($controller)
{
$this->methods["DELETE"] = $controller;
return $this;
}
public function all($controller)
{
$this->methods["ALL"] = $controller;
return $this;
}
public function getController(string $method)
{
return $this->methods[$method] ?? $this->methods["ALL"];
}
}