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 4253566

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

File tree

4 files changed

+143
-0
lines changed
Filter options

4 files changed

+143
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* added max-items + LRU + max-lifetime capabilities to `ArrayCache`
88
* added `CouchbaseBucketAdapter`
9+
* added `IdentityMarshaller`
910

1011
5.0.0
1112
-----
+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 \RuntimeException(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)
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
@@ -23,6 +23,7 @@ CHANGELOG
2323
* made `Request::getSession()` throw if the session has not been set before
2424
* removed `Response::HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL`
2525
* passing a null url when instantiating a `RedirectResponse` is not allowed
26+
* added `MarshallingSessionHandler`
2627

2728
4.4.0
2829
-----
+101Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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\IdentityMarshaller;
15+
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
16+
17+
/**
18+
* @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
19+
*/
20+
class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
21+
{
22+
private $handler;
23+
private $marshaller;
24+
25+
public function __construct(AbstractSessionHandler $handler, MarshallerInterface $marshaller = null)
26+
{
27+
$this->handler = $handler;
28+
$this->marshaller = $marshaller ?? new IdentityMarshaller();
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function close()
35+
{
36+
return $this->handler->close();
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function destroy($sessionId)
43+
{
44+
return $this->handler->destroy($sessionId);
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function gc($maxlifetime)
51+
{
52+
return $this->handler->gc($maxlifetime);
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function open($savePath, $name)
59+
{
60+
return $this->handler->open($savePath, $name);
61+
}
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function read($sessionId)
67+
{
68+
return $this->marshaller->unmarshall($this->handler->read($sessionId));
69+
}
70+
71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public function write($sessionId, $data)
75+
{
76+
$failed = [];
77+
$marshalledData = $this->marshaller->marshall(['data' => $data], $failed);
78+
79+
if (!isset($failed['data'])) {
80+
$data = $marshalledData['data'];
81+
}
82+
83+
return $this->handler->write($sessionId, $data);
84+
}
85+
86+
/**
87+
* {@inheritdoc}
88+
*/
89+
public function validateId($sessionId)
90+
{
91+
return $this->handler->validateId($sessionId);
92+
}
93+
94+
/**
95+
* {@inheritdoc}
96+
*/
97+
public function updateTimestamp($sessionId, $data)
98+
{
99+
return $this->handler->updateTimestamp($sessionId, $data);
100+
}
101+
}

0 commit comments

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