Skip to content

Commit

Permalink
bug #27747 [HttpFoundation] fix registration of session proxies (nico…
Browse files Browse the repository at this point in the history
…las-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 | #27674
| License       | MIT
| Doc PR        | -

Commits
-------

5ed40c0 [HttpFoundation] fix registration of session proxies
  • Loading branch information
nicolas-grekas committed Jun 28, 2018
2 parents af00528 + 5ed40c0 commit ad066bb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Expand Up @@ -411,8 +411,6 @@ public function setSaveHandler($saveHandler = null)
}

if ($this->saveHandler instanceof SessionHandlerProxy) {
session_set_save_handler($this->saveHandler->getHandler(), false);
} elseif ($this->saveHandler instanceof \SessionHandlerInterface) {
session_set_save_handler($this->saveHandler, false);
}
}
Expand Down
Expand Up @@ -14,7 +14,7 @@
/**
* @author Drak <drak@zikula.org>
*/
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
{
protected $handler;

Expand Down Expand Up @@ -82,4 +82,20 @@ public function gc($maxlifetime)
{
return (bool) $this->handler->gc($maxlifetime);
}

/**
* {@inheritdoc}
*/
public function validateId($sessionId)
{
return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
}

/**
* {@inheritdoc}
*/
public function updateTimestamp($sessionId, $data)
{
return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data);
}
}
Expand Up @@ -121,4 +121,37 @@ public function testGc()

$this->proxy->gc(86400);
}

/**
* @requires PHPUnit 5.1
*/
public function testValidateId()
{
$mock = $this->getMockBuilder(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
$mock->expects($this->once())
->method('validateId');

$proxy = new SessionHandlerProxy($mock);
$proxy->validateId('id');

$this->assertTrue($this->proxy->validateId('id'));
}

/**
* @requires PHPUnit 5.1
*/
public function testUpdateTimestamp()
{
$mock = $this->getMockBuilder(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
$mock->expects($this->once())
->method('updateTimestamp');

$proxy = new SessionHandlerProxy($mock);
$proxy->updateTimestamp('id', 'data');

$this->mock->expects($this->once())
->method('write');

$this->proxy->updateTimestamp('id', 'data');
}
}

0 comments on commit ad066bb

Please sign in to comment.