public function testSetGet()
 {
     $session = new Session([]);
     $this->assertNull($session->get('unit'));
     $session->set('unit', 'test');
     $this->assertEquals('test', $session->get('unit'));
 }
 /**
  * Method to get the session handler field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     $options = array();
     // Get the options from JSession.
     foreach (Session::getStores() as $store) {
         $options[] = Html::_('select.option', $store, Text::_('JLIB_FORM_VALUE_SESSION_' . $store), 'value', 'text');
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Beispiel #3
0
 /**
  * Method to get the session handler field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     $options = array();
     // Get the options from the session object.
     foreach (Session::getHandlers() as $store) {
         $options[] = JHtml::_('select.option', strtolower($store), JText::_('JLIB_FORM_VALUE_SESSION_' . $store), 'value', 'text');
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
 /**
  * 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;
 }
 /**
  * Method to determine a hash for anti-spoofing variable names
  *
  * @param   boolean  $forceNew  If true, force a new token to be created
  *
  * @return  string  Hashed var name
  *
  * @since   1.0
  * @deprecated  2.0  Deprecated without replacement
  */
 public function getFormToken($forceNew = false)
 {
     // @todo we need the user id somehow here
     $userId = 0;
     return md5($this->get('secret') . $userId . $this->session->getToken($forceNew));
 }
 /**
  * Displays a hidden token field to reduce the risk of CSRF exploits
  *
  * Use in conjunction with JSession::checkToken
  *
  * @return  string  A hidden input field with a token
  *
  * @see     JSession::checkToken
  * @since   11.1
  */
 public static function token()
 {
     return '<input type="hidden" name="' . Session::getFormToken() . '" value="1" />';
 }
 /**
  * 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;
 }
Beispiel #8
0
 /**
  * Clears all variables from the session store
  *
  * @return  void
  *
  * @since   1.5
  */
 public function clear()
 {
     // Handle B/C by checking if parameters were passed to this method; if so proxy to the new remove() method, will be removed at 5.0
     if (func_num_args() >= 1) {
         $args = func_get_args();
         if (!empty($args[0])) {
             JLog::add('Using ' . __METHOD__ . '() to remove a single element from the session is deprecated.  Use ' . __CLASS__ . '::remove() instead.', JLog::WARNING, 'deprecated');
             $name = $args[0];
             // Also check for a namespace
             if (func_num_args() > 1 && !empty($args[1])) {
                 JLog::add('Passing a namespace as a parameter to ' . __METHOD__ . '() is deprecated. The namespace should be prepended to the name instead.', JLog::WARNING, 'deprecated');
                 $name = $args[1] . '.' . $name;
             }
             return $this->remove($name);
         }
     }
     return parent::clear();
 }