public function testAddDefaultsPerformsMergeProperly() { $config = new SessionHandlerConfig(array('dynamodb_client' => $this->getMockedClient())); $this->assertNull($config->get('foo_bar')); $config->addDefaults(array('foo_bar' => 'baz')); $this->assertEquals('baz', $config->get('foo_bar')); $config->addDefaults(array('foo_bar' => 'CHANGED')); $this->assertEquals('baz', $config->get('foo_bar')); }
/** * Creates a session handler locking strategy * * @param string $lockingStrategy The name if the locking strategy * @param SessionHandlerConfig $config The session handler config data * * @return LockingStrategyInterface * * @throws InvalidArgumentException If the locking strategy doesn't exist */ public function factory($lockingStrategy = null, SessionHandlerConfig $config) { // If the locking strategy is null, let's give it the name "null" if ($lockingStrategy === null) { $lockingStrategy = 'null'; } // Make sure the locking strategy name provided is a string if (!is_string($lockingStrategy)) { throw new InvalidArgumentException('The session locking strategy ' . 'name must be provided as a string.'); } // Determine the class name of the locking strategy class $classPath = $this->baseNamespace . '\\' . $this->inflector->camel($lockingStrategy) . 'LockingStrategy'; // Make sure the locking strategy class exists if (!class_exists($classPath)) { throw new InvalidArgumentException("There is no session locking " . "strategy named \"{$classPath}\"."); } // Call the factory on the locking strategy class to create it return new $classPath($config->get('dynamodb_client'), $config); }
/** * Factory method to create a new DynamoDB Session Handler * * The configuration array accepts the following array keys and values: * - locking_strategy: Locking strategy fused for doing session locking. Default: null * - dynamodb_client: DynamoDbClient object used for performing DynamoDB operations * - table_name: Name of the DynamoDB table in which to store the sessions. Default: "sessions" * - hash_key: Name of the hash key in the DynamoDB sessions table. Default: "id" * - session_lifetime: Lifetime of an inactive session before it should be garbage collected. * - consistent_read: Whether or not to use DynamoDB consistent reads for `GetItem`. Default: true * - automatic_gc: Whether or not to use PHP's session auto garbage collection triggers. * - gc_batch_size: Batch size used for removing expired sessions during garbage collection. Default: 25 * - gc_operation_delay: Delay between service operations during garbage collection * - max_lock_wait_time: Maximum time (in seconds) to wait to acquire a lock before giving up * - min_lock_retry_microtime: Minimum time (in microseconds) to wait between attempts to acquire a lock * - max_lock_retry_microtime: Maximum time (in microseconds) to wait between attempts to acquire a lock * * @param array $config Configuration options * * @return SessionHandler */ public static function factory(array $config = array()) { // Setup session handler configuration and get the client $config = new SessionHandlerConfig($config); $client = $config->get('dynamodb_client'); // Make sure locking strategy has been provided or provide a default $strategy = $config->get('locking_strategy'); if (!$strategy instanceof LockingStrategyInterface) { $factory = new LockingStrategyFactory(); $strategy = $factory->factory($strategy, $config); } // Return an instance of the session handler return new static($client, $strategy, $config); }