/** * Create the session object. * * @param boolean $create_session * Whether to create the session for the user. * * @return Session * The current session. */ public static function createInstance($create_session = true) { if ($session_key = static::loadRequestSessionKey()) { $session_criteria = array('session_key' => array('LIKE', $session_key)); // If the session is only allowed on one IP. if (Configuration::get('session.single_ip')) { $session_criteria['session_ip'] = LightningRequest::server('ip_int'); } // See if the session exists. if ($session_details = Database::getInstance()->selectRow('session', $session_criteria)) { // Load the session. $session = new static($session_details); if ($session->validateState()) { $session->ping(); return $session; } else { $session->destroy(); return static::create(); } } else { // Possible security issue. Logger::security('Bad session', Logger::SEVERITY_MED); // There is an old cookie that we should delete. // Send a cookie to erase the users cookie, in case this is really a minor error. static::clearCookie(); return static::create(); } } elseif ($create_session) { // No session exists, create a new one. return static::create(); } else { return null; } }
/** * Instantiate and bring up an encapsulated instance * * @param string|Instance $instance */ public static function unmake($instance) { try { $_capsule = new static($instance, true); } catch (\Exception $_ex) { // Ignored } finally { isset($_capsule) && $_capsule->destroy(); } }