Domain registry project http://reg.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
711 B

<?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);
}
}