| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
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 |
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
|
|
|
18 |
*/
|
|
|
19 |
class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
|
|
|
20 |
{
|
|
|
21 |
private AbstractSessionHandler $handler;
|
|
|
22 |
private MarshallerInterface $marshaller;
|
|
|
23 |
|
|
|
24 |
public function __construct(AbstractSessionHandler $handler, MarshallerInterface $marshaller)
|
|
|
25 |
{
|
|
|
26 |
$this->handler = $handler;
|
|
|
27 |
$this->marshaller = $marshaller;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public function open(string $savePath, string $name): bool
|
|
|
31 |
{
|
|
|
32 |
return $this->handler->open($savePath, $name);
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public function close(): bool
|
|
|
36 |
{
|
|
|
37 |
return $this->handler->close();
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function destroy(string $sessionId): bool
|
|
|
41 |
{
|
|
|
42 |
return $this->handler->destroy($sessionId);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public function gc(int $maxlifetime): int|false
|
|
|
46 |
{
|
|
|
47 |
return $this->handler->gc($maxlifetime);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public function read(string $sessionId): string
|
|
|
51 |
{
|
|
|
52 |
return $this->marshaller->unmarshall($this->handler->read($sessionId));
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public function write(string $sessionId, string $data): bool
|
|
|
56 |
{
|
|
|
57 |
$failed = [];
|
|
|
58 |
$marshalledData = $this->marshaller->marshall(['data' => $data], $failed);
|
|
|
59 |
|
|
|
60 |
if (isset($failed['data'])) {
|
|
|
61 |
return false;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
return $this->handler->write($sessionId, $marshalledData['data']);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public function validateId(string $sessionId): bool
|
|
|
68 |
{
|
|
|
69 |
return $this->handler->validateId($sessionId);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
public function updateTimestamp(string $sessionId, string $data): bool
|
|
|
73 |
{
|
|
|
74 |
return $this->handler->updateTimestamp($sessionId, $data);
|
|
|
75 |
}
|
|
|
76 |
}
|