static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
public function __construct() { debug('Initializing ' . __CLASS__); // Register Exception Handlers set_error_handler(array(__CLASS__, "errorHandler")); set_exception_handler(array(__CLASS__, "exceptionHandler")); //$this->request = Araknid_Request::getInstance(); $this->router = Araknid_Router::getInstance(); // Setup default routes $defaults = array('/' => array('controller' => 'main', 'action' => 'index'), '/:controller' => array('action' => 'index'), '/:controller/:action' => array()); // Looking for a routes.php in Application directory if (file_exists(APP_CONFIG_PATH . '/routes.php')) { include APP_CONFIG_PATH . '/routes.php'; $this->router->routes(array_merge($cfg['routes'], $defaults)); } else { $this->router->routes($defaults); } if (!($route = $this->router->execute())) { throw new Exception('No Route for ' . $this->router->request); } // Initializing controller if (is_callable(array($route->controller, $route->action)) && class_exists($route->controller)) { $R = new ReflectionClass($route->controller); $O = $R->newInstance($route->params['id']); $O->params = $route->params; $method = $route->action; $response = $O->{$method}(); // $response = call_user_func_array(array(&$O, $route->action), $route->params); return; } else { if (!class_exists($route->controller)) { throw new Exception("Not A Valid Controller: '{$route->controller}'"); } } }