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); }
/** * @dataProvider getFactoryTestCases */ public function testFactoryWorksCorrectly($strategyName, $class) { // Setup mocks $config = $this->getMockedConfig(); $client = $this->getMockedClient(); $config->expects($this->any())->method('get')->will($this->returnCallback(function ($key) use($client) { return $key === 'dynamodb_client' ? $client : null; })); $factory = new LockingStrategyFactory('Aws\\DynamoDb\\Session\\LockingStrategy'); try { $strategy = $factory->factory($strategyName, $config); } catch (\Aws\Common\Exception\InvalidArgumentException $e) { $strategy = $e; } $this->assertInstanceOf($class, $strategy); }
/** * 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); }