Exemple #1
0
 /**
  * After the session has been started we need to populate it with some default values.
  *
  * @param   SessionEvent  $event  Session event being triggered
  *
  * @return  void
  *
  * @since   4.0
  */
 public function afterSessionStart(SessionEvent $event)
 {
     $session = $event->getSession();
     if ($session->isNew()) {
         $session->set('registry', new Registry('session'));
     }
 }
Exemple #2
0
 /**
  * After the session has been started we need to populate it with some default values.
  *
  * @param   SessionEvent  $event  Session event being triggered
  *
  * @return  void
  *
  * @since   3.2
  */
 public function afterSessionStart(SessionEvent $event)
 {
     $session = $event->getSession();
     if ($session->isNew()) {
         $session->set('registry', new Registry('session'));
         $session->set('user', new JUser());
     }
     // TODO: At some point we need to get away from having session data always in the db.
     $db = JFactory::getDbo();
     $time = time();
     // Get the session handler from the configuration.
     $handler = $this->get('session_handler', 'none');
     // Purge expired session data if not using the database handler; the handler will run garbage collection as a native part of PHP's API
     if ($handler != 'database' && $time % 2) {
         // The modulus introduces a little entropy, making the flushing less accurate but fires the query less than half the time.
         try {
             $db->setQuery($db->getQuery(true)->delete($db->quoteName('#__session'))->where($db->quoteName('time') . ' < ' . $db->quote((int) ($time - $session->getExpire()))))->execute();
         } catch (RuntimeException $e) {
             /*
              * The database API logs errors on failures so we don't need to add any error handling mechanisms here.
              * Since garbage collection does not result in a fatal error when run in the session API, we don't allow it here either.
              */
         }
     }
     /*
      * Check for extra session metadata when:
      *
      * 1) The database handler is in use and the session is new
      * 2) The database handler is not in use and the time is an even numbered second or the session is new
      */
     if ($handler != 'database' && ($time % 2 || $session->isNew()) || $handler == 'database' && $session->isNew()) {
         $this->checkSession();
     }
 }