public function testRegisterSetsSessionSaveHandlerAndIniSettings()
 {
     ini_set('session.gc_probability', '0');
     $handler = SessionHandler::factory(array('dynamodb_client' => $this->getMockedClient(), 'automatic_gc' => true));
     $this->assertTrue($handler->register());
     $this->assertEquals('1', ini_get('session.gc_probability'));
     ini_set('session.gc_probability', '0');
 }
 public function register(Application $app)
 {
     parent::register($app);
     /** @noinspection PhpParamsInspection */
     $app['session.storage.handler'] = $app->share(function ($app) {
         $config = $app['session.dynamodb.options'];
         if (!array_key_exists('dynamodb_client', $config)) {
             $config['dynamodb_client'] = $this->getDynamoDbClient($app['aws']);
         }
         return SessionHandler::factory($config);
     });
     $app['session.dynamodb.options'] = array();
 }
Exemple #3
0
 public function __construct()
 {
     $bucket = Config::get('storage.bucket', 'default');
     $key = Config::get('storage.key');
     $secret = Config::get('storage.secret');
     $client = DynamoDbClient::factory(array('key' => $key, 'secret' => $secret, 'region' => '<region name>'));
     $config = new SessionHandlerConfig(array('table_name' => 'sessions'));
     // Make sure locking strategy has been provided or provide a default
     $factory = new LockingStrategyFactory();
     $strategy = $factory->factory($strategy, $config);
     // Return an instance of the session handler
     parent::__construct($client, $strategy, $config);
 }
 public function __construct()
 {
     $aws = Configure::read('Session.handler.aws');
     $dynamoDB = $aws->get('dynamodb');
     $config = array('dynamodb_client' => $dynamoDB, 'session_lifetime' => Configure::read('Session.timeout') * 60, 'table_name' => DynamoDBSession::DEFAULT_TABLE_NAME, 'locking_strategy' => 'pessimistic');
     if (Configure::check('Session.handler.table_name')) {
         $config['table_name'] = Configure::read('Session.handler.table_name');
     }
     if (Configure::check('Session.handler.locking_strategy')) {
         $config['locking_strategy'] = Configure::read('Session.handler.locking_strategy');
     }
     $this->_sessionHandler = SessionHandler::factory($config);
     if (Configure::check('Session.handler.session_name')) {
         $this->_sessionName = Configure::read('Session.handler.session_name');
     }
 }
Exemple #5
0
 /**
  * Convenience method for instantiating and registering the DynamoDB
  * Session handler with this DynamoDB client object.
  *
  * @param array $config Array of options for the session handler factory
  *
  * @return SessionHandler
  */
 public function registerSessionHandler(array $config = array())
 {
     $config = array_replace(array('dynamodb_client' => $this), $config);
     $handler = SessionHandler::factory($config);
     $handler->register();
     return $handler;
 }
 /**
  * Garbage collect the configured DynamoDB session table
  */
 public function collect()
 {
     return $this->handler->garbageCollect();
 }
 protected function simulateSessionDestroy(SessionHandler $handler)
 {
     $handler->destroy('example');
     $handler->close();
 }
        $connexionString = "mysql:host=" . $config->db->mysql->host . ";dbname=" . $config->db->mysql->database;
        if ($config->db->mysql->logged) {
            $db = new LoggedPDO($connexionString, $config->db->mysql->user, $config->db->mysql->password, $pdo_options);
        } else {
            $db = new PDO($connexionString, $config->db->mysql->user, $config->db->mysql->password, $pdo_options);
        }
        $db->exec("SET time_zone='" . $offset . "';");
    } catch (Exception $e) {
        die("Erreur : " . $e->getMessage());
    }
    return $db;
}
function connect_dynamoDB($config)
{
    $client = DynamoDbClient::factory(array('key' => $config->aws->key, 'secret' => $config->aws->secret, 'region' => $config->aws->region));
    return $client;
}
if ($config->db->dynamoSessions) {
    require_once dirname(__FILE__) . '/../ext/autoload.php';
    $dynamoDB = connect_dynamoDB($config);
    // registering the dynamodb session handler performs some useless operations
    // in session!
    if (!isset($noSessions) || !$noSessions) {
        $sessionHandler = SessionHandler::factory(array('dynamodb_client' => $dynamoDB, 'table_name' => 'sessions', 'locking_strategy' => 'pessimistic', 'consistent_read' => true));
        $sessionHandler->register();
    }
}
if ($config->db->use != "dynamoDB" || !isset($noSQL) || !$noSQL) {
    // mysql is almost always used
    $db = connect_pdo($config);
}
 /**
  * Write session data
  * @link http://php.net/manual/en/sessionhandlerinterafce.write.php
  * @param string $session_id
  * @param string $session_data
  * @return bool
  */
 public function write($session_id, $session_data)
 {
     return $this->handler->write($session_id, $session_data);
 }