Laravel version update
Laravel version update
This commit is contained in:
@@ -17,20 +17,11 @@ namespace Symfony\Component\HttpFoundation\Session\Attribute;
|
||||
class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Countable
|
||||
{
|
||||
private $name = 'attributes';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $storageKey;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $storageKey The key used to store attributes in the session
|
||||
*/
|
||||
public function __construct($storageKey = '_sf2_attributes')
|
||||
@@ -152,6 +143,6 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->attributes);
|
||||
return \count($this->attributes);
|
||||
}
|
||||
}
|
||||
|
@@ -19,16 +19,9 @@ namespace Symfony\Component\HttpFoundation\Session\Attribute;
|
||||
*/
|
||||
class NamespacedAttributeBag extends AttributeBag
|
||||
{
|
||||
/**
|
||||
* Namespace character.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $namespaceCharacter;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $storageKey Session storage key
|
||||
* @param string $namespaceCharacter Namespace character to use in keys
|
||||
*/
|
||||
@@ -109,7 +102,7 @@ class NamespacedAttributeBag extends AttributeBag
|
||||
protected function &resolveAttributePath($name, $writeContext = false)
|
||||
{
|
||||
$array = &$this->attributes;
|
||||
$name = (strpos($name, $this->namespaceCharacter) === 0) ? substr($name, 1) : $name;
|
||||
$name = (0 === strpos($name, $this->namespaceCharacter)) ? substr($name, 1) : $name;
|
||||
|
||||
// Check if there is anything to do, else return
|
||||
if (!$name) {
|
||||
@@ -117,7 +110,7 @@ class NamespacedAttributeBag extends AttributeBag
|
||||
}
|
||||
|
||||
$parts = explode($this->namespaceCharacter, $name);
|
||||
if (count($parts) < 2) {
|
||||
if (\count($parts) < 2) {
|
||||
if (!$writeContext) {
|
||||
return $array;
|
||||
}
|
||||
@@ -127,11 +120,17 @@ class NamespacedAttributeBag extends AttributeBag
|
||||
return $array;
|
||||
}
|
||||
|
||||
unset($parts[count($parts) - 1]);
|
||||
unset($parts[\count($parts) - 1]);
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (null !== $array && !array_key_exists($part, $array)) {
|
||||
$array[$part] = $writeContext ? array() : null;
|
||||
if (!$writeContext) {
|
||||
$null = null;
|
||||
|
||||
return $null;
|
||||
}
|
||||
|
||||
$array[$part] = array();
|
||||
}
|
||||
|
||||
$array = &$array[$part];
|
||||
|
@@ -19,27 +19,13 @@ namespace Symfony\Component\HttpFoundation\Session\Flash;
|
||||
class AutoExpireFlashBag implements FlashBagInterface
|
||||
{
|
||||
private $name = 'flashes';
|
||||
|
||||
/**
|
||||
* Flash messages.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $flashes = array('display' => array(), 'new' => array());
|
||||
|
||||
/**
|
||||
* The storage key for flashes in the session.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $storageKey;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $storageKey The key used to store flashes in the session
|
||||
*/
|
||||
public function __construct($storageKey = '_sf2_flashes')
|
||||
public function __construct($storageKey = '_symfony_flashes')
|
||||
{
|
||||
$this->storageKey = $storageKey;
|
||||
}
|
||||
@@ -120,7 +106,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
public function all()
|
||||
{
|
||||
$return = $this->flashes['display'];
|
||||
$this->flashes = array('new' => array(), 'display' => array());
|
||||
$this->flashes['display'] = array();
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@@ -19,27 +19,13 @@ namespace Symfony\Component\HttpFoundation\Session\Flash;
|
||||
class FlashBag implements FlashBagInterface
|
||||
{
|
||||
private $name = 'flashes';
|
||||
|
||||
/**
|
||||
* Flash messages.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $flashes = array();
|
||||
|
||||
/**
|
||||
* The storage key for flashes in the session.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $storageKey;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $storageKey The key used to store flashes in the session
|
||||
*/
|
||||
public function __construct($storageKey = '_sf2_flashes')
|
||||
public function __construct($storageKey = '_symfony_flashes')
|
||||
{
|
||||
$this->storageKey = $storageKey;
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ interface FlashBagInterface extends SessionBagInterface
|
||||
* Adds a flash message for type.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $message
|
||||
* @param mixed $message
|
||||
*/
|
||||
public function add($type, $message);
|
||||
|
||||
|
@@ -11,41 +11,27 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
|
||||
|
||||
/**
|
||||
* Session.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
{
|
||||
/**
|
||||
* Storage driver.
|
||||
*
|
||||
* @var SessionStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $flashName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $attributeName;
|
||||
private $data = array();
|
||||
private $usageIndex = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param SessionStorageInterface $storage A SessionStorageInterface instance
|
||||
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
|
||||
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
|
||||
@@ -76,7 +62,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
return $this->storage->getBag($this->attributeName)->has($name);
|
||||
return $this->getAttributeBag()->has($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +70,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
return $this->storage->getBag($this->attributeName)->get($name, $default);
|
||||
return $this->getAttributeBag()->get($name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +78,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
$this->storage->getBag($this->attributeName)->set($name, $value);
|
||||
$this->getAttributeBag()->set($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +86,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->storage->getBag($this->attributeName)->all();
|
||||
return $this->getAttributeBag()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +94,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function replace(array $attributes)
|
||||
{
|
||||
$this->storage->getBag($this->attributeName)->replace($attributes);
|
||||
$this->getAttributeBag()->replace($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +102,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
return $this->storage->getBag($this->attributeName)->remove($name);
|
||||
return $this->getAttributeBag()->remove($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +110,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->storage->getBag($this->attributeName)->clear();
|
||||
$this->getAttributeBag()->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +128,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->storage->getBag($this->attributeName)->all());
|
||||
return new \ArrayIterator($this->getAttributeBag()->all());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +138,36 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->storage->getBag($this->attributeName)->all());
|
||||
return \count($this->getAttributeBag()->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getUsageIndex()
|
||||
{
|
||||
return $this->usageIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
if ($this->isStarted()) {
|
||||
++$this->usageIndex;
|
||||
}
|
||||
foreach ($this->data as &$data) {
|
||||
if (!empty($data)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,6 +233,8 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function getMetadataBag()
|
||||
{
|
||||
++$this->usageIndex;
|
||||
|
||||
return $this->storage->getMetadataBag();
|
||||
}
|
||||
|
||||
@@ -226,7 +243,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag)
|
||||
{
|
||||
$this->storage->registerBag($bag);
|
||||
$this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->usageIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +251,7 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function getBag($name)
|
||||
{
|
||||
return $this->storage->getBag($name);
|
||||
return $this->storage->getBag($name)->getBag();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,4 +263,16 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
{
|
||||
return $this->getBag($this->flashName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attributebag interface.
|
||||
*
|
||||
* Note that this method was added to help with IDE autocompletion.
|
||||
*
|
||||
* @return AttributeBagInterface
|
||||
*/
|
||||
private function getAttributeBag()
|
||||
{
|
||||
return $this->getBag($this->attributeName);
|
||||
}
|
||||
}
|
||||
|
@@ -27,8 +27,6 @@ interface SessionBagInterface
|
||||
|
||||
/**
|
||||
* Initializes the Bag.
|
||||
*
|
||||
* @param array $array
|
||||
*/
|
||||
public function initialize(array &$array);
|
||||
|
||||
|
89
vendor/symfony/http-foundation/Session/SessionBagProxy.php
vendored
Normal file
89
vendor/symfony/http-foundation/Session/SessionBagProxy.php
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class SessionBagProxy implements SessionBagInterface
|
||||
{
|
||||
private $bag;
|
||||
private $data;
|
||||
private $usageIndex;
|
||||
|
||||
public function __construct(SessionBagInterface $bag, array &$data, &$usageIndex)
|
||||
{
|
||||
$this->bag = $bag;
|
||||
$this->data = &$data;
|
||||
$this->usageIndex = &$usageIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SessionBagInterface
|
||||
*/
|
||||
public function getBag()
|
||||
{
|
||||
++$this->usageIndex;
|
||||
|
||||
return $this->bag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
if (!isset($this->data[$this->bag->getStorageKey()])) {
|
||||
return true;
|
||||
}
|
||||
++$this->usageIndex;
|
||||
|
||||
return empty($this->data[$this->bag->getStorageKey()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->bag->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initialize(array &$array)
|
||||
{
|
||||
++$this->usageIndex;
|
||||
$this->data[$this->bag->getStorageKey()] = &$array;
|
||||
|
||||
$this->bag->initialize($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStorageKey()
|
||||
{
|
||||
return $this->bag->getStorageKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
return $this->bag->clear();
|
||||
}
|
||||
}
|
@@ -25,7 +25,7 @@ interface SessionInterface
|
||||
*
|
||||
* @return bool True if session started
|
||||
*
|
||||
* @throws \RuntimeException If session fails to start.
|
||||
* @throws \RuntimeException if session fails to start
|
||||
*/
|
||||
public function start();
|
||||
|
||||
@@ -159,8 +159,6 @@ interface SessionInterface
|
||||
|
||||
/**
|
||||
* Registers a SessionBagInterface with the session.
|
||||
*
|
||||
* @param SessionBagInterface $bag
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag);
|
||||
|
||||
|
168
vendor/symfony/http-foundation/Session/Storage/Handler/AbstractSessionHandler.php
vendored
Normal file
168
vendor/symfony/http-foundation/Session/Storage/Handler/AbstractSessionHandler.php
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* This abstract session handler provides a generic implementation
|
||||
* of the PHP 7.0 SessionUpdateTimestampHandlerInterface,
|
||||
* enabling strict and lazy session handling.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
abstract class AbstractSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
|
||||
{
|
||||
private $sessionName;
|
||||
private $prefetchId;
|
||||
private $prefetchData;
|
||||
private $newSessionId;
|
||||
private $igbinaryEmptyData;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
$this->sessionName = $sessionName;
|
||||
if (!headers_sent() && !ini_get('session.cache_limiter') && '0' !== ini_get('session.cache_limiter')) {
|
||||
header(sprintf('Cache-Control: max-age=%d, private, must-revalidate', 60 * (int) ini_get('session.cache_expire')));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sessionId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function doRead($sessionId);
|
||||
|
||||
/**
|
||||
* @param string $sessionId
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function doWrite($sessionId, $data);
|
||||
|
||||
/**
|
||||
* @param string $sessionId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function doDestroy($sessionId);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateId($sessionId)
|
||||
{
|
||||
$this->prefetchData = $this->read($sessionId);
|
||||
$this->prefetchId = $sessionId;
|
||||
|
||||
return '' !== $this->prefetchData;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
{
|
||||
if (null !== $this->prefetchId) {
|
||||
$prefetchId = $this->prefetchId;
|
||||
$prefetchData = $this->prefetchData;
|
||||
$this->prefetchId = $this->prefetchData = null;
|
||||
|
||||
if ($prefetchId === $sessionId || '' === $prefetchData) {
|
||||
$this->newSessionId = '' === $prefetchData ? $sessionId : null;
|
||||
|
||||
return $prefetchData;
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->doRead($sessionId);
|
||||
$this->newSessionId = '' === $data ? $sessionId : null;
|
||||
if (\PHP_VERSION_ID < 70000) {
|
||||
$this->prefetchData = $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
{
|
||||
if (\PHP_VERSION_ID < 70000 && $this->prefetchData) {
|
||||
$readData = $this->prefetchData;
|
||||
$this->prefetchData = null;
|
||||
|
||||
if ($readData === $data) {
|
||||
return $this->updateTimestamp($sessionId, $data);
|
||||
}
|
||||
}
|
||||
if (null === $this->igbinaryEmptyData) {
|
||||
// see https://github.com/igbinary/igbinary/issues/146
|
||||
$this->igbinaryEmptyData = \function_exists('igbinary_serialize') ? igbinary_serialize(array()) : '';
|
||||
}
|
||||
if ('' === $data || $this->igbinaryEmptyData === $data) {
|
||||
return $this->destroy($sessionId);
|
||||
}
|
||||
$this->newSessionId = null;
|
||||
|
||||
return $this->doWrite($sessionId, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
if (\PHP_VERSION_ID < 70000) {
|
||||
$this->prefetchData = null;
|
||||
}
|
||||
if (!headers_sent() && ini_get('session.use_cookies')) {
|
||||
if (!$this->sessionName) {
|
||||
throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', \get_class($this)));
|
||||
}
|
||||
$sessionCookie = sprintf(' %s=', urlencode($this->sessionName));
|
||||
$sessionCookieWithId = sprintf('%s%s;', $sessionCookie, urlencode($sessionId));
|
||||
$sessionCookieFound = false;
|
||||
$otherCookies = array();
|
||||
foreach (headers_list() as $h) {
|
||||
if (0 !== stripos($h, 'Set-Cookie:')) {
|
||||
continue;
|
||||
}
|
||||
if (11 === strpos($h, $sessionCookie, 11)) {
|
||||
$sessionCookieFound = true;
|
||||
|
||||
if (11 !== strpos($h, $sessionCookieWithId, 11)) {
|
||||
$otherCookies[] = $h;
|
||||
}
|
||||
} else {
|
||||
$otherCookies[] = $h;
|
||||
}
|
||||
}
|
||||
if ($sessionCookieFound) {
|
||||
header_remove('Set-Cookie');
|
||||
foreach ($otherCookies as $h) {
|
||||
header($h, false);
|
||||
}
|
||||
} else {
|
||||
setcookie($this->sessionName, '', 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->newSessionId === $sessionId || $this->doDestroy($sessionId);
|
||||
}
|
||||
}
|
@@ -11,16 +11,15 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
@trigger_error(sprintf('The class %s is deprecated since Symfony 3.4 and will be removed in 4.0. Use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler instead.', MemcacheSessionHandler::class), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* MemcacheSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler instead.
|
||||
*/
|
||||
class MemcacheSessionHandler implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var \Memcache Memcache driver
|
||||
*/
|
||||
private $memcache;
|
||||
|
||||
/**
|
||||
@@ -71,7 +70,7 @@ class MemcacheSessionHandler implements \SessionHandlerInterface
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
return $this->memcache->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +94,9 @@ class MemcacheSessionHandler implements \SessionHandlerInterface
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
return $this->memcache->delete($this->prefix.$sessionId);
|
||||
$this->memcache->delete($this->prefix.$sessionId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -12,8 +12,6 @@
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* MemcachedSessionHandler.
|
||||
*
|
||||
* Memcached based session storage handler based on the Memcached class
|
||||
* provided by the PHP memcached extension.
|
||||
*
|
||||
@@ -21,11 +19,8 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class MemcachedSessionHandler implements \SessionHandlerInterface
|
||||
class MemcachedSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
/**
|
||||
* @var \Memcached Memcached driver
|
||||
*/
|
||||
private $memcached;
|
||||
|
||||
/**
|
||||
@@ -43,7 +38,7 @@ class MemcachedSessionHandler implements \SessionHandlerInterface
|
||||
*
|
||||
* List of available options:
|
||||
* * prefix: The prefix to use for the memcached keys in order to avoid collision
|
||||
* * expiretime: The time to live in seconds
|
||||
* * expiretime: The time to live in seconds.
|
||||
*
|
||||
* @param \Memcached $memcached A \Memcached instance
|
||||
* @param array $options An associative array of Memcached options
|
||||
@@ -64,14 +59,6 @@ class MemcachedSessionHandler implements \SessionHandlerInterface
|
||||
$this->prefix = isset($options['prefix']) ? $options['prefix'] : 'sf2s';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -83,7 +70,7 @@ class MemcachedSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
protected function doRead($sessionId)
|
||||
{
|
||||
return $this->memcached->get($this->prefix.$sessionId) ?: '';
|
||||
}
|
||||
@@ -91,7 +78,17 @@ class MemcachedSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
public function updateTimestamp($sessionId, $data)
|
||||
{
|
||||
$this->memcached->touch($this->prefix.$sessionId, time() + $this->ttl);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWrite($sessionId, $data)
|
||||
{
|
||||
return $this->memcached->set($this->prefix.$sessionId, $data, time() + $this->ttl);
|
||||
}
|
||||
@@ -99,9 +96,11 @@ class MemcachedSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
protected function doDestroy($sessionId)
|
||||
{
|
||||
return $this->memcached->delete($this->prefix.$sessionId);
|
||||
$result = $this->memcached->delete($this->prefix.$sessionId);
|
||||
|
||||
return $result || \Memcached::RES_NOTFOUND == $this->memcached->getResultCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -12,15 +12,15 @@
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* MongoDB session handler.
|
||||
* Session handler using the mongodb/mongodb package and MongoDB driver extension.
|
||||
*
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
*
|
||||
* @see https://packagist.org/packages/mongodb/mongodb
|
||||
* @see http://php.net/manual/en/set.mongodb.php
|
||||
*/
|
||||
class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
class MongoDbSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
/**
|
||||
* @var \Mongo|\MongoClient|\MongoDB\Client
|
||||
*/
|
||||
private $mongo;
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
* * id_field: The field name for storing the session id [default: _id]
|
||||
* * data_field: The field name for storing the session data [default: data]
|
||||
* * time_field: The field name for storing the timestamp [default: time]
|
||||
* * expiry_field: The field name for storing the expiry-timestamp [default: expires_at]
|
||||
* * expiry_field: The field name for storing the expiry-timestamp [default: expires_at].
|
||||
*
|
||||
* It is strongly recommended to put an index on the `expiry_field` for
|
||||
* garbage-collection. Alternatively it's possible to automatically expire
|
||||
@@ -61,14 +61,18 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
* If you use such an index, you can drop `gc_probability` to 0 since
|
||||
* no garbage-collection is required.
|
||||
*
|
||||
* @param \Mongo|\MongoClient|\MongoDB\Client $mongo A MongoDB\Client, MongoClient or Mongo instance
|
||||
* @param array $options An associative array of field options
|
||||
* @param \MongoDB\Client $mongo A MongoDB\Client instance
|
||||
* @param array $options An associative array of field options
|
||||
*
|
||||
* @throws \InvalidArgumentException When MongoClient or Mongo instance not provided
|
||||
* @throws \InvalidArgumentException When "database" or "collection" not provided
|
||||
*/
|
||||
public function __construct($mongo, array $options)
|
||||
{
|
||||
if ($mongo instanceof \MongoClient || $mongo instanceof \Mongo) {
|
||||
@trigger_error(sprintf('Using %s with the legacy mongo extension is deprecated as of 3.4 and will be removed in 4.0. Use it with the mongodb/mongodb package and ext-mongodb instead.', __CLASS__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (!($mongo instanceof \MongoDB\Client || $mongo instanceof \MongoClient || $mongo instanceof \Mongo)) {
|
||||
throw new \InvalidArgumentException('MongoClient or Mongo instance required');
|
||||
}
|
||||
@@ -87,14 +91,6 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -106,7 +102,7 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
protected function doDestroy($sessionId)
|
||||
{
|
||||
$methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteOne' : 'remove';
|
||||
|
||||
@@ -122,7 +118,7 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
*/
|
||||
public function gc($maxlifetime)
|
||||
{
|
||||
$methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteOne' : 'remove';
|
||||
$methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteMany' : 'remove';
|
||||
|
||||
$this->getCollection()->$methodName(array(
|
||||
$this->options['expiry_field'] => array('$lt' => $this->createDateTime()),
|
||||
@@ -134,7 +130,7 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
protected function doWrite($sessionId, $data)
|
||||
{
|
||||
$expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime'));
|
||||
|
||||
@@ -166,7 +162,34 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
public function updateTimestamp($sessionId, $data)
|
||||
{
|
||||
$expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime'));
|
||||
|
||||
if ($this->mongo instanceof \MongoDB\Client) {
|
||||
$methodName = 'updateOne';
|
||||
$options = array();
|
||||
} else {
|
||||
$methodName = 'update';
|
||||
$options = array('multiple' => false);
|
||||
}
|
||||
|
||||
$this->getCollection()->$methodName(
|
||||
array($this->options['id_field'] => $sessionId),
|
||||
array('$set' => array(
|
||||
$this->options['time_field'] => $this->createDateTime(),
|
||||
$this->options['expiry_field'] => $expiry,
|
||||
)),
|
||||
$options
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doRead($sessionId)
|
||||
{
|
||||
$dbData = $this->getCollection()->findOne(array(
|
||||
$this->options['id_field'] => $sessionId,
|
||||
@@ -214,6 +237,8 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
|
||||
* Return an instance of a MongoDate or \MongoDB\BSON\UTCDateTime
|
||||
*
|
||||
* @param int $seconds An integer representing UTC seconds since Jan 1 1970. Defaults to now.
|
||||
*
|
||||
* @return \MongoDate|\MongoDB\BSON\UTCDateTime
|
||||
*/
|
||||
private function createDateTime($seconds = null)
|
||||
{
|
||||
|
@@ -12,8 +12,6 @@
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* NativeFileSessionHandler.
|
||||
*
|
||||
* Native session handler using PHP's built in file storage.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
@@ -21,8 +19,6 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
class NativeFileSessionHandler extends NativeSessionHandler
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $savePath Path of directory to save session files
|
||||
* Default null will leave setting as defined by PHP.
|
||||
* '/path', 'N;/path', or 'N;octal-mode;/path
|
||||
@@ -30,6 +26,7 @@ class NativeFileSessionHandler extends NativeSessionHandler
|
||||
* @see http://php.net/session.configuration.php#ini.session.save-path for further details.
|
||||
*
|
||||
* @throws \InvalidArgumentException On invalid $savePath
|
||||
* @throws \RuntimeException When failing to create the save directory
|
||||
*/
|
||||
public function __construct($savePath = null)
|
||||
{
|
||||
|
@@ -12,10 +12,13 @@
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* Adds SessionHandler functionality if available.
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Use \SessionHandler instead.
|
||||
* @see http://php.net/sessionhandler
|
||||
*/
|
||||
class NativeSessionHandler extends \SessionHandler
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
@trigger_error('The '.__NAMESPACE__.'\NativeSessionHandler class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the \SessionHandler class instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
@@ -12,22 +12,12 @@
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* NullSessionHandler.
|
||||
*
|
||||
* Can be used in unit testing or in a situations where persisted sessions are not desired.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NullSessionHandler implements \SessionHandlerInterface
|
||||
class NullSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -39,15 +29,7 @@ class NullSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
public function validateId($sessionId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -55,7 +37,31 @@ class NullSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
protected function doRead($sessionId)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateTimestamp($sessionId, $data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWrite($sessionId, $data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDestroy($sessionId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
* @author Michael Williams <michael.williams@funsational.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
class PdoSessionHandler implements \SessionHandlerInterface
|
||||
class PdoSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
/**
|
||||
* No locking is done. This means sessions are prone to loss of data due to
|
||||
@@ -148,8 +148,6 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
private $gcCalled = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* You can either pass an existing database connection as PDO instance or
|
||||
* pass a DSN string that will be used to lazy-connect to the database
|
||||
* when the session is actually used. Furthermore it's possible to pass null
|
||||
@@ -166,7 +164,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
* * db_connection_options: An array of driver-specific connection options [default: array()]
|
||||
* * lock_mode: The strategy for locking, see constants [default: LOCK_TRANSACTIONAL]
|
||||
*
|
||||
* @param \PDO|string|null $pdoOrDsn A \PDO instance or DSN string or null
|
||||
* @param \PDO|string|null $pdoOrDsn A \PDO instance or DSN string or URL string or null
|
||||
* @param array $options An associative array of options
|
||||
*
|
||||
* @throws \InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
|
||||
@@ -180,6 +178,8 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
|
||||
$this->pdo = $pdoOrDsn;
|
||||
$this->driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||
} elseif (\is_string($pdoOrDsn) && false !== strpos($pdoOrDsn, '://')) {
|
||||
$this->dsn = $this->buildDsnFromUrl($pdoOrDsn);
|
||||
} else {
|
||||
$this->dsn = $pdoOrDsn;
|
||||
}
|
||||
@@ -262,11 +262,13 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
$this->sessionExpired = false;
|
||||
|
||||
if (null === $this->pdo) {
|
||||
$this->connect($this->dsn ?: $savePath);
|
||||
}
|
||||
|
||||
return true;
|
||||
return parent::open($savePath, $sessionName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,7 +277,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
public function read($sessionId)
|
||||
{
|
||||
try {
|
||||
return $this->doRead($sessionId);
|
||||
return parent::read($sessionId);
|
||||
} catch (\PDOException $e) {
|
||||
$this->rollback();
|
||||
|
||||
@@ -298,7 +300,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
protected function doDestroy($sessionId)
|
||||
{
|
||||
// delete the record associated with this id
|
||||
$sql = "DELETE FROM $this->table WHERE $this->idCol = :id";
|
||||
@@ -319,7 +321,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
protected function doWrite($sessionId, $data)
|
||||
{
|
||||
$maxlifetime = (int) ini_get('session.gc_maxlifetime');
|
||||
|
||||
@@ -332,13 +334,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
$updateStmt = $this->pdo->prepare(
|
||||
"UPDATE $this->table SET $this->dataCol = :data, $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id"
|
||||
);
|
||||
$updateStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$updateStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
|
||||
$updateStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
|
||||
$updateStmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
$updateStmt = $this->getUpdateStatement($sessionId, $data, $maxlifetime);
|
||||
$updateStmt->execute();
|
||||
|
||||
// When MERGE is not supported, like in Postgres < 9.5, we have to use this approach that can result in
|
||||
@@ -348,13 +344,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
// false positives due to longer gap locking.
|
||||
if (!$updateStmt->rowCount()) {
|
||||
try {
|
||||
$insertStmt = $this->pdo->prepare(
|
||||
"INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)"
|
||||
);
|
||||
$insertStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$insertStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
|
||||
$insertStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
|
||||
$insertStmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
$insertStmt = $this->getInsertStatement($sessionId, $data, $maxlifetime);
|
||||
$insertStmt->execute();
|
||||
} catch (\PDOException $e) {
|
||||
// Handle integrity violation SQLSTATE 23000 (or a subclass like 23505 in Postgres) for duplicate keys
|
||||
@@ -374,6 +364,30 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateTimestamp($sessionId, $data)
|
||||
{
|
||||
$maxlifetime = (int) ini_get('session.gc_maxlifetime');
|
||||
|
||||
try {
|
||||
$updateStmt = $this->pdo->prepare(
|
||||
"UPDATE $this->table SET $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id"
|
||||
);
|
||||
$updateStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$updateStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
|
||||
$updateStmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
$updateStmt->execute();
|
||||
} catch (\PDOException $e) {
|
||||
$this->rollback();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -389,7 +403,11 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
$this->gcCalled = false;
|
||||
|
||||
// delete the session records that have expired
|
||||
$sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol < :time";
|
||||
if ('mysql' === $this->driver) {
|
||||
$sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol < :time";
|
||||
} else {
|
||||
$sql = "DELETE FROM $this->table WHERE $this->lifetimeCol < :time - $this->timeCol";
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
@@ -415,6 +433,102 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
$this->driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a PDO DSN from a URL-like connection string.
|
||||
*
|
||||
* @param string $dsnOrUrl
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @todo implement missing support for oci DSN (which look totally different from other PDO ones)
|
||||
*/
|
||||
private function buildDsnFromUrl($dsnOrUrl)
|
||||
{
|
||||
// (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid
|
||||
$url = preg_replace('#^((?:pdo_)?sqlite3?):///#', '$1://localhost/', $dsnOrUrl);
|
||||
|
||||
$params = parse_url($url);
|
||||
|
||||
if (false === $params) {
|
||||
return $dsnOrUrl; // If the URL is not valid, let's assume it might be a DSN already.
|
||||
}
|
||||
|
||||
$params = array_map('rawurldecode', $params);
|
||||
|
||||
// Override the default username and password. Values passed through options will still win over these in the constructor.
|
||||
if (isset($params['user'])) {
|
||||
$this->username = $params['user'];
|
||||
}
|
||||
|
||||
if (isset($params['pass'])) {
|
||||
$this->password = $params['pass'];
|
||||
}
|
||||
|
||||
if (!isset($params['scheme'])) {
|
||||
throw new \InvalidArgumentException('URLs without scheme are not supported to configure the PdoSessionHandler');
|
||||
}
|
||||
|
||||
$driverAliasMap = array(
|
||||
'mssql' => 'sqlsrv',
|
||||
'mysql2' => 'mysql', // Amazon RDS, for some weird reason
|
||||
'postgres' => 'pgsql',
|
||||
'postgresql' => 'pgsql',
|
||||
'sqlite3' => 'sqlite',
|
||||
);
|
||||
|
||||
$driver = isset($driverAliasMap[$params['scheme']]) ? $driverAliasMap[$params['scheme']] : $params['scheme'];
|
||||
|
||||
// Doctrine DBAL supports passing its internal pdo_* driver names directly too (allowing both dashes and underscores). This allows supporting the same here.
|
||||
if (0 === strpos($driver, 'pdo_') || 0 === strpos($driver, 'pdo-')) {
|
||||
$driver = substr($driver, 4);
|
||||
}
|
||||
|
||||
switch ($driver) {
|
||||
case 'mysql':
|
||||
case 'pgsql':
|
||||
$dsn = $driver.':';
|
||||
|
||||
if (isset($params['host']) && '' !== $params['host']) {
|
||||
$dsn .= 'host='.$params['host'].';';
|
||||
}
|
||||
|
||||
if (isset($params['port']) && '' !== $params['port']) {
|
||||
$dsn .= 'port='.$params['port'].';';
|
||||
}
|
||||
|
||||
if (isset($params['path'])) {
|
||||
$dbName = substr($params['path'], 1); // Remove the leading slash
|
||||
$dsn .= 'dbname='.$dbName.';';
|
||||
}
|
||||
|
||||
return $dsn;
|
||||
|
||||
case 'sqlite':
|
||||
return 'sqlite:'.substr($params['path'], 1);
|
||||
|
||||
case 'sqlsrv':
|
||||
$dsn = 'sqlsrv:server=';
|
||||
|
||||
if (isset($params['host'])) {
|
||||
$dsn .= $params['host'];
|
||||
}
|
||||
|
||||
if (isset($params['port']) && '' !== $params['port']) {
|
||||
$dsn .= ','.$params['port'];
|
||||
}
|
||||
|
||||
if (isset($params['path'])) {
|
||||
$dbName = substr($params['path'], 1); // Remove the leading slash
|
||||
$dsn .= ';Database='.$dbName;
|
||||
}
|
||||
|
||||
return $dsn;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('The scheme "%s" is not supported by the PdoSessionHandler URL configuration. Pass a PDO DSN directly.', $params['scheme']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to begin a transaction.
|
||||
*
|
||||
@@ -493,10 +607,8 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
*
|
||||
* @return string The session data
|
||||
*/
|
||||
private function doRead($sessionId)
|
||||
protected function doRead($sessionId)
|
||||
{
|
||||
$this->sessionExpired = false;
|
||||
|
||||
if (self::LOCK_ADVISORY === $this->lockMode) {
|
||||
$this->unlockStatements[] = $this->doAdvisoryLock($sessionId);
|
||||
}
|
||||
@@ -504,6 +616,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
$selectSql = $this->getSelectSql();
|
||||
$selectStmt = $this->pdo->prepare($selectSql);
|
||||
$selectStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$insertStmt = null;
|
||||
|
||||
do {
|
||||
$selectStmt->execute();
|
||||
@@ -516,20 +629,21 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
return is_resource($sessionRows[0][0]) ? stream_get_contents($sessionRows[0][0]) : $sessionRows[0][0];
|
||||
return \is_resource($sessionRows[0][0]) ? stream_get_contents($sessionRows[0][0]) : $sessionRows[0][0];
|
||||
}
|
||||
|
||||
if (self::LOCK_TRANSACTIONAL === $this->lockMode && 'sqlite' !== $this->driver) {
|
||||
if (null !== $insertStmt) {
|
||||
$this->rollback();
|
||||
throw new \RuntimeException('Failed to read session: INSERT reported a duplicate id but next SELECT did not return any data.');
|
||||
}
|
||||
|
||||
if (!ini_get('session.use_strict_mode') && self::LOCK_TRANSACTIONAL === $this->lockMode && 'sqlite' !== $this->driver) {
|
||||
// In strict mode, session fixation is not possible: new sessions always start with a unique
|
||||
// random id, so that concurrency is not possible and this code path can be skipped.
|
||||
// Exclusive-reading of non-existent rows does not block, so we need to do an insert to block
|
||||
// until other connections to the session are committed.
|
||||
try {
|
||||
$insertStmt = $this->pdo->prepare(
|
||||
"INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)"
|
||||
);
|
||||
$insertStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$insertStmt->bindValue(':data', '', \PDO::PARAM_LOB);
|
||||
$insertStmt->bindValue(':lifetime', 0, \PDO::PARAM_INT);
|
||||
$insertStmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
$insertStmt = $this->getInsertStatement($sessionId, '', 0);
|
||||
$insertStmt->execute();
|
||||
} catch (\PDOException $e) {
|
||||
// Catch duplicate key error because other connection created the session already.
|
||||
@@ -568,23 +682,25 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
{
|
||||
switch ($this->driver) {
|
||||
case 'mysql':
|
||||
// MySQL 5.7.5 and later enforces a maximum length on lock names of 64 characters. Previously, no limit was enforced.
|
||||
$lockId = \substr($sessionId, 0, 64);
|
||||
// should we handle the return value? 0 on timeout, null on error
|
||||
// we use a timeout of 50 seconds which is also the default for innodb_lock_wait_timeout
|
||||
$stmt = $this->pdo->prepare('SELECT GET_LOCK(:key, 50)');
|
||||
$stmt->bindValue(':key', $sessionId, \PDO::PARAM_STR);
|
||||
$stmt->bindValue(':key', $lockId, \PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
|
||||
$releaseStmt = $this->pdo->prepare('DO RELEASE_LOCK(:key)');
|
||||
$releaseStmt->bindValue(':key', $sessionId, \PDO::PARAM_STR);
|
||||
$releaseStmt->bindValue(':key', $lockId, \PDO::PARAM_STR);
|
||||
|
||||
return $releaseStmt;
|
||||
case 'pgsql':
|
||||
// Obtaining an exclusive session level advisory lock requires an integer key.
|
||||
// So we convert the HEX representation of the session id to an integer.
|
||||
// Since integers are signed, we have to skip one hex char to fit in the range.
|
||||
if (4 === PHP_INT_SIZE) {
|
||||
$sessionInt1 = hexdec(substr($sessionId, 0, 7));
|
||||
$sessionInt2 = hexdec(substr($sessionId, 7, 7));
|
||||
// When session.sid_bits_per_character > 4, the session id can contain non-hex-characters.
|
||||
// So we cannot just use hexdec().
|
||||
if (4 === \PHP_INT_SIZE) {
|
||||
$sessionInt1 = $this->convertStringToInt($sessionId);
|
||||
$sessionInt2 = $this->convertStringToInt(substr($sessionId, 4, 4));
|
||||
|
||||
$stmt = $this->pdo->prepare('SELECT pg_advisory_lock(:key1, :key2)');
|
||||
$stmt->bindValue(':key1', $sessionInt1, \PDO::PARAM_INT);
|
||||
@@ -595,7 +711,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
$releaseStmt->bindValue(':key1', $sessionInt1, \PDO::PARAM_INT);
|
||||
$releaseStmt->bindValue(':key2', $sessionInt2, \PDO::PARAM_INT);
|
||||
} else {
|
||||
$sessionBigInt = hexdec(substr($sessionId, 0, 15));
|
||||
$sessionBigInt = $this->convertStringToInt($sessionId);
|
||||
|
||||
$stmt = $this->pdo->prepare('SELECT pg_advisory_lock(:key)');
|
||||
$stmt->bindValue(':key', $sessionBigInt, \PDO::PARAM_INT);
|
||||
@@ -613,6 +729,27 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the first 4 (when PHP_INT_SIZE == 4) or 8 characters of the string as an integer.
|
||||
*
|
||||
* Keep in mind, PHP integers are signed.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function convertStringToInt($string)
|
||||
{
|
||||
if (4 === \PHP_INT_SIZE) {
|
||||
return (\ord($string[3]) << 24) + (\ord($string[2]) << 16) + (\ord($string[1]) << 8) + \ord($string[0]);
|
||||
}
|
||||
|
||||
$int1 = (\ord($string[7]) << 24) + (\ord($string[6]) << 16) + (\ord($string[5]) << 8) + \ord($string[4]);
|
||||
$int2 = (\ord($string[3]) << 24) + (\ord($string[2]) << 16) + (\ord($string[1]) << 8) + \ord($string[0]);
|
||||
|
||||
return $int2 + ($int1 << 32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a locking or nonlocking SQL query to read session information.
|
||||
*
|
||||
@@ -643,6 +780,72 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
return "SELECT $this->dataCol, $this->lifetimeCol, $this->timeCol FROM $this->table WHERE $this->idCol = :id";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an insert statement supported by the database for writing session data.
|
||||
*
|
||||
* @param string $sessionId Session ID
|
||||
* @param string $sessionData Encoded session data
|
||||
* @param int $maxlifetime session.gc_maxlifetime
|
||||
*
|
||||
* @return \PDOStatement The insert statement
|
||||
*/
|
||||
private function getInsertStatement($sessionId, $sessionData, $maxlifetime)
|
||||
{
|
||||
switch ($this->driver) {
|
||||
case 'oci':
|
||||
$data = fopen('php://memory', 'r+');
|
||||
fwrite($data, $sessionData);
|
||||
rewind($data);
|
||||
$sql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, EMPTY_BLOB(), :lifetime, :time) RETURNING $this->dataCol into :data";
|
||||
break;
|
||||
default:
|
||||
$data = $sessionData;
|
||||
$sql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)";
|
||||
break;
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$stmt->bindParam(':data', $data, \PDO::PARAM_LOB);
|
||||
$stmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an update statement supported by the database for writing session data.
|
||||
*
|
||||
* @param string $sessionId Session ID
|
||||
* @param string $sessionData Encoded session data
|
||||
* @param int $maxlifetime session.gc_maxlifetime
|
||||
*
|
||||
* @return \PDOStatement The update statement
|
||||
*/
|
||||
private function getUpdateStatement($sessionId, $sessionData, $maxlifetime)
|
||||
{
|
||||
switch ($this->driver) {
|
||||
case 'oci':
|
||||
$data = fopen('php://memory', 'r+');
|
||||
fwrite($data, $sessionData);
|
||||
rewind($data);
|
||||
$sql = "UPDATE $this->table SET $this->dataCol = EMPTY_BLOB(), $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id RETURNING $this->dataCol into :data";
|
||||
break;
|
||||
default:
|
||||
$data = $sessionData;
|
||||
$sql = "UPDATE $this->table SET $this->dataCol = :data, $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id";
|
||||
break;
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$stmt->bindParam(':data', $data, \PDO::PARAM_LOB);
|
||||
$stmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a merge/upsert (i.e. insert or update) statement when supported by the database for writing session data.
|
||||
*
|
||||
@@ -654,18 +857,11 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
*/
|
||||
private function getMergeStatement($sessionId, $data, $maxlifetime)
|
||||
{
|
||||
$mergeSql = null;
|
||||
switch (true) {
|
||||
case 'mysql' === $this->driver:
|
||||
$mergeSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time) ".
|
||||
"ON DUPLICATE KEY UPDATE $this->dataCol = VALUES($this->dataCol), $this->lifetimeCol = VALUES($this->lifetimeCol), $this->timeCol = VALUES($this->timeCol)";
|
||||
break;
|
||||
case 'oci' === $this->driver:
|
||||
// DUAL is Oracle specific dummy table
|
||||
$mergeSql = "MERGE INTO $this->table USING DUAL ON ($this->idCol = ?) ".
|
||||
"WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
|
||||
"WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?";
|
||||
break;
|
||||
case 'sqlsrv' === $this->driver && version_compare($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '10', '>='):
|
||||
// MERGE is only available since SQL Server 2008 and must be terminated by semicolon
|
||||
// It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx
|
||||
@@ -680,29 +876,30 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
$mergeSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time) ".
|
||||
"ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)";
|
||||
break;
|
||||
default:
|
||||
// MERGE is not supported with LOBs: http://www.oracle.com/technetwork/articles/fuecks-lobs-095315.html
|
||||
return null;
|
||||
}
|
||||
|
||||
if (null !== $mergeSql) {
|
||||
$mergeStmt = $this->pdo->prepare($mergeSql);
|
||||
$mergeStmt = $this->pdo->prepare($mergeSql);
|
||||
|
||||
if ('sqlsrv' === $this->driver || 'oci' === $this->driver) {
|
||||
$mergeStmt->bindParam(1, $sessionId, \PDO::PARAM_STR);
|
||||
$mergeStmt->bindParam(2, $sessionId, \PDO::PARAM_STR);
|
||||
$mergeStmt->bindParam(3, $data, \PDO::PARAM_LOB);
|
||||
$mergeStmt->bindParam(4, $maxlifetime, \PDO::PARAM_INT);
|
||||
$mergeStmt->bindValue(5, time(), \PDO::PARAM_INT);
|
||||
$mergeStmt->bindParam(6, $data, \PDO::PARAM_LOB);
|
||||
$mergeStmt->bindParam(7, $maxlifetime, \PDO::PARAM_INT);
|
||||
$mergeStmt->bindValue(8, time(), \PDO::PARAM_INT);
|
||||
} else {
|
||||
$mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
|
||||
$mergeStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
|
||||
$mergeStmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
return $mergeStmt;
|
||||
if ('sqlsrv' === $this->driver) {
|
||||
$mergeStmt->bindParam(1, $sessionId, \PDO::PARAM_STR);
|
||||
$mergeStmt->bindParam(2, $sessionId, \PDO::PARAM_STR);
|
||||
$mergeStmt->bindParam(3, $data, \PDO::PARAM_LOB);
|
||||
$mergeStmt->bindParam(4, $maxlifetime, \PDO::PARAM_INT);
|
||||
$mergeStmt->bindValue(5, time(), \PDO::PARAM_INT);
|
||||
$mergeStmt->bindParam(6, $data, \PDO::PARAM_LOB);
|
||||
$mergeStmt->bindParam(7, $maxlifetime, \PDO::PARAM_INT);
|
||||
$mergeStmt->bindValue(8, time(), \PDO::PARAM_INT);
|
||||
} else {
|
||||
$mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
|
||||
$mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
|
||||
$mergeStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
|
||||
$mergeStmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
return $mergeStmt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
103
vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php
vendored
Normal file
103
vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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 basic `SessionUpdateTimestampHandlerInterface` behaviors to another `SessionHandlerInterface`.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class StrictSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
private $handler;
|
||||
private $doDestroy;
|
||||
|
||||
public function __construct(\SessionHandlerInterface $handler)
|
||||
{
|
||||
if ($handler instanceof \SessionUpdateTimestampHandlerInterface) {
|
||||
throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', \get_class($handler), self::class));
|
||||
}
|
||||
|
||||
$this->handler = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
parent::open($savePath, $sessionName);
|
||||
|
||||
return $this->handler->open($savePath, $sessionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doRead($sessionId)
|
||||
{
|
||||
return $this->handler->read($sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateTimestamp($sessionId, $data)
|
||||
{
|
||||
return $this->write($sessionId, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWrite($sessionId, $data)
|
||||
{
|
||||
return $this->handler->write($sessionId, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
$this->doDestroy = true;
|
||||
$destroyed = parent::destroy($sessionId);
|
||||
|
||||
return $this->doDestroy ? $this->doDestroy($sessionId) : $destroyed;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDestroy($sessionId)
|
||||
{
|
||||
$this->doDestroy = false;
|
||||
|
||||
return $this->handler->destroy($sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
return $this->handler->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function gc($maxlifetime)
|
||||
{
|
||||
return $this->handler->gc($maxlifetime);
|
||||
}
|
||||
}
|
@@ -15,12 +15,11 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
* Wraps another SessionHandlerInterface to only write the session when it has been modified.
|
||||
*
|
||||
* @author Adrien Brault <adrien.brault@gmail.com>
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Implement `SessionUpdateTimestampHandlerInterface` or extend `AbstractSessionHandler` instead.
|
||||
*/
|
||||
class WriteCheckSessionHandler implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var \SessionHandlerInterface
|
||||
*/
|
||||
private $wrappedSessionHandler;
|
||||
|
||||
/**
|
||||
@@ -30,6 +29,8 @@ class WriteCheckSessionHandler implements \SessionHandlerInterface
|
||||
|
||||
public function __construct(\SessionHandlerInterface $wrappedSessionHandler)
|
||||
{
|
||||
@trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Implement `SessionUpdateTimestampHandlerInterface` or extend `AbstractSessionHandler` instead.', self::class), E_USER_DEPRECATED);
|
||||
|
||||
$this->wrappedSessionHandler = $wrappedSessionHandler;
|
||||
}
|
||||
|
||||
|
@@ -54,8 +54,6 @@ class MetadataBag implements SessionBagInterface
|
||||
private $updateThreshold;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $storageKey The key used to store bag in the session
|
||||
* @param int $updateThreshold The time to wait between two UPDATED updates
|
||||
*/
|
||||
|
@@ -58,13 +58,11 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
protected $metadataBag;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var array|SessionBagInterface[]
|
||||
*/
|
||||
protected $bags;
|
||||
protected $bags = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name Session name
|
||||
* @param MetadataBag $metaBag MetadataBag instance
|
||||
*/
|
||||
@@ -74,11 +72,6 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
$this->setMetadataBag($metaBag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the session data.
|
||||
*
|
||||
* @param array $array
|
||||
*/
|
||||
public function setSessionData(array $array)
|
||||
{
|
||||
$this->data = $array;
|
||||
@@ -215,11 +208,6 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
return $this->started;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MetadataBag.
|
||||
*
|
||||
* @param MetadataBag $bag
|
||||
*/
|
||||
public function setMetadataBag(MetadataBag $bag = null)
|
||||
{
|
||||
if (null === $bag) {
|
||||
|
@@ -24,14 +24,9 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
*/
|
||||
class MockFileSessionStorage extends MockArraySessionStorage
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $savePath;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $savePath Path of directory to save session files
|
||||
* @param string $name Session name
|
||||
* @param MetadataBag $metaBag MetadataBag instance
|
||||
@@ -96,7 +91,26 @@ class MockFileSessionStorage extends MockArraySessionStorage
|
||||
throw new \RuntimeException('Trying to save a session that was not started yet or was already closed');
|
||||
}
|
||||
|
||||
file_put_contents($this->getFilePath(), serialize($this->data));
|
||||
$data = $this->data;
|
||||
|
||||
foreach ($this->bags as $bag) {
|
||||
if (empty($data[$key = $bag->getStorageKey()])) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
}
|
||||
if (array($key = $this->metadataBag->getStorageKey()) === array_keys($data)) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
try {
|
||||
if ($data) {
|
||||
file_put_contents($this->getFilePath(), serialize($data));
|
||||
} else {
|
||||
$this->destroy();
|
||||
}
|
||||
} finally {
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
// this is needed for Silex, where the session object is re-used across requests
|
||||
// in functional tests. In Symfony, the container is rebooted, so we don't have
|
||||
|
@@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
|
||||
@@ -24,11 +24,9 @@ use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
class NativeSessionStorage implements SessionStorageInterface
|
||||
{
|
||||
/**
|
||||
* Array of SessionBagInterface.
|
||||
*
|
||||
* @var SessionBagInterface[]
|
||||
*/
|
||||
protected $bags;
|
||||
protected $bags = array();
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
@@ -41,7 +39,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
protected $closed = false;
|
||||
|
||||
/**
|
||||
* @var AbstractProxy
|
||||
* @var AbstractProxy|\SessionHandlerInterface
|
||||
*/
|
||||
protected $saveHandler;
|
||||
|
||||
@@ -51,8 +49,6 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
protected $metadataBag;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Depending on how you want the storage driver to behave you probably
|
||||
* want to override this constructor entirely.
|
||||
*
|
||||
@@ -65,6 +61,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* PHP starts to execute user-land code. Setting during runtime has no effect).
|
||||
*
|
||||
* cache_limiter, "" (use "0" to prevent headers from being sent entirely).
|
||||
* cache_expire, "0"
|
||||
* cookie_domain, ""
|
||||
* cookie_httponly, ""
|
||||
* cookie_lifetime, "0"
|
||||
@@ -77,9 +74,11 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* gc_probability, "1"
|
||||
* hash_bits_per_character, "4"
|
||||
* hash_function, "0"
|
||||
* lazy_write, "1"
|
||||
* name, "PHPSESSID"
|
||||
* referer_check, ""
|
||||
* serialize_handler, "php"
|
||||
* use_strict_mode, "0"
|
||||
* use_cookies, "1"
|
||||
* use_only_cookies, "1"
|
||||
* use_trans_sid, "0"
|
||||
@@ -90,15 +89,23 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* upload_progress.freq, "1%"
|
||||
* upload_progress.min-freq, "1"
|
||||
* url_rewriter.tags, "a=href,area=href,frame=src,form=,fieldset="
|
||||
* sid_length, "32"
|
||||
* sid_bits_per_character, "5"
|
||||
* trans_sid_hosts, $_SERVER['HTTP_HOST']
|
||||
* trans_sid_tags, "a=href,area=href,frame=src,form="
|
||||
*
|
||||
* @param array $options Session configuration options
|
||||
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
|
||||
* @param MetadataBag $metaBag MetadataBag
|
||||
* @param array $options Session configuration options
|
||||
* @param \SessionHandlerInterface|null $handler
|
||||
* @param MetadataBag $metaBag MetadataBag
|
||||
*/
|
||||
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
|
||||
{
|
||||
session_cache_limiter(''); // disable by default because it's managed by HeaderBag (if used)
|
||||
ini_set('session.use_cookies', 1);
|
||||
$options += array(
|
||||
'cache_limiter' => '',
|
||||
'cache_expire' => 0,
|
||||
'use_cookies' => 1,
|
||||
'lazy_write' => 1,
|
||||
);
|
||||
|
||||
session_register_shutdown();
|
||||
|
||||
@@ -110,7 +117,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
/**
|
||||
* Gets the save handler instance.
|
||||
*
|
||||
* @return AbstractProxy
|
||||
* @return AbstractProxy|\SessionHandlerInterface
|
||||
*/
|
||||
public function getSaveHandler()
|
||||
{
|
||||
@@ -186,6 +193,10 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
if (headers_sent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null !== $lifetime) {
|
||||
ini_set('session.cookie_lifetime', $lifetime);
|
||||
}
|
||||
@@ -208,7 +219,40 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
session_write_close();
|
||||
$session = $_SESSION;
|
||||
|
||||
foreach ($this->bags as $bag) {
|
||||
if (empty($_SESSION[$key = $bag->getStorageKey()])) {
|
||||
unset($_SESSION[$key]);
|
||||
}
|
||||
}
|
||||
if (array($key = $this->metadataBag->getStorageKey()) === array_keys($_SESSION)) {
|
||||
unset($_SESSION[$key]);
|
||||
}
|
||||
|
||||
// Register custom error handler to catch a possible failure warning during session write
|
||||
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
||||
throw new \ErrorException($errstr, $errno, E_WARNING, $errfile, $errline);
|
||||
}, E_WARNING);
|
||||
|
||||
try {
|
||||
$e = null;
|
||||
session_write_close();
|
||||
} catch (\ErrorException $e) {
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
$_SESSION = $session;
|
||||
}
|
||||
if (null !== $e) {
|
||||
// The default PHP error message is not very helpful, as it does not give any information on the current save handler.
|
||||
// Therefore, we catch this error and trigger a warning with a better error message
|
||||
$handler = $this->getSaveHandler();
|
||||
if ($handler instanceof SessionHandlerProxy) {
|
||||
$handler = $handler->getHandler();
|
||||
}
|
||||
|
||||
trigger_error(sprintf('session_write_close(): Failed to write session data with %s handler', \get_class($handler)), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$this->closed = true;
|
||||
$this->started = false;
|
||||
@@ -252,7 +296,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
|
||||
}
|
||||
|
||||
if ($this->saveHandler->isActive() && !$this->started) {
|
||||
if (!$this->started && $this->saveHandler->isActive()) {
|
||||
$this->loadSession();
|
||||
} elseif (!$this->started) {
|
||||
$this->start();
|
||||
@@ -261,11 +305,6 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
return $this->bags[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MetadataBag.
|
||||
*
|
||||
* @param MetadataBag $metaBag
|
||||
*/
|
||||
public function setMetadataBag(MetadataBag $metaBag = null)
|
||||
{
|
||||
if (null === $metaBag) {
|
||||
@@ -305,21 +344,26 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$validOptions = array_flip(array(
|
||||
'cache_limiter', 'cookie_domain', 'cookie_httponly',
|
||||
'cache_expire', 'cache_limiter', 'cookie_domain', 'cookie_httponly',
|
||||
'cookie_lifetime', 'cookie_path', 'cookie_secure',
|
||||
'entropy_file', 'entropy_length', 'gc_divisor',
|
||||
'gc_maxlifetime', 'gc_probability', 'hash_bits_per_character',
|
||||
'hash_function', 'name', 'referer_check',
|
||||
'serialize_handler', 'use_cookies',
|
||||
'hash_function', 'lazy_write', 'name', 'referer_check',
|
||||
'serialize_handler', 'use_strict_mode', 'use_cookies',
|
||||
'use_only_cookies', 'use_trans_sid', 'upload_progress.enabled',
|
||||
'upload_progress.cleanup', 'upload_progress.prefix', 'upload_progress.name',
|
||||
'upload_progress.freq', 'upload_progress.min-freq', 'url_rewriter.tags',
|
||||
'upload_progress.freq', 'upload_progress.min_freq', 'url_rewriter.tags',
|
||||
'sid_length', 'sid_bits_per_character', 'trans_sid_hosts', 'trans_sid_tags',
|
||||
));
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
if (isset($validOptions[$key])) {
|
||||
ini_set('session.'.$key, $value);
|
||||
ini_set('url_rewriter.tags' !== $key ? 'session.'.$key : $key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,7 +377,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* ini_set('session.save_handler', 'files');
|
||||
* ini_set('session.save_path', '/tmp');
|
||||
*
|
||||
* or pass in a NativeSessionHandler instance which configures session.save_handler in the
|
||||
* or pass in a \SessionHandler instance which configures session.save_handler in the
|
||||
* constructor, for a template see NativeFileSessionHandler or use handlers in
|
||||
* composer package drak/native-session
|
||||
*
|
||||
@@ -342,28 +386,31 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* @see http://php.net/sessionhandler
|
||||
* @see http://github.com/drak/NativeSession
|
||||
*
|
||||
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler
|
||||
* @param \SessionHandlerInterface|null $saveHandler
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setSaveHandler($saveHandler = null)
|
||||
{
|
||||
if (!$saveHandler instanceof AbstractProxy &&
|
||||
!$saveHandler instanceof NativeSessionHandler &&
|
||||
!$saveHandler instanceof \SessionHandlerInterface &&
|
||||
null !== $saveHandler) {
|
||||
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
|
||||
throw new \InvalidArgumentException('Must be instance of AbstractProxy; implement \SessionHandlerInterface; or be null.');
|
||||
}
|
||||
|
||||
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
|
||||
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
|
||||
$saveHandler = new SessionHandlerProxy($saveHandler);
|
||||
} elseif (!$saveHandler instanceof AbstractProxy) {
|
||||
$saveHandler = new SessionHandlerProxy(new \SessionHandler());
|
||||
$saveHandler = new SessionHandlerProxy(new StrictSessionHandler(new \SessionHandler()));
|
||||
}
|
||||
$this->saveHandler = $saveHandler;
|
||||
|
||||
if ($this->saveHandler instanceof \SessionHandlerInterface) {
|
||||
if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->saveHandler instanceof SessionHandlerProxy) {
|
||||
session_set_save_handler($this->saveHandler, false);
|
||||
}
|
||||
}
|
||||
@@ -375,8 +422,6 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* are set to (either PHP's internal, or a custom save handler set with session_set_save_handler()).
|
||||
* PHP takes the return value from the read() handler, unserializes it
|
||||
* and populates $_SESSION with the result automatically.
|
||||
*
|
||||
* @param array|null $session
|
||||
*/
|
||||
protected function loadSession(array &$session = null)
|
||||
{
|
||||
|
@@ -11,9 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
|
||||
|
||||
/**
|
||||
* Allows session to be started by PHP and managed by Symfony.
|
||||
*
|
||||
@@ -22,10 +19,8 @@ use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandle
|
||||
class PhpBridgeSessionStorage extends NativeSessionStorage
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
|
||||
* @param MetadataBag $metaBag MetadataBag
|
||||
* @param \SessionHandlerInterface|null $handler
|
||||
* @param MetadataBag $metaBag MetadataBag
|
||||
*/
|
||||
public function __construct($handler = null, MetadataBag $metaBag = null)
|
||||
{
|
||||
|
@@ -12,8 +12,6 @@
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
|
||||
|
||||
/**
|
||||
* AbstractProxy.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
abstract class AbstractProxy
|
||||
|
@@ -11,18 +11,17 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\NativeProxy class is deprecated since Symfony 3.4 and will be removed in 4.0. Use your session handler implementation directly.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* NativeProxy.
|
||||
* This proxy is built-in session handlers in PHP 5.3.x.
|
||||
*
|
||||
* This proxy is built-in session handlers in PHP 5.3.x
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Use your session handler implementation directly.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NativeProxy extends AbstractProxy
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// this makes an educated guess as to what the handler is since it should already be set.
|
||||
|
@@ -12,22 +12,12 @@
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
|
||||
|
||||
/**
|
||||
* SessionHandler proxy.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
|
||||
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var \SessionHandlerInterface
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \SessionHandlerInterface $handler
|
||||
*/
|
||||
public function __construct(\SessionHandlerInterface $handler)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
@@ -35,6 +25,14 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
|
||||
$this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \SessionHandlerInterface
|
||||
*/
|
||||
public function getHandler()
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
// \SessionHandlerInterface
|
||||
|
||||
/**
|
||||
@@ -84,4 +82,20 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ interface SessionStorageInterface
|
||||
*
|
||||
* @return bool True if started
|
||||
*
|
||||
* @throws \RuntimeException If something goes wrong starting the session.
|
||||
* @throws \RuntimeException if something goes wrong starting the session
|
||||
*/
|
||||
public function start();
|
||||
|
||||
@@ -104,8 +104,8 @@ interface SessionStorageInterface
|
||||
* a real PHP session would interfere with testing, in which case
|
||||
* it should actually persist the session data if required.
|
||||
*
|
||||
* @throws \RuntimeException If the session is saved without being started, or if the session
|
||||
* is already closed.
|
||||
* @throws \RuntimeException if the session is saved without being started, or if the session
|
||||
* is already closed
|
||||
*/
|
||||
public function save();
|
||||
|
||||
@@ -127,8 +127,6 @@ interface SessionStorageInterface
|
||||
|
||||
/**
|
||||
* Registers a SessionBagInterface for use.
|
||||
*
|
||||
* @param SessionBagInterface $bag
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag);
|
||||
|
||||
|
Reference in New Issue
Block a user