fix:更新已知bug,优化代码
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user