mirror of
https://github.com/PurpleI2P/regi2p.git
synced 2025-01-15 18:09:57 +00:00
29 lines
709 B
PHP
29 lines
709 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
class Router
|
|
{
|
|
private $routes;
|
|
private $errRoute;
|
|
|
|
public function addRoute($pattern, $function) {
|
|
$this->routes['{'.$pattern.'}'] = $function;
|
|
}
|
|
|
|
public function addErrorRoute($function) {
|
|
$this->errRoute = $function;
|
|
}
|
|
|
|
public function run() {
|
|
foreach ($this->routes as $pattern => $function) {
|
|
if (preg_match($pattern, $_SERVER['REQUEST_URI'], $params)) {
|
|
array_shift($params);
|
|
array_unshift($params, $_SERVER['REQUEST_URI']);
|
|
return call_user_func_array($function, array_values($params));
|
|
}
|
|
}
|
|
return call_user_func($this->errRoute);
|
|
}
|
|
}
|