/** * This method runs the application * parses URL, to get controller & action to run * if URL is invalid, passes control to ErrorController */ public function delegate() { $destination = $this->parseUrl(); $this->registry['args'] = $destination->args; $this->registry['name'] = $destination->name . ':' . $destination->action; $file = $destination->file; $controller = $destination->controller; $action = $destination->action; // $action = "action". ucfirst($destination->action); // File available? if (!file_exists($file)) { $controller = $this->controllersNamespace . "ErrorController"; $controllerFile = "ErrorController"; $file = $this->controllersDir . $controllerFile . '.php'; $action = 'actionIndex'; } if (is_readable($file) == false) { throw new \Exception("File '{$file}' cannot be read from filesystem"); } include $file; $controllerObj = new $controller($this->registry); if (!method_exists($controllerObj, $action) and !method_exists($controllerObj, "action" . ucfirst($destination->action))) { unset($controllerObj); $this->registry->remove('args'); // pass control to ErrorController $controller = $this->controllersNamespace . "ErrorController"; $controllerFile = 'ErrorController'; $action = 'actionIndex'; $file = $this->controllersDir . "{$controllerFile}.php"; include $file; // Initiate the class $controllerObj = new $controller($this->registry); } // Start session $s = Stupid::getSession(); if (!$s->isStarted() && $s->exists()) { $s->start(); } if (method_exists($controllerObj, 'startup')) { $controllerObj->startup(); } if (method_exists($controllerObj, "action" . ucfirst($destination->action))) { // Run Controller::action<Action>() $action = "action" . ucfirst($destination->action); $controllerObj->{$action}(); } else { $controllerObj->{$action}(); } }
/** * Sets the authenticated status of this user. * @param bool flag indicating the authenticated status of user * @return User provides a fluent interface */ protected function setAuthenticated($state) { $session = $this->getUserNamespace(true); $session->authenticated = (bool) $state; // Session Fixation defence Stupid::getSession()->regenerateId(); if ($state) { $session->reason = NULL; $session->authTime = time(); // informative value } else { $session->reason = self::MANUAL; $session->authTime = NULL; } return $this; }