1
0
mirror of https://github.com/PurpleI2P/regi2p.git synced 2025-01-15 18:09:57 +00:00
regi2p/lib/router.php
r4sas 80bb08fbd2
reg.i2p files
Signed-off-by: r4sas <r4sas@i2pmail.org>
2021-02-21 17:02:38 +00:00

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