Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9277bc2

Browse files
committed
[HttpFoundation] MakeSessionHandlerProxy implementSessionIdInterface
1 parent52a9292 commit9277bc2

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Make`HeaderBag::getDate()`,`Response::getDate()`,`getExpires()` and`getLastModified()` return a`DateTimeImmutable`
8+
* Make`SessionHandlerProxy` implement`SessionIdInterface`
89

910
6.3
1011
---
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
namespaceSymfony\Component\HttpFoundation\Exception;
13+
14+
class SessionIdCreationExceptionextends \RuntimeException
15+
{
16+
publicfunction__construct(string$message ='Could not create a session id.',int$code =0,\Throwable$previous =null)
17+
{
18+
parent::__construct($message,$code,$previous);
19+
}
20+
}

‎src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
namespaceSymfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

14+
useSymfony\Component\HttpFoundation\Exception\SessionIdCreationException;
1415
useSymfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
1516

1617
/**
1718
* @author Drak <drak@zikula.org>
1819
*/
19-
class SessionHandlerProxyextends AbstractProxyimplements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
20+
class SessionHandlerProxyextends AbstractProxyimplements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface, \SessionIdInterface
2021
{
2122
protected$handler;
2223

@@ -73,4 +74,17 @@ public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string
7374
{
7475
return$this->handlerinstanceof \SessionUpdateTimestampHandlerInterface ?$this->handler->updateTimestamp($sessionId,$data) :$this->write($sessionId,$data);
7576
}
77+
78+
publicfunctioncreate_sid():string
79+
{
80+
if ($this->handlerinstanceof \SessionIdInterface) {
81+
return$this->handler->create_sid();
82+
}
83+
84+
if (!$id =session_create_id()) {
85+
thrownewSessionIdCreationException();
86+
}
87+
88+
return$id;
89+
}
7690
}

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,25 @@ public static function provideNativeSessionStorageHandler()
179179
[newSessionHandlerProxy(newStrictSessionHandler(new \SessionHandler()))],
180180
];
181181
}
182+
183+
publicfunctiontestCreateSid()
184+
{
185+
$mock =$this->createMock(SessionIdSessionHandler::class);
186+
$mock->expects($this->once())
187+
->method('create_sid');
188+
189+
$proxy =newSessionHandlerProxy($mock);
190+
$proxy->create_sid();
191+
192+
$this->proxy->create_sid();
193+
$this->addToAssertionCount(1);
194+
}
182195
}
183196

184197
abstractclass TestSessionHandlerimplements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
185198
{
186199
}
200+
201+
abstractclass SessionIdSessionHandlerimplements \SessionHandlerInterface, \SessionIdInterface
202+
{
203+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp