upgraded dependencies
This commit is contained in:
@@ -11,6 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
use MongoDB\BSON\Binary;
|
||||
use MongoDB\BSON\UTCDateTime;
|
||||
use MongoDB\Client;
|
||||
use MongoDB\Collection;
|
||||
|
||||
/**
|
||||
* Session handler using the mongodb/mongodb package and MongoDB driver extension.
|
||||
*
|
||||
@@ -24,7 +29,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
private $mongo;
|
||||
|
||||
/**
|
||||
* @var \MongoDB\Collection
|
||||
* @var Collection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
@@ -63,7 +68,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
*
|
||||
* @throws \InvalidArgumentException When "database" or "collection" not provided
|
||||
*/
|
||||
public function __construct(\MongoDB\Client $mongo, array $options)
|
||||
public function __construct(Client $mongo, array $options)
|
||||
{
|
||||
if (!isset($options['database']) || !isset($options['collection'])) {
|
||||
throw new \InvalidArgumentException('You must provide the "database" and "collection" option for MongoDBSessionHandler.');
|
||||
@@ -91,7 +96,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDestroy($sessionId)
|
||||
protected function doDestroy(string $sessionId)
|
||||
{
|
||||
$this->getCollection()->deleteOne([
|
||||
$this->options['id_field'] => $sessionId,
|
||||
@@ -107,21 +112,21 @@ class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
public function gc($maxlifetime)
|
||||
{
|
||||
return $this->getCollection()->deleteMany([
|
||||
$this->options['expiry_field'] => ['$lt' => new \MongoDB\BSON\UTCDateTime()],
|
||||
$this->options['expiry_field'] => ['$lt' => new UTCDateTime()],
|
||||
])->getDeletedCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWrite($sessionId, $data)
|
||||
protected function doWrite(string $sessionId, string $data)
|
||||
{
|
||||
$expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) \ini_get('session.gc_maxlifetime')) * 1000);
|
||||
$expiry = new UTCDateTime((time() + (int) \ini_get('session.gc_maxlifetime')) * 1000);
|
||||
|
||||
$fields = [
|
||||
$this->options['time_field'] => new \MongoDB\BSON\UTCDateTime(),
|
||||
$this->options['time_field'] => new UTCDateTime(),
|
||||
$this->options['expiry_field'] => $expiry,
|
||||
$this->options['data_field'] => new \MongoDB\BSON\Binary($data, \MongoDB\BSON\Binary::TYPE_OLD_BINARY),
|
||||
$this->options['data_field'] => new Binary($data, Binary::TYPE_OLD_BINARY),
|
||||
];
|
||||
|
||||
$this->getCollection()->updateOne(
|
||||
@@ -139,12 +144,12 @@ class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
#[\ReturnTypeWillChange]
|
||||
public function updateTimestamp($sessionId, $data)
|
||||
{
|
||||
$expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) \ini_get('session.gc_maxlifetime')) * 1000);
|
||||
$expiry = new UTCDateTime((time() + (int) \ini_get('session.gc_maxlifetime')) * 1000);
|
||||
|
||||
$this->getCollection()->updateOne(
|
||||
[$this->options['id_field'] => $sessionId],
|
||||
['$set' => [
|
||||
$this->options['time_field'] => new \MongoDB\BSON\UTCDateTime(),
|
||||
$this->options['time_field'] => new UTCDateTime(),
|
||||
$this->options['expiry_field'] => $expiry,
|
||||
]]
|
||||
);
|
||||
@@ -155,11 +160,11 @@ class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doRead($sessionId)
|
||||
protected function doRead(string $sessionId)
|
||||
{
|
||||
$dbData = $this->getCollection()->findOne([
|
||||
$this->options['id_field'] => $sessionId,
|
||||
$this->options['expiry_field'] => ['$gte' => new \MongoDB\BSON\UTCDateTime()],
|
||||
$this->options['expiry_field'] => ['$gte' => new UTCDateTime()],
|
||||
]);
|
||||
|
||||
if (null === $dbData) {
|
||||
@@ -169,7 +174,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
return $dbData[$this->options['data_field']]->getData();
|
||||
}
|
||||
|
||||
private function getCollection(): \MongoDB\Collection
|
||||
private function getCollection(): Collection
|
||||
{
|
||||
if (null === $this->collection) {
|
||||
$this->collection = $this->mongo->selectCollection($this->options['database'], $this->options['collection']);
|
||||
@@ -179,7 +184,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MongoDB\Client
|
||||
* @return Client
|
||||
*/
|
||||
protected function getMongo()
|
||||
{
|
||||
|
Reference in New Issue
Block a user