vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php line 87

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
  11. /**
  12.  * Adds basic `SessionUpdateTimestampHandlerInterface` behaviors to another `SessionHandlerInterface`.
  13.  *
  14.  * @author Nicolas Grekas <p@tchwork.com>
  15.  */
  16. class StrictSessionHandler extends AbstractSessionHandler
  17. {
  18.     private \SessionHandlerInterface $handler;
  19.     private bool $doDestroy;
  20.     public function __construct(\SessionHandlerInterface $handler)
  21.     {
  22.         if ($handler instanceof \SessionUpdateTimestampHandlerInterface) {
  23.             throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".'get_debug_type($handler), self::class));
  24.         }
  25.         $this->handler $handler;
  26.     }
  27.     /**
  28.      * Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
  29.      *
  30.      * @internal
  31.      */
  32.     public function isWrapper(): bool
  33.     {
  34.         return $this->handler instanceof \SessionHandler;
  35.     }
  36.     public function open(string $savePathstring $sessionName): bool
  37.     {
  38.         parent::open($savePath$sessionName);
  39.         return $this->handler->open($savePath$sessionName);
  40.     }
  41.     protected function doRead(string $sessionId): string
  42.     {
  43.         return $this->handler->read($sessionId);
  44.     }
  45.     public function updateTimestamp(string $sessionIdstring $data): bool
  46.     {
  47.         return $this->write($sessionId$data);
  48.     }
  49.     protected function doWrite(string $sessionIdstring $data): bool
  50.     {
  51.         return $this->handler->write($sessionId$data);
  52.     }
  53.     public function destroy(string $sessionId): bool
  54.     {
  55.         $this->doDestroy true;
  56.         $destroyed parent::destroy($sessionId);
  57.         return $this->doDestroy $this->doDestroy($sessionId) : $destroyed;
  58.     }
  59.     protected function doDestroy(string $sessionId): bool
  60.     {
  61.         $this->doDestroy false;
  62.         return $this->handler->destroy($sessionId);
  63.     }
  64.     public function close(): bool
  65.     {
  66.         return $this->handler->close();
  67.     }
  68.     public function gc(int $maxlifetime): int|false
  69.     {
  70.         return $this->handler->gc($maxlifetime);
  71.     }
  72. }