Can you review my code?
class Router {
/**
* Store the current URI [0] => Controller/ [1] => Method/ [2]=> parameter
* @var array
*/
private $URI = array();
/**
* Store an instance of configuration object
* @var object
*/
private $config = NULL;
/**
* Store an instance of Application object
* @var object
*/
private $app = NULL;
/**
* Initialize the router
*/
public function __construct() {
$this->startup();
}
/**
*
* @param object $route
* @return string
*/
public function get($route) {
return $this->config->getRoute($route);
}
/**
* First step, to catch the url and manipulate it.
*/
private function startup() {
if ($url = $this->getURL()) {
$this->app = Application::getAppInstance();
$this->config = Application::getInstance('Configuration');
if ($this->validateURL()) {
$class = (isset($url[1])) ? $url[1] : $this->get('defaultController');
unset($url[1]);
$method = (isset($url[2])) ? $url[2] : $this->get('defaultMethod');
unset($url[2]);
$params = (count($url > 0)) ? $url : "";
unset($url);
if (class_exists($class)) {
$controller = $this->app->getInstance($class);
} else {
exit("Class not found");
}
if (method_exists($controller, $method)) {
if ($params !== "") {
call_user_func_array(array($class, $method), $params);
} else {
$controller->{$method}();
}
} else {
exit("Method not found");
}
} else {
exit("URI chars not allowed");
}
} else {
if ($this->get('defaultController') !== "") {
$this->app->getInstance($this->get('defaultController'));
call_user_func(array($this->get('defaultController'), $this->get('defaultMethod')));
} else {
echo "Default does not added.";
}
}
}
/**
* Get the current url and convert into an array
* @return array
*/
private function getURL() {
$currentURL = $_SERVER['QUERY_STRING'];
if ($currentURL !== "") {
$currentURL = rtrim($currentURL, '/');
$currentURL = explode('/', $currentURL);
unset($currentURL[0]);
$this->URI = $currentURL;
return $currentURL;
}
return false;
}
/**
* Validate the URI characters
* @return boolean
*/
private function validateURL() {
foreach ($this->URI as $uri) {
if (!preg_match("/^[" . $this->config->get('allow_uri_chars') . "]+$/i", $uri)) {
return false;
}
}
return true;
}
}