Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c75755

Browse filesBrowse files
committed
[HttpFoundation][Cache] Added MarshallingSessionHandler
1 parent cde44fc commit 3c75755
Copy full SHA for 3c75755

File tree

3 files changed

+141
-0
lines changed
Filter options

3 files changed

+141
-0
lines changed
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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\Cache\Marshaller;
13+
14+
/**
15+
* @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
16+
*/
17+
class IdentityMarshaller implements MarshallerInterface
18+
{
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
public function marshall(array $values, ?array &$failed): array
23+
{
24+
foreach ($values as $key => $value) {
25+
if (!\is_string($value)) {
26+
throw new \LogicException(sprintf('%s accepts only string as data.', __METHOD__));
27+
}
28+
}
29+
30+
return $values;
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function unmarshall(string $value): string
37+
{
38+
return $value;
39+
}
40+
}

‎src/Symfony/Component/HttpFoundation/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
* added `Request::preferSafeContent()` and `Response::setContentSafe()` to handle "safe" HTTP preference
1414
according to [RFC 8674](https://tools.ietf.org/html/rfc8674)
1515
* made the Mime component an optional dependency
16+
* added `MarshallingSessionHandler`, `IdentityMarshaller`
1617

1718
5.0.0
1819
-----
+100Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 $handler;
22+
private $marshaller;
23+
24+
public function __construct(AbstractSessionHandler $handler, MarshallerInterface $marshaller)
25+
{
26+
$this->handler = $handler;
27+
$this->marshaller = $marshaller;
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function close()
34+
{
35+
return $this->handler->close();
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function destroy($sessionId)
42+
{
43+
return $this->handler->destroy($sessionId);
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function gc($maxlifetime)
50+
{
51+
return $this->handler->gc($maxlifetime);
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function open($savePath, $name)
58+
{
59+
return $this->handler->open($savePath, $name);
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
public function read($sessionId)
66+
{
67+
return $this->marshaller->unmarshall($this->handler->read($sessionId));
68+
}
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
public function write($sessionId, $data)
74+
{
75+
$failed = [];
76+
$marshalledData = $this->marshaller->marshall(['data' => $data], $failed);
77+
78+
if (!isset($failed['data'])) {
79+
$data = $marshalledData['data'];
80+
}
81+
82+
return $this->handler->write($sessionId, $data);
83+
}
84+
85+
/**
86+
* {@inheritdoc}
87+
*/
88+
public function validateId($sessionId)
89+
{
90+
return $this->handler->validateId($sessionId);
91+
}
92+
93+
/**
94+
* {@inheritdoc}
95+
*/
96+
public function updateTimestamp($sessionId, $data)
97+
{
98+
return $this->handler->updateTimestamp($sessionId, $data);
99+
}
100+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.