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

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  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 <[email protected]>
  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.     public function open(string $savePathstring $sessionName): bool
  28.     {
  29.         parent::open($savePath$sessionName);
  30.         return $this->handler->open($savePath$sessionName);
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     protected function doRead(string $sessionId): string
  36.     {
  37.         return $this->handler->read($sessionId);
  38.     }
  39.     public function updateTimestamp(string $sessionIdstring $data): bool
  40.     {
  41.         return $this->write($sessionId$data);
  42.     }
  43.     /**
  44.      * {@inheritdoc}
  45.      */
  46.     protected function doWrite(string $sessionIdstring $data): bool
  47.     {
  48.         return $this->handler->write($sessionId$data);
  49.     }
  50.     public function destroy(string $sessionId): bool
  51.     {
  52.         $this->doDestroy true;
  53.         $destroyed parent::destroy($sessionId);
  54.         return $this->doDestroy $this->doDestroy($sessionId) : $destroyed;
  55.     }
  56.     /**
  57.      * {@inheritdoc}
  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. }