[HttpFoundation] Added forward compatibility for \SessionHandlerInterface
This commit is contained in:
parent
d339e74bc5
commit
e585ca783d
@ -20,7 +20,10 @@ $loader->registerPrefixes(array(
|
||||
if (!function_exists('intl_get_error_code')) {
|
||||
require_once __DIR__.'/src/Symfony/Component/Locale/Resources/stubs/functions.php';
|
||||
|
||||
$loader->registerPrefixFallbacks(array(__DIR__.'/src/Symfony/Component/Locale/Resources/stubs'));
|
||||
$loader->registerPrefixFallback(__DIR__.'/src/Symfony/Component/Locale/Resources/stubs');
|
||||
}
|
||||
if (!interface_exists('SessionHandlerInterface', false)) {
|
||||
$loader->registerPrefixFallback(__DIR__.'/src/Symfony/Component/HttpFoundation/Resources/stubs');
|
||||
}
|
||||
$loader->register();
|
||||
|
||||
|
@ -0,0 +1,155 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Session Savehandler Interface.
|
||||
*
|
||||
* This interface is for implementing methods required for the
|
||||
* session_set_save_handler() function.
|
||||
*
|
||||
* @see http://php.net/session_set_save_handler
|
||||
*
|
||||
* These are methods called by PHP when the session is started
|
||||
* and closed and for various house-keeping tasks required
|
||||
* by session management.
|
||||
*
|
||||
* PHP requires session save handlers. There are some defaults set
|
||||
* automatically when PHP starts, but these can be overriden using
|
||||
* this command if you need anything other than PHP's default handling.
|
||||
*
|
||||
* When the session starts, PHP will call the read() handler
|
||||
* which should return a string extactly as stored (which will have
|
||||
* been encoded by PHP using a special session serializer session_decode()
|
||||
* which is different to the serialize() function. PHP will then populate
|
||||
* these into $_SESSION.
|
||||
*
|
||||
* When PHP shuts down, the write() handler is called and will pass
|
||||
* the $_SESSION contents already serialized (using session_encode()) to
|
||||
* be stored.
|
||||
*
|
||||
* When a session is specifically destroyed, PHP will call the
|
||||
* destroy() handler with the session ID. This happens when the
|
||||
* session is regenerated for example and th handler MUST delete the
|
||||
* session by ID from the persistent storage immediately.
|
||||
*
|
||||
* PHP will call gc() from time to time to expire any session
|
||||
* records according to the set max lifetime of a session. This routine
|
||||
* should delete all records from persistent storage which were last
|
||||
* accessed longer than the $lifetime.
|
||||
*
|
||||
* PHP open() and close() are pretty much redundant and
|
||||
* can return true.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
interface SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Open session.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* @param string $savePath Save path.
|
||||
* @param string $sessionName Session Name.
|
||||
*
|
||||
* @throws \RuntimeException If something goes wrong starting the session.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function open($savePath, $sessionName);
|
||||
|
||||
/**
|
||||
* Close session.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function close();
|
||||
|
||||
/**
|
||||
* Read session.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* This method is called by PHP itself when the session is started.
|
||||
* This method should retrieve the session data from storage by the
|
||||
* ID provided by PHP. Return the string directly as is from storage.
|
||||
* If the record was not found you must return an empty string.
|
||||
*
|
||||
* The returned data will be unserialized automatically by PHP using a
|
||||
* special unserializer method session_decode() and the result will be used
|
||||
* to populate the $_SESSION superglobal. This is done automatically and
|
||||
* is not configurable.
|
||||
*
|
||||
* @param string $sessionId Session ID.
|
||||
*
|
||||
* @throws \RuntimeException On fatal error but not "record not found".
|
||||
*
|
||||
* @return string String as stored in persistent storage or empty string in all other cases.
|
||||
*/
|
||||
function read($sessionId);
|
||||
|
||||
/**
|
||||
* Commit session to storage.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* PHP will call this method when the session is closed. It sends
|
||||
* the session ID and the contents of $_SESSION to be saved in a lightweight
|
||||
* serialized format (which PHP does automatically using session_encode()
|
||||
* which should be stored exactly as is given in $data.
|
||||
*
|
||||
* Note this method is normally called by PHP after the output buffers
|
||||
* have been closed.
|
||||
*
|
||||
* @param string $sessionId Session ID.
|
||||
* @param string $data Session serialized data to save.
|
||||
*
|
||||
* @throws \RuntimeException On fatal error.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function write($sessionId, $data);
|
||||
|
||||
/**
|
||||
* Destroys this session.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* PHP will call this method when the session data associated
|
||||
* with the session ID provided needs to be immediately
|
||||
* deleted from the permanent storage.
|
||||
*
|
||||
* @param string $sessionId Session ID.
|
||||
*
|
||||
* @throws \RuntimeException On fatal error.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function destroy($sessionId);
|
||||
|
||||
/**
|
||||
* Garbage collection for storage.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* This method is called by PHP periodically and passes the maximum
|
||||
* time a session can exist for before being deleted from permanent storage.
|
||||
*
|
||||
* @param integer $lifetime Max lifetime in seconds to keep sessions stored.
|
||||
*
|
||||
* @throws \RuntimeException On fatal error.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function gc($lifetime);
|
||||
}
|
@ -13,11 +13,6 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
|
||||
|
||||
// force load forward compatability for PHP 5.4's SessionHandlerInterface if necessary.
|
||||
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||
interface_exists('Symfony\Component\HttpFoundation\Session\Storage\SessionHandlerInterface');
|
||||
}
|
||||
|
||||
/**
|
||||
* This provides a base class for session attribute storage.
|
||||
*
|
||||
@ -283,7 +278,7 @@ abstract class AbstractSessionStorage implements SessionStorageInterface
|
||||
{
|
||||
// note this can be reset to PHP's control using ini_set('session.save_handler', 'files');
|
||||
// so long as ini_set() is called before the session is started.
|
||||
if ($this instanceof \SessionHandlerInterface || $this instanceof SessionHandlerInterface) {
|
||||
if ($this instanceof \SessionHandlerInterface) {
|
||||
session_set_save_handler(
|
||||
array($this, 'open'),
|
||||
array($this, 'close'),
|
||||
|
@ -16,7 +16,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class MemcacheSessionStorage extends AbstractSessionStorage implements SessionHandlerInterface
|
||||
class MemcacheSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Memcache driver.
|
||||
|
@ -16,7 +16,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class MemcachedSessionStorage extends AbstractSessionStorage implements SessionHandlerInterface
|
||||
class MemcachedSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Memcached driver.
|
||||
|
@ -20,7 +20,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class NullSessionStorage extends AbstractSessionStorage implements SessionHandlerInterface
|
||||
class NullSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -17,7 +17,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Michael Williams <michael.williams@funsational.com>
|
||||
*/
|
||||
class PdoSessionStorage extends AbstractSessionStorage implements SessionHandlerInterface
|
||||
class PdoSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* PDO instance.
|
||||
|
@ -1,167 +0,0 @@
|
||||
<?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
|
||||
{
|
||||
if (!interface_exists('SessionHandlerInterface', false)) {
|
||||
/**
|
||||
* Session Savehandler Interface.
|
||||
*
|
||||
* This interface is for implementing methods required for the
|
||||
* session_set_save_handler() function.
|
||||
*
|
||||
* @see http://php.net/session_set_save_handler
|
||||
*
|
||||
* These are methods called by PHP when the session is started
|
||||
* and closed and for various house-keeping tasks required
|
||||
* by session management.
|
||||
*
|
||||
* PHP requires session save handlers. There are some defaults set
|
||||
* automatically when PHP starts, but these can be overriden using
|
||||
* this command if you need anything other than PHP's default handling.
|
||||
*
|
||||
* When the session starts, PHP will call the read() handler
|
||||
* which should return a string extactly as stored (which will have
|
||||
* been encoded by PHP using a special session serializer session_decode()
|
||||
* which is different to the serialize() function. PHP will then populate
|
||||
* these into $_SESSION.
|
||||
*
|
||||
* When PHP shuts down, the write() handler is called and will pass
|
||||
* the $_SESSION contents already serialized (using session_encode()) to
|
||||
* be stored.
|
||||
*
|
||||
* When a session is specifically destroyed, PHP will call the
|
||||
* destroy() handler with the session ID. This happens when the
|
||||
* session is regenerated for example and th handler MUST delete the
|
||||
* session by ID from the persistent storage immediately.
|
||||
*
|
||||
* PHP will call gc() from time to time to expire any session
|
||||
* records according to the set max lifetime of a session. This routine
|
||||
* should delete all records from persistent storage which were last
|
||||
* accessed longer than the $lifetime.
|
||||
*
|
||||
* PHP open() and close() are pretty much redundant and
|
||||
* can return true.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
interface SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Open session.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* @param string $savePath Save path.
|
||||
* @param string $sessionName Session Name.
|
||||
*
|
||||
* @throws \RuntimeException If something goes wrong starting the session.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function open($savePath, $sessionName);
|
||||
|
||||
/**
|
||||
* Close session.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function close();
|
||||
|
||||
/**
|
||||
* Read session.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* This method is called by PHP itself when the session is started.
|
||||
* This method should retrieve the session data from storage by the
|
||||
* ID provided by PHP. Return the string directly as is from storage.
|
||||
* If the record was not found you must return an empty string.
|
||||
*
|
||||
* The returned data will be unserialized automatically by PHP using a
|
||||
* special unserializer method session_decode() and the result will be used
|
||||
* to populate the $_SESSION superglobal. This is done automatically and
|
||||
* is not configurable.
|
||||
*
|
||||
* @param string $sessionId Session ID.
|
||||
*
|
||||
* @throws \RuntimeException On fatal error but not "record not found".
|
||||
*
|
||||
* @return string String as stored in persistent storage or empty string in all other cases.
|
||||
*/
|
||||
function read($sessionId);
|
||||
|
||||
/**
|
||||
* Commit session to storage.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* PHP will call this method when the session is closed. It sends
|
||||
* the session ID and the contents of $_SESSION to be saved in a lightweight
|
||||
* serialized format (which PHP does automatically using session_encode()
|
||||
* which should be stored exactly as is given in $data.
|
||||
*
|
||||
* Note this method is normally called by PHP after the output buffers
|
||||
* have been closed.
|
||||
*
|
||||
* @param string $sessionId Session ID.
|
||||
* @param string $data Session serialized data to save.
|
||||
*
|
||||
* @throws \RuntimeException On fatal error.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function write($sessionId, $data);
|
||||
|
||||
/**
|
||||
* Destroys this session.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* PHP will call this method when the session data associated
|
||||
* with the session ID provided needs to be immediately
|
||||
* deleted from the permanent storage.
|
||||
*
|
||||
* @param string $sessionId Session ID.
|
||||
*
|
||||
* @throws \RuntimeException On fatal error.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function destroy($sessionId);
|
||||
|
||||
/**
|
||||
* Garbage collection for storage.
|
||||
*
|
||||
* This method is for internal use by PHP and must not be called manually.
|
||||
*
|
||||
* This method is called by PHP periodically and passes the maximum
|
||||
* time a session can exist for before being deleted from permanent storage.
|
||||
*
|
||||
* @param integer $lifetime Max lifetime in seconds to keep sessions stored.
|
||||
*
|
||||
* @throws \RuntimeException On fatal error.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function gc($lifetime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage
|
||||
{
|
||||
interface SessionHandlerInterface extends \SessionHandlerInterface
|
||||
{
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionHandlerInterface;
|
||||
|
||||
/**
|
||||
* Turn AbstractSessionStorage into something concrete because
|
||||
@ -16,7 +15,7 @@ class ConcreteSessionStorage extends AbstractSessionStorage
|
||||
{
|
||||
}
|
||||
|
||||
class CustomHandlerSessionStorage extends AbstractSessionStorage implements SessionHandlerInterface
|
||||
class CustomHandlerSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
||||
{
|
||||
public function open($path, $id)
|
||||
{
|
||||
|
Reference in New Issue
Block a user