class CRouter
{
public $controllerName = 'main';
public $actionName = 'index';
public $arrayGET = array();
private $uri;
private function getURI() {
$request_uri = filter_input(\INPUT_SERVER, 'REQUEST_URI');
$this->uri = isset($request_uri) ? $request_uri : '';
}
private function parseURI() {
$routes = explode('/', $this->uri);
if(!empty($routes[1])) {
$this->controllerName = $routes[1];
} else {
return;
}
if(!empty($routes[2])) {
$this->actionName = $routes[2];
} else {
return;
}
for($i = 3; $i < count($routes); $i+=2) {
if(!empty($routes[$i]) && !empty($routes[$i + 1])) {
$this->arrayGET[$routes[$i]] = $routes[$i + 1];
} else {
return;
}
}
}
/**
* This is the run
*/
public function run() {
$this->getURI();
$this->parseURI();
}
}
$route = new CRouter();
$route->run();
echo $route->controllerName.'/';
echo $route->actionName.'/';
foreach($route->arrayGET as $key => $value) {
echo $key.'/'.$value.'/';
}
Правильность данного подхода реализации маршрутизатора?