Example #1
0
 protected function _getSessionHandler()
 {
     if (isset($this->_config['storage']) && $this->_config['storage']) {
         $handlerClass = $this->_config['storage'];
         unset($this->_config['handler']);
         $storage = new $handlerClass($this->_config);
         session_set_save_handler(array(&$storage, 'open'), array(&$storage, 'close'), array(&$storage, 'read'), array(&$storage, 'write'), array(&$storage, 'destroy'), array(&$storage, 'gc'));
         self::$_storage = $storage;
     }
 }
 /**
  * initConfig
  * @param $config
  */
 public function __construct($config = array())
 {
     // Load config
     if (empty($config)) {
         ConfigHandler::get('session');
         // Read config from session key in config file
     }
     $this->_config = array_merge($this->_config, $config);
     if (isset($this->_config['storage']) && $this->_config['storage']) {
         $handlerClass = $this->_config['storage'];
         unset($this->_config['handler']);
         $storage = new $handlerClass($this->_config);
         session_set_save_handler(array(&$storage, 'open'), array(&$storage, 'close'), array(&$storage, 'read'), array(&$storage, 'write'), array(&$storage, 'destroy'), array(&$storage, 'gc'));
         self::$_storage = $storage;
     }
     if (isset($this->_config['name'])) {
         session_name($this->_config['name']);
     }
     ini_set('session.gc_maxlifetime', $this->_config['lifetime']);
     //define the lifetime of the cookie
     if (isset($this->_config['cookie_ttl']) || isset($this->_config['cookie_domain']) || isset($this->_config['cookie_path'])) {
         // cross subdomain validity is default behavior
         $ttl = isset($this->_config['cookie_ttl']) ? (int) $this->_config['cookie_ttl'] : 0;
         $domain = isset($this->_config['cookie_domain']) ? $this->_config['cookie_domain'] : '.' . Factory::getRouter()->getDomain();
         $path = isset($this->_config['cookie_path']) ? '/' . trim($this->_config['cookie_path'], '/') . '/' : '/';
         session_set_cookie_params($ttl, $path, $domain);
     } else {
         $cookie = session_get_cookie_params();
         session_set_cookie_params($cookie['lifetime'], $cookie['path'], $cookie['domain']);
     }
     if (Base::getApp()) {
         if (Factory::getRequest()->isSecure()) {
             ini_set('session.cookie_secure', true);
         }
     }
     ini_set('session.use_only_cookies', 1);
     if (isset($handlerClass)) {
         $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => $handlerClass)));
     } else {
         $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => 'default')));
     }
 }