/** * @param ContainerInterface $container * @param string $requestedName * @param array|null $options * @return DynamoDbSaveHandler */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $config = $container->get('Config'); if (!isset($config['aws_zf2']['session']['save_handler']['dynamodb'])) { throw new ServiceNotCreatedException('ZF2 AWS PHP SDK configuration is missing a "dynamodb" key. ' . 'Have you copied "config/aws_zf2.local.php.dist" into your ' . 'project (without the .dist extension)?'); } /** @var AwsSdk $awsSdk */ $awsSdk = $container->get(AwsSdk::class); $saveHandlerConfig = $config['aws_zf2']['session']['save_handler']['dynamodb']; $sessionHandler = SessionHandler::fromClient($awsSdk->createDynamoDb(), $saveHandlerConfig); return new DynamoDbSaveHandler($sessionHandler); }
/** * 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 = []) { $handler = SessionHandler::fromClient($this, $config); $handler->register(); return $handler; }
/** * Trigger garbage collection on expired sessions * * Part of the standard PHP session handler interface * * @param int $maxlifetime The value of `session.gc_maxlifetime`. Ignored. * * @return bool Whether or not the operation succeeded */ public function gc($maxlifetime) { return $this->sessionHandler->gc($maxlifetime); }
/** * @param \Aws\DynamoDb\DynamoDbClient $client * @param $config array */ public function __construct(DynamoDbClient $client, array $config) { $this->client = $client; $config['dynamodb_client'] = $client; $this->handler = \Aws\DynamoDb\SessionHandler::fromClient($client, $config); }
public function testSessionHandlerGcIsCalled() { $this->sessionHandler->expects($this->once())->method('gc')->with($this->equalTo(420))->will($this->returnValue(true)); $result = $this->saveHandler->gc(420); $this->assertTrue($result); }
/** * Garbage collect the configured DynamoDB session table */ public function collect() { return $this->handler->garbageCollect(); }
$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('credentials' => array('key' => $config->aws->key, 'secret' => $config->aws->secret), 'region' => $config->aws->region, 'version' => '2012-08-10')); return $client; } if ($config->db->dynamoSessions) { require_once dirname(__FILE__) . '/../vendor/autoload.php'; $dynamoDB = connect_dynamoDB($config); // registering the dynamodb session handler performs some useless operations // in session! if (!isset($noSessions) || !$noSessions) { $sessionHandler = SessionHandler::fromClient($dynamoDB, array('table_name' => $config->db->dynamoDBPrefix . 'sessions')); $sessionHandler->register(); } } if ($config->db->use != "dynamoDB" || !isset($noSQL) || !$noSQL) { // mysql is almost always used $db = connect_pdo($config); }