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

@@ -24,14 +24,14 @@ class MemcachedSessionHandler extends AbstractSessionHandler
private $memcached;
/**
* @var int Time to live in seconds
* Time to live in seconds.
*/
private $ttl;
private ?int $ttl;
/**
* @var string Key prefix for shared environments
* Key prefix for shared environments.
*/
private $prefix;
private string $prefix;
/**
* Constructor.
@@ -54,11 +54,7 @@ class MemcachedSessionHandler extends AbstractSessionHandler
$this->prefix = $options['prefix'] ?? 'sf2s';
}
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
public function close(): bool
{
return $this->memcached->quit();
}
@@ -66,16 +62,12 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead(string $sessionId)
protected function doRead(string $sessionId): string
{
return $this->memcached->get($this->prefix.$sessionId) ?: '';
}
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
public function updateTimestamp(string $sessionId, string $data): bool
{
$this->memcached->touch($this->prefix.$sessionId, time() + (int) ($this->ttl ?? \ini_get('session.gc_maxlifetime')));
@@ -85,7 +77,7 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite(string $sessionId, string $data)
protected function doWrite(string $sessionId, string $data): bool
{
return $this->memcached->set($this->prefix.$sessionId, $data, time() + (int) ($this->ttl ?? \ini_get('session.gc_maxlifetime')));
}
@@ -93,18 +85,14 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy(string $sessionId)
protected function doDestroy(string $sessionId): bool
{
$result = $this->memcached->delete($this->prefix.$sessionId);
return $result || \Memcached::RES_NOTFOUND == $this->memcached->getResultCode();
}
/**
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
public function gc(int $maxlifetime): int|false
{
// not required here because memcached will auto expire the records anyhow.
return 0;
@@ -112,10 +100,8 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* Return a Memcached instance.
*
* @return \Memcached
*/
protected function getMemcached()
protected function getMemcached(): \Memcached
{
return $this->memcached;
}