public function testConstruct()
 {
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
     if (PHP_VERSION_ID < 50400) {
         $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('files', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
 public function testConstruct()
 {
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
     if (version_compare(phpversion(), '5.4.0', '<')) {
         $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('files', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
 public function getSaveHandler()
 {
     if ( $this->innerSessionStorage instanceof NativeSessionStorage )
     {
         return $this->innerSessionStorage->getSaveHandler();
     }
 }
 public function testSaveHandlers()
 {
     if (!extension_loaded('sqlite')) {
         $this->markTestSkipped('Skipped tests SQLite extension is not present');
     }
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeSqliteSessionHandler(sys_get_temp_dir() . '/sqlite.db'));
     if (version_compare(phpversion(), '5.4.0', '<')) {
         $this->assertEquals('sqlite', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('sqlite', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('sqlite', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals(sys_get_temp_dir() . '/sqlite.db', ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
 public function testSaveHandlers()
 {
     if (!extension_loaded('redis')) {
         $this->markTestSkipped('Skipped tests Redis extension is not present');
     }
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeRedisSessionHandler('tcp://127.0.0.1:6379?persistent=0'));
     if (version_compare(phpversion(), '5.4.0', '<')) {
         $this->assertEquals('redis', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('redis', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('redis', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals('tcp://127.0.0.1:6379?persistent=0', ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
 public function testSaveHandlers()
 {
     if (!extension_loaded('memcached')) {
         $this->markTestSkipped('Skipped tests memcached extension is not present');
     }
     // test takes too long if memcached server is not running
     ini_set('memcached.sess_locking', '0');
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeMemcachedSessionHandler('127.0.0.1:11211'));
     if (version_compare(phpversion(), '5.4.0', '<')) {
         $this->assertEquals('memcached', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('memcached', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('memcached', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals('127.0.0.1:11211', ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
Esempio n. 7
0
 /**
  * Session constructor.
  * @param array|String $options
  * ***********************************************************************************
  * #------------- [options] -------------#
  * List of options for $options array with their defaults.
  *
  * @see http://php.net/session.configuration for options
  * but we omit 'session.' from the beginning of the keys for convenience.
  *
  * ("auto_start", is not supported as it tells PHP to start a session before
  * PHP starts to execute user-land code. Setting during runtime has no effect).
  *
  * cache_limiter, "" (use "0" to prevent headers from being sent entirely).
  * cookie_domain, ""
  * cookie_httponly, ""
  * cookie_lifetime, "0"
  * cookie_path, "/"
  * cookie_secure, ""
  * entropy_file, ""
  * entropy_length, "0"
  * gc_divisor, "100"
  * gc_maxlifetime, "1440"
  * gc_probability, "1"
  * hash_bits_per_character, "4"
  * hash_function, "0"
  * name, "PHPSESSID"
  * referer_check, ""
  * serialize_handler, "php"
  * use_cookies, "1"
  * use_only_cookies, "1"
  * use_trans_sid, "0"
  * upload_progress.enabled, "1"
  * upload_progress.cleanup, "1"
  * upload_progress.prefix, "upload_progress_"
  * upload_progress.name, "PHP_SESSION_UPLOAD_PROGRESS"
  * upload_progress.freq, "1%"
  * upload_progress.min-freq, "1"
  * url_rewriter.tags, "a=href,area=href,frame=src,form=,fieldset="
  *
  *
  * #------------- [handler] -------------#
  * prefix, "sid_"
  * expiretime, 86400
  * ***********************************************************************************
  *
  * @param boolean $createNew Create new session id, destroy old session from cookie and storage.
  * @param null|String $driver
  * @param null|string $driverConfig
  */
 public function __construct($options, $createNew = false, $driver = null, $driverConfig = null)
 {
     is_string($options) && ($options = config($options));
     $options = $options ?: config(env("SESSION_DEFAULT_OPTIONS"));
     if (!$options || !$options['handler'] || !$options['options']) {
         throw new \RuntimeException("Invalid options: " . var_export($options, true));
     }
     $driver = $driver ?: env("SESSION_DRIVER", 'file');
     $driverConfig = $driverConfig ?: env("SESSION_DRIVER_CONFIG");
     $optionsHandler = $options['handler'];
     switch ($driver = strtolower($driver)) {
         case 'redis':
         case 'predis':
         case 'memcache':
         case 'memcached':
         case 'mongodb':
         case 'mongo':
         case 'pdo':
         case 'file':
             $handler = call_user_func_array([$this, "{$driver}SessionHandler"], [$driverConfig, $optionsHandler]);
             break;
         default:
             throw new \RuntimeException("The session driver not support.");
             break;
     }
     $optionsStorage = $options['options'];
     $storage = new NativeSessionStorage($optionsStorage, $handler);
     $attributes = new AttributeBag("_ips_attributes");
     if ($createNew) {
         $session_name = isset($options['options']['name']) ? $options['options']['name'] : "PHPSESSID";
         if (isset($_COOKIE[$session_name])) {
             $old_session_id = $_COOKIE[$session_name];
             $_COOKIE[$session_name] = null;
             @$storage->getSaveHandler()->destroy($old_session_id);
         }
     }
     parent::__construct($storage, $attributes);
 }