package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -21,17 +21,17 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
*/
class MemcachedSessionHandler extends AbstractSessionHandler
{
private $memcached;
private \Memcached $memcached;
/**
* @var int Time to live in seconds
* Time to live in seconds.
*/
private $ttl;
private int|\Closure|null $ttl;
/**
* @var string Key prefix for shared environments
* Key prefix for shared environments.
*/
private $prefix;
private string $prefix;
/**
* Constructor.
@@ -54,45 +54,31 @@ class MemcachedSessionHandler extends AbstractSessionHandler
$this->prefix = $options['prefix'] ?? 'sf2s';
}
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
public function close(): bool
{
return $this->memcached->quit();
}
/**
* {@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, $this->getCompatibleTtl());
return true;
}
/**
* {@inheritdoc}
*/
protected function doWrite(string $sessionId, string $data)
protected function doWrite(string $sessionId, string $data): bool
{
return $this->memcached->set($this->prefix.$sessionId, $data, $this->getCompatibleTtl());
}
private function getCompatibleTtl(): int
{
$ttl = (int) ($this->ttl ?? \ini_get('session.gc_maxlifetime'));
$ttl = ($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime');
// If the relative TTL that is used exceeds 30 days, memcached will treat the value as Unix time.
// We have to convert it to an absolute Unix time at this point, to make sure the TTL is correct.
@@ -103,21 +89,14 @@ class MemcachedSessionHandler extends AbstractSessionHandler
return $ttl;
}
/**
* {@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;
@@ -125,10 +104,8 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* Return a Memcached instance.
*
* @return \Memcached
*/
protected function getMemcached()
protected function getMemcached(): \Memcached
{
return $this->memcached;
}