Skip to content

Commit ad066bb

Browse files
bug symfony#27747 [HttpFoundation] fix registration of session proxies (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [HttpFoundation] fix registration of session proxies | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#27674 | License | MIT | Doc PR | - Commits ------- 5ed40c0 [HttpFoundation] fix registration of session proxies
2 parents af00528 + 5ed40c0 commit ad066bb

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ public function setSaveHandler($saveHandler = null)
411411
}
412412

413413
if ($this->saveHandler instanceof SessionHandlerProxy) {
414-
session_set_save_handler($this->saveHandler->getHandler(), false);
415-
} elseif ($this->saveHandler instanceof \SessionHandlerInterface) {
416414
session_set_save_handler($this->saveHandler, false);
417415
}
418416
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @author Drak <drak@zikula.org>
1616
*/
17-
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
17+
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
1818
{
1919
protected $handler;
2020

@@ -82,4 +82,20 @@ public function gc($maxlifetime)
8282
{
8383
return (bool) $this->handler->gc($maxlifetime);
8484
}
85+
86+
/**
87+
* {@inheritdoc}
88+
*/
89+
public function validateId($sessionId)
90+
{
91+
return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
92+
}
93+
94+
/**
95+
* {@inheritdoc}
96+
*/
97+
public function updateTimestamp($sessionId, $data)
98+
{
99+
return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data);
100+
}
85101
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,37 @@ public function testGc()
121121

122122
$this->proxy->gc(86400);
123123
}
124+
125+
/**
126+
* @requires PHPUnit 5.1
127+
*/
128+
public function testValidateId()
129+
{
130+
$mock = $this->getMockBuilder(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
131+
$mock->expects($this->once())
132+
->method('validateId');
133+
134+
$proxy = new SessionHandlerProxy($mock);
135+
$proxy->validateId('id');
136+
137+
$this->assertTrue($this->proxy->validateId('id'));
138+
}
139+
140+
/**
141+
* @requires PHPUnit 5.1
142+
*/
143+
public function testUpdateTimestamp()
144+
{
145+
$mock = $this->getMockBuilder(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
146+
$mock->expects($this->once())
147+
->method('updateTimestamp');
148+
149+
$proxy = new SessionHandlerProxy($mock);
150+
$proxy->updateTimestamp('id', 'data');
151+
152+
$this->mock->expects($this->once())
153+
->method('write');
154+
155+
$this->proxy->updateTimestamp('id', 'data');
156+
}
124157
}

0 commit comments

Comments
 (0)