49 lines
998 B
PHP
49 lines
998 B
PHP
<?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"];
|
|
}
|
|
} |