Files
swiftadmin/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php

99 lines
2.5 KiB
PHP
Raw Normal View History

2022-08-19 19:48:37 +08:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
/**
* Adds basic `SessionUpdateTimestampHandlerInterface` behaviors to another `SessionHandlerInterface`.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class StrictSessionHandler extends AbstractSessionHandler
{
2022-11-28 19:11:12 +08:00
private \SessionHandlerInterface $handler;
private bool $doDestroy;
2022-08-19 19:48:37 +08:00
public function __construct(\SessionHandlerInterface $handler)
{
if ($handler instanceof \SessionUpdateTimestampHandlerInterface) {
throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', get_debug_type($handler), self::class));
}
$this->handler = $handler;
}
/**
2022-11-28 19:11:12 +08:00
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
*
* @internal
2022-08-19 19:48:37 +08:00
*/
2022-11-28 19:11:12 +08:00
public function isWrapper(): bool
{
return $this->handler instanceof \SessionHandler;
}
public function open(string $savePath, string $sessionName): bool
2022-08-19 19:48:37 +08:00
{
parent::open($savePath, $sessionName);
return $this->handler->open($savePath, $sessionName);
}
/**
* {@inheritdoc}
*/
2022-11-28 19:11:12 +08:00
protected function doRead(string $sessionId): string
2022-08-19 19:48:37 +08:00
{
return $this->handler->read($sessionId);
}
2022-11-28 19:11:12 +08:00
public function updateTimestamp(string $sessionId, string $data): bool
2022-08-19 19:48:37 +08:00
{
return $this->write($sessionId, $data);
}
/**
* {@inheritdoc}
*/
2022-11-28 19:11:12 +08:00
protected function doWrite(string $sessionId, string $data): bool
2022-08-19 19:48:37 +08:00
{
return $this->handler->write($sessionId, $data);
}
2022-11-28 19:11:12 +08:00
public function destroy(string $sessionId): bool
2022-08-19 19:48:37 +08:00
{
$this->doDestroy = true;
$destroyed = parent::destroy($sessionId);
return $this->doDestroy ? $this->doDestroy($sessionId) : $destroyed;
}
/**
* {@inheritdoc}
*/
2022-11-28 19:11:12 +08:00
protected function doDestroy(string $sessionId): bool
2022-08-19 19:48:37 +08:00
{
$this->doDestroy = false;
return $this->handler->destroy($sessionId);
}
2022-11-28 19:11:12 +08:00
public function close(): bool
2022-08-19 19:48:37 +08:00
{
return $this->handler->close();
}
2022-11-28 19:11:12 +08:00
public function gc(int $maxlifetime): int|false
2022-08-19 19:48:37 +08:00
{
return $this->handler->gc($maxlifetime);
}
}