- print_r: documentation ( source)
- parse_ini_string: documentation ( source)
<?php
// Configure here:
$userSpecifiedPath = '/';
// ================================================================
// Don't edit below
// ================================================================
$routerConfig = <<<CONFIG
[/]
"Controller" = "HomepageController"
[404]
"Controller" = "404Controller"
CONFIG;
class Router {
private $routes;
public function __construct($routes) {
$this->routes = $routes;
}
public function getControllerFromPath($path) {
if(array_key_exists($path, $this->routes) === true) {
return $this->routes[$path];
} elseif(array_key_exists('404', $this->routes) === true) {
return $this->routes['404'];
}
}
}
$routes = parse_ini_string($routerConfig, true);
print_r($routes);
$Router = new Router($routes);
echo 'Using controller: ' . $Router->getControllerFromPath($userSpecifiedPath);