| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 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 |
|
| 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 |
|
| 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 |
} |