/**
  * Allows the application to load a custom or default session.
  *
  * The logic and options for creating this object are adequately generic for default cases
  * but for many applications it will make sense to override this method and create a session,
  * if required, based on more specific needs.
  *
  * @param   JSession  $session  An optional session object. If omitted, the session is created.
  *
  * @return  JApplicationWeb This method is chainable.
  *
  * @since   11.3
  */
 public function loadSession(Session $session = null)
 {
     if ($session !== null) {
         $this->session = $session;
         return $this;
     }
     // Generate a session name.
     $name = md5($this->get('secret') . $this->get('session_name', get_class($this)));
     // Calculate the session lifetime.
     $lifetime = $this->get('sess_lifetime') ? $this->get('sess_lifetime') * 60 : 900;
     // Get the session handler from the configuration.
     $handler = $this->get('sess_handler', 'none');
     // Initialize the options for JSession.
     $options = array('name' => $name, 'expire' => $lifetime, 'force_ssl' => $this->get('force_ssl'));
     $this->registerEvent('onAfterSessionStart', array($this, 'afterSessionStart'));
     // Instantiate the session object.
     $session = Session::getInstance($handler, $options);
     $session->initialise($this->input, $this->dispatcher);
     if ($session->getState() == 'expired') {
         $session->restart();
     } else {
         $session->start();
     }
     // Set the session object.
     $this->session = $session;
     return $this;
 }
 /**
  * Create a session object
  *
  * @param   array  $options  An array containing session options
  *
  * @return  Session object
  *
  * @since   11.1
  */
 protected static function createSession(array $options = array())
 {
     // Get the editor configuration setting
     $conf = self::getConfig();
     $handler = $conf->get('session_handler', 'none');
     // Config time is in minutes
     $options['expire'] = $conf->get('lifetime') ? $conf->get('lifetime') * 60 : 900;
     $session = Session::getInstance($handler, $options);
     if ($session->getState() == 'expired') {
         $session->restart();
     }
     return $session;
 }