Skip to content

Commit

Permalink
Merge pull request #11969 from cakephp/issue-11895-instance
Browse files Browse the repository at this point in the history
Replace the session engine when an instance is provided.
  • Loading branch information
markstory committed Apr 19, 2018
2 parents 7bc858b + 047903c commit 56b9b24
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Http/Session.php
Expand Up @@ -248,13 +248,12 @@ public function __construct(array $config = [])
*/
public function engine($class = null, array $options = [])
{
if ($class instanceof SessionHandlerInterface) {
return $this->_engine = $class;
}

if ($class === null) {
return $this->_engine;
}
if ($class instanceof SessionHandlerInterface) {
return $this->setEngine($class);
}
$className = App::className($class, 'Http/Session');

if (!$className) {
Expand All @@ -273,6 +272,18 @@ public function engine($class = null, array $options = [])
'The chosen SessionHandler does not implement SessionHandlerInterface, it cannot be used as an engine.'
);
}

return $this->setEngine($handler);
}

/**
* Set the engine property and update the session handler in PHP.
*
* @param \SessionHandlerInterface $handler The handler to set
* @return \SessionHandlerInterface
*/
protected function setEngine(SessionHandlerInterface $handler)
{
if (!headers_sent()) {
session_set_save_handler($handler, false);
}
Expand Down

0 comments on commit 56b9b24

Please sign in to comment.