/** * Sign a user out * * @param id $user_id * @param string $name * @return false */ public function sign_out() { if (!$this->authenticated) { return false; } // remove the restore login \DB::delete($this->config->get('logins.table'))->where('restore_token', $this->restore_key($this->user))->run(); // logout the user $this->session->delete($this->config->session_key); // pass the user object through all user hooks $this->user = \CCEvent::pass('auth.sign_out', $this->user); $this->user->save(); $user_model = $this->config->user_model; // create new empty user $this->user = new $user_model(); return $this->authenticated = false; }
/** * send response * means printing the response and setting the headers if set * * @param bool $headers * @return void */ public function send($headers = false) { if ($headers && headers_sent() && !CLI) { throw new CCException("CCResponse::send - cannot send header, header has already been send."); } if ($headers) { // status header header(CCIn::server('SERVER_PROTOCOL') . ' ' . $this->_status . ' ' . CCResponse::$messages[$this->_status]); // check if content type is already set if (!isset($this->_header['Content-Type'])) { $this->header('Content-Type', 'text/html; charset=' . ClanCats::$config->get('charset', 'utf-8')); } $this->header('X-Powered-By', 'ClanCatsFramework version: ' . ClanCats::VERSION); // set headers foreach ($this->_header as $key => $content) { header($key . ': ' . $content); } } // profiler CCProfiler::check('CCResponse - sending response'); // print the body echo CCEvent::pass('response.output', $this->body()); }
/** * Resolve an uri and get the route object * * @param string $uri * @return CCRoute */ public static function resolve($uri) { // cut unnecessary slashes and params if (substr($uri, -1) == '/') { $uri = substr($uri, 0, -1); } if (substr($uri, 0, 1) == '/') { $uri = substr($uri, 1); } $uri = CCStr::cut($uri, '?'); // create new route instance $route = new CCRoute($uri); // private route if (substr($uri, 0, 1) == '#') { if (!array_key_exists($uri, static::$privates)) { throw new CCException("CCRouter::resolve() - private route {$uri} could not be found."); } return static::configure($route, static::$privates[$uri]); } // pass the route trough the priority events if ($hook_route = CCEvent::pass('ccf.router.resolve.before', array($route, false))) { if ($hook_route[1] === true) { return static::configure($route, $hook_route[0]); } } // if the uri is empty root is requestet if (empty($uri)) { // try one slash also aka empty if (array_key_exists('', static::$routes)) { return static::configure($route, static::$routes['']); } return static::configure($route, static::$privates['#root']); } // simple static key route if (isset(static::$routes[$uri])) { return static::configure($route, static::$routes[$uri]); } // explode the uri $uri_parts = explode('/', $uri); // get the action $action = array_pop($uri_parts); // implode the uri without action $uri_without_action = implode('/', $uri_parts); // try the static key with an action if (isset($action)) { if (isset(static::$routes[$uri_without_action])) { if (CCController::has_action(static::$routes[$uri_without_action], $action)) { $route->action = $action; return static::configure($route, static::$routes[$uri_without_action]); } } } // dynamic keys foreach (static::$routes as $pattern => $dynamic_route) { // try the dynamic route only if it can be a pattern if (strpos($pattern, '[') !== false && strpos($pattern, ']') !== false) { // build an reqular expression $regx = '#^' . CCStr::replace($pattern, static::$filters) . '$#i'; // try to match the uri with regex if (preg_match($regx, $uri, $params)) { // remove the first param unset($params[0]); $route->action = null; $route->params = $params; return static::configure($route, $dynamic_route); } // try to match the uri without the action with the regex if (is_string($dynamic_route) && preg_match($regx, $uri_without_action, $params)) { if (CCController::has_action($dynamic_route, $action)) { // remove the first param unset($params[0]); $route->action = $action; $route->params = $params; return static::configure($route, $dynamic_route); } } } } /* * pass to events */ if ($hook_route = CCEvent::pass('ccf.router.resolve.after', array($route, false))) { if ($hook_route[1] === true) { return static::configure($route, $hook_route[0]); } } return false; }