Debian Codegraph @

lib/3rdParty/composer/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php

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