Debian Codegraph @

lib/3rdParty/composer/symfony/http-foundation/Session/Storage/Handler/MigratingSessionHandler.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 * Migrating session handler for migrating from one handler to another. It reads
16 * from the current handler and writes both the current and new ones.
17 *
18 * It ignores errors from the new handler.
19 *
20 * @author Ross Motley <[email protected]>
21 * @author Oliver Radwell <[email protected]>
22 */
23 class MigratingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
24 {
25 private \SessionHandlerInterface&\SessionUpdateTimestampHandlerInterface $currentHandler;
26 private \SessionHandlerInterface&\SessionUpdateTimestampHandlerInterface $writeOnlyHandler;
27
28 public function __construct(\SessionHandlerInterface $currentHandler, \SessionHandlerInterface $writeOnlyHandler)
29 {
30 if (!$currentHandler instanceof \SessionUpdateTimestampHandlerInterface) {
31 $currentHandler = new StrictSessionHandler($currentHandler);
32 }
33 if (!$writeOnlyHandler instanceof \SessionUpdateTimestampHandlerInterface) {
34 $writeOnlyHandler = new StrictSessionHandler($writeOnlyHandler);
35 }
36
37 $this->currentHandler = $currentHandler;
38 $this->writeOnlyHandler = $writeOnlyHandler;
39 }
40
41 public function close(): bool
42 {
43 $result = $this->currentHandler->close();
44 $this->writeOnlyHandler->close();
45
46 return $result;
47 }
48
49 public function destroy(#[\SensitiveParameter] string $sessionId): bool
50 {
51 $result = $this->currentHandler->destroy($sessionId);
52 $this->writeOnlyHandler->destroy($sessionId);
53
54 return $result;
55 }
56
57 public function gc(int $maxlifetime): int|false
58 {
59 $result = $this->currentHandler->gc($maxlifetime);
60 $this->writeOnlyHandler->gc($maxlifetime);
61
62 return $result;
63 }
64
65 public function open(string $savePath, string $sessionName): bool
66 {
67 $result = $this->currentHandler->open($savePath, $sessionName);
68 $this->writeOnlyHandler->open($savePath, $sessionName);
69
70 return $result;
71 }
72
73 public function read(#[\SensitiveParameter] string $sessionId): string
74 {
75 // No reading from new handler until switch-over
76 return $this->currentHandler->read($sessionId);
77 }
78
79 public function write(#[\SensitiveParameter] string $sessionId, string $sessionData): bool
80 {
81 $result = $this->currentHandler->write($sessionId, $sessionData);
82 $this->writeOnlyHandler->write($sessionId, $sessionData);
83
84 return $result;
85 }
86
87 public function validateId(#[\SensitiveParameter] string $sessionId): bool
88 {
89 // No reading from new handler until switch-over
90 return $this->currentHandler->validateId($sessionId);
91 }
92
93 public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string $sessionData): bool
94 {
95 $result = $this->currentHandler->updateTimestamp($sessionId, $sessionData);
96 $this->writeOnlyHandler->updateTimestamp($sessionId, $sessionData);
97
98 return $result;
99 }
100 }