[HttpFoundation] Prepare to split out session handler callback from session storage.
This commit is contained in:
parent
e01106f2b3
commit
bb30a447c5
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* Adds SessionHandler functionality if available.
|
||||
*
|
||||
* @see http://php.net/sessionhandler
|
||||
*/
|
||||
|
||||
if (version_compare(phpversion(), '5.4.0', '>=')) {
|
||||
class NativeSessionHandler extends \SessionHandler {}
|
||||
} else {
|
||||
class NativeSessionHandler {}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
|
||||
|
||||
/**
|
||||
* AbstractProxy.
|
||||
*/
|
||||
abstract class AbstractProxy
|
||||
{
|
||||
/**
|
||||
* Flag if handler wraps an internal PHP session handler (using \SessionHandler).
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $wrapper = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $active = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $saveHandlerName;
|
||||
|
||||
/**
|
||||
* Gets the session.save_handler name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSaveHandlerName()
|
||||
{
|
||||
return $this->saveHandlerName;
|
||||
}
|
||||
|
||||
public function isSessionHandlerInterface()
|
||||
{
|
||||
return (bool)($this instanceof \SessionHandlerInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isWrapper()
|
||||
{
|
||||
return $this->wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has a session started?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive()
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the active flag.
|
||||
*
|
||||
* @param bool $flag
|
||||
*/
|
||||
public function setActive($flag)
|
||||
{
|
||||
$this->active = (bool)$flag;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
|
||||
|
||||
/**
|
||||
* NativeProxy.
|
||||
*
|
||||
* This proxy is built-in session handlers in PHP 5.3.x
|
||||
*/
|
||||
class NativeProxy extends AbstractProxy
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param $handler
|
||||
*/
|
||||
public function __construct($handler)
|
||||
{
|
||||
if (version_compare(phpversion(), '5.4.0', '>=') && $handler instanceof \SessionHandlerInterface) {
|
||||
throw new \InvalidArgumentException('This proxy is only for PHP 5.3 and not for instances of \SessionHandler or \SessionHandlerInterface');
|
||||
}
|
||||
|
||||
$this->handler = $handler;
|
||||
$this->saveHandlerName = ini_get('session.save_handler');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
|
||||
*
|
||||
* @return bool False.
|
||||
*/
|
||||
public function isWrapper()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
|
||||
|
||||
/**
|
||||
* SessionHandler proxy.
|
||||
*/
|
||||
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var \SessionHandlerInterface
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \SessionHandlerInterface $handler
|
||||
*/
|
||||
public function __construct(\SessionHandlerInterface $handler)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
$this->wrapper = (bool)(class_exists('SessionHandler') && $handler instanceof \SessionHandler);
|
||||
$this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user';
|
||||
}
|
||||
|
||||
// \SessionHandlerInterface
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function open($savePath, $sessionName)
|
||||
{
|
||||
$return = (bool)$this->handler->open($savePath, $sessionName);
|
||||
|
||||
if (true === $return) {
|
||||
$this->active = true;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
$this->active = false;
|
||||
|
||||
return (bool)$this->handler->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function read($id)
|
||||
{
|
||||
return (string)$this->handler->read($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function write($id, $data)
|
||||
{
|
||||
return (bool)$this->handler->write($id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function destroy($id)
|
||||
{
|
||||
return (bool)$this->handler->destroy($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function gc($maxlifetime)
|
||||
{
|
||||
return (bool)$this->handler->gc($maxlifetime);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user