Skip to content

Commit a8e5f8d

Browse files
Merge branch '3.4' into 4.0
* 3.4: [HttpFoundation] fix registration of session proxies failing test to reproduce session problem [HttpFoundation] fix session tracking counter
2 parents 58cda54 + 0a9f3b2 commit a8e5f8d

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

Session/Session.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public function __construct(SessionStorageInterface $storage = null, AttributeBa
5454
*/
5555
public function start()
5656
{
57-
++$this->usageIndex;
58-
5957
return $this->storage->start();
6058
}
6159

@@ -160,7 +158,9 @@ public function getUsageIndex()
160158
*/
161159
public function isEmpty()
162160
{
163-
++$this->usageIndex;
161+
if ($this->isStarted()) {
162+
++$this->usageIndex;
163+
}
164164
foreach ($this->data as &$data) {
165165
if (!empty($data)) {
166166
return false;
@@ -185,8 +185,6 @@ public function invalidate($lifetime = null)
185185
*/
186186
public function migrate($destroy = false, $lifetime = null)
187187
{
188-
++$this->usageIndex;
189-
190188
return $this->storage->regenerate($destroy, $lifetime);
191189
}
192190

@@ -195,8 +193,6 @@ public function migrate($destroy = false, $lifetime = null)
195193
*/
196194
public function save()
197195
{
198-
++$this->usageIndex;
199-
200196
$this->storage->save();
201197
}
202198

Session/SessionBagProxy.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function getBag()
4444
*/
4545
public function isEmpty()
4646
{
47+
if (!isset($this->data[$this->bag->getStorageKey()])) {
48+
return true;
49+
}
4750
++$this->usageIndex;
4851

4952
return empty($this->data[$this->bag->getStorageKey()]);
@@ -81,8 +84,6 @@ public function getStorageKey()
8184
*/
8285
public function clear()
8386
{
84-
++$this->usageIndex;
85-
8687
return $this->bag->clear();
8788
}
8889
}

Session/Storage/NativeSessionStorage.php

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

409409
if ($this->saveHandler instanceof SessionHandlerProxy) {
410-
session_set_save_handler($this->saveHandler->getHandler(), false);
411-
} elseif ($this->saveHandler instanceof \SessionHandlerInterface) {
412410
session_set_save_handler($this->saveHandler, false);
413411
}
414412
}

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
}

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)