fix:更新已知bug,优化代码

This commit is contained in:
Ying
2022-11-28 19:11:12 +08:00
parent f6aee95cfc
commit 9445b206a2
1378 changed files with 53759 additions and 20789 deletions

View File

@@ -27,16 +27,8 @@ use MongoDB\Collection;
class MongoDbSessionHandler extends AbstractSessionHandler
{
private $mongo;
/**
* @var Collection
*/
private $collection;
/**
* @var array
*/
private $options;
private array $options;
/**
* Constructor.
@@ -84,11 +76,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
], $options);
}
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
public function close(): bool
{
return true;
}
@@ -96,7 +84,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy(string $sessionId)
protected function doDestroy(string $sessionId): bool
{
$this->getCollection()->deleteOne([
$this->options['id_field'] => $sessionId,
@@ -105,11 +93,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
return true;
}
/**
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
public function gc(int $maxlifetime): int|false
{
return $this->getCollection()->deleteMany([
$this->options['expiry_field'] => ['$lt' => new UTCDateTime()],
@@ -119,7 +103,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite(string $sessionId, string $data)
protected function doWrite(string $sessionId, string $data): bool
{
$expiry = new UTCDateTime((time() + (int) \ini_get('session.gc_maxlifetime')) * 1000);
@@ -138,11 +122,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
return true;
}
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
public function updateTimestamp(string $sessionId, string $data): bool
{
$expiry = new UTCDateTime((time() + (int) \ini_get('session.gc_maxlifetime')) * 1000);
@@ -160,7 +140,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead(string $sessionId)
protected function doRead(string $sessionId): string
{
$dbData = $this->getCollection()->findOne([
$this->options['id_field'] => $sessionId,
@@ -176,17 +156,10 @@ class MongoDbSessionHandler extends AbstractSessionHandler
private function getCollection(): Collection
{
if (null === $this->collection) {
$this->collection = $this->mongo->selectCollection($this->options['database'], $this->options['collection']);
}
return $this->collection;
return $this->collection ??= $this->mongo->selectCollection($this->options['database'], $this->options['collection']);
}
/**
* @return Client
*/
protected function getMongo()
protected function getMongo(): Client
{
return $this->mongo;
}