DirektiveDesDons/Router/Route.php

84 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2022-12-08 14:43:05 +01:00
<?php namespace Router;
class Route
{
private array $methods = [];
2022-12-15 14:55:00 +01:00
/**
* @param string|null $method
* @param $controller
* @author Johannes Kantz
*/
2022-12-08 14:43:05 +01:00
public function __construct(string $method = null, $controller = null)
{
if ($method != null && $controller != null) {
$this->methods[$method] = $controller;
}
}
2022-12-15 14:55:00 +01:00
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
2022-12-08 14:43:05 +01:00
public function get($controller)
{
$this->methods["GET"] = $controller;
return $this;
}
2022-12-15 14:55:00 +01:00
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
2022-12-08 14:43:05 +01:00
public function post($controller)
{
$this->methods["POST"] = $controller;
return $this;
}
2022-12-15 14:55:00 +01:00
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
2022-12-08 14:43:05 +01:00
public function put($controller)
{
$this->methods["PUT"] = $controller;
return $this;
}
2022-12-15 14:55:00 +01:00
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
2022-12-08 14:43:05 +01:00
public function delete($controller)
{
$this->methods["DELETE"] = $controller;
return $this;
}
2022-12-15 14:55:00 +01:00
/**
* @param $controller
* @return $this
* @author Johannes Kantz
*/
2022-12-08 14:43:05 +01:00
public function all($controller)
{
$this->methods["ALL"] = $controller;
return $this;
}
2022-12-15 14:55:00 +01:00
/**
* @param string $method
* @return mixed
* @author Johannes Kantz
*/
2022-12-08 14:43:05 +01:00
public function getController(string $method)
{
return $this->methods[$method] ?? $this->methods["ALL"];
}
}