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

Commitb56606e

Browse files
committed
Provide migration path for TestSessionListener
1 parentcfb1016 commitb56606e

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

‎UPGRADE-5.4.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ FrameworkBundle
55
---------------
66

77
* Deprecate the`AdapterInterface` autowiring alias, use`CacheItemPoolInterface` instead
8+
9+
HttpKernel
10+
----------
11+
12+
* Deprecate`AbstractTestSessionListener::getSession` inject a session in the request instead

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/test.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
->set('test.session.listener', TestSessionListener::class)
3939
->args([
4040
service_locator([
41-
'session_factory' =>service('session.factory')->ignoreOnInvalid(),
4241
'session' =>service('.session.do-not-use')->ignoreOnInvalid(),
4342
]),
4443
])

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.4
5+
---
6+
7+
* Deprecate`AbstractTestSessionListener::getSession` inject a session in the request instead
8+
49
5.3
510
---
611

‎src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public function onKernelRequest(RequestEvent $event)
4646
}
4747

4848
// bootstrap the session
49-
if (!$session =$this->getSession()) {
49+
if ($event->getRequest()->hasSession()) {
50+
$session =$event->getRequest()->getSession();
51+
}elseif (!$session =$this->getSession()) {
5052
return;
5153
}
5254

@@ -100,14 +102,16 @@ public function onKernelResponse(ResponseEvent $event)
100102
publicstaticfunctiongetSubscribedEvents():array
101103
{
102104
return [
103-
KernelEvents::REQUEST => ['onKernelRequest',192],
105+
KernelEvents::REQUEST => ['onKernelRequest',127],// AFTER SessionListener
104106
KernelEvents::RESPONSE => ['onKernelResponse', -128],
105107
];
106108
}
107109

108110
/**
109111
* Gets the session object.
110112
*
113+
* @deprecated since Symfony 5.4, will be removed in 6.0.
114+
*
111115
* @return SessionInterface|null A SessionInterface instance or null if no session is available
112116
*/
113117
abstractprotectedfunctiongetSession();

‎src/Symfony/Component/HttpKernel/EventListener/TestSessionListener.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ public function __construct(ContainerInterface $container, array $sessionOptions
3131
parent::__construct($sessionOptions);
3232
}
3333

34+
/**
35+
* @deprecated since Symfony 5.4, will be removed in 6.0.
36+
*/
3437
protectedfunctiongetSession(): ?SessionInterface
3538
{
39+
trigger_deprecation('symfony/http-kernel','5.4','"%s" is deprecated and will be removed in 6.0, inject a session in the request instead.',__METHOD__);
40+
3641
if ($this->container->has('session')) {
3742
return$this->container->get('session');
3843
}
3944

40-
if ($this->container->has('session_factory')) {
41-
return$this->container->get('session_factory')->createSession();
42-
}
43-
4445
returnnull;
4546
}
4647
}

‎src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
useSymfony\Component\HttpKernel\Event\RequestEvent;
2020
useSymfony\Component\HttpKernel\Event\ResponseEvent;
2121
useSymfony\Component\HttpKernel\EventListener\AbstractTestSessionListener;
22-
useSymfony\Component\HttpKernel\EventListener\SessionListener;
2322
useSymfony\Component\HttpKernel\EventListener\TestSessionListener;
2423
useSymfony\Component\HttpKernel\HttpKernelInterface;
2524

@@ -99,6 +98,7 @@ public function testEmptySessionWithNewSessionIdDoesSendCookie()
9998

10099
$kernel =$this->createMock(HttpKernelInterface::class);
101100
$request = Request::create('/','GET', [], ['MOCKSESSID' =>'123']);
101+
$request->setSession($this->getSession());
102102
$event =newRequestEvent($kernel,$request, HttpKernelInterface::MAIN_REQUEST);
103103
$this->listener->onKernelRequest($event);
104104

@@ -118,6 +118,7 @@ public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie(
118118

119119
$kernel =$this->createMock(HttpKernelInterface::class);
120120
$request = Request::create('/','GET', [], ['MOCKSESSID' =>'123']);
121+
$request->setSession($this->getSession());
121122
$event =newRequestEvent($kernel,$request, HttpKernelInterface::MAIN_REQUEST);
122123
$this->listener->onKernelRequest($event);
123124

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp