add: Router
This commit is contained in:
49
Router/Route.php
Normal file
49
Router/Route.php
Normal 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"];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user