[HttpFoundation] Free bags from session storage and move classes to their own namespaces.

This commit is contained in:
Drak 2012-02-08 15:31:38 +05:45
parent d64939aeee
commit 468391525a
44 changed files with 385 additions and 383 deletions

View File

@ -232,7 +232,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
* Flashes are now stored as a bucket of messages per `$type` so there can be multiple messages per type. * Flashes are now stored as a bucket of messages per `$type` so there can be multiple messages per type.
There are four interface constants for type, `FlashBagInterface::INFO`, `FlashBagInterface::NOTICE`, There are four interface constants for type, `FlashBagInterface::INFO`, `FlashBagInterface::NOTICE`,
`FlashBagInterface::WARNING` and `FlashBagInterface::ERROR`. `FlashBagInterface::WARNING` and `FlashBagInterface::ERROR`.
* Added `FlashBag` (default). Flashes expire when retrieved by `popFlashes()`. * Added `FlashBag` (default). Flashes expire when retrieved by `pop()` or `popAll()`.
This makes the implementation ESI compatible. This makes the implementation ESI compatible.
* Added `AutoExpireFlashBag` to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring * Added `AutoExpireFlashBag` to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring
after one page page load. Messages must be retrived by `pop()` or `popAll()`. after one page page load. Messages must be retrived by `pop()` or `popAll()`.

View File

@ -259,7 +259,7 @@ UPGRADE FROM 2.0 to 2.1
</div> </div>
<?php endif; ?> <?php endif; ?>
If You wanted to process all flash types you could also make use of the `popAllFlashes()` API: If you wanted to process all flash types you could also make use of the `getFlashes()->all()` API:
<?php foreach ($view['session']->getFlashes()->all() as $type => $flash): ?> <?php foreach ($view['session']->getFlashes()->all() as $type => $flash): ?>
<div class="flash-$type"> <div class="flash-$type">
@ -270,8 +270,8 @@ UPGRADE FROM 2.0 to 2.1
.. note:: .. note::
The Flash Message API provides constants which you can optionally use. For example The Flash Message API provides constants which you can optionally use. For example
`Symfony\Component\HttpFoundation\FlashBag::NOTICE`, which can also be abbreviated to `Symfony\Component\HttpFoundation\SessionFlash\FlashBag::NOTICE`, which can also be abbreviated to
`FlashBag::NOTICE` providing you declare `<?php use Symfony\Component\HttpFoundation\FlashBag; ?>` `FlashBag::NOTICE` providing you declare `<?php use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; ?>`
at the beginning of the PHP template. at the beginning of the PHP template.
Before (Twig): Before (Twig):
@ -301,7 +301,7 @@ UPGRADE FROM 2.0 to 2.1
.. note:: .. note::
You can optionally use constants in Twig templates using `constant()` e.g. You can optionally use constants in Twig templates using `constant()` e.g.
`constant('Symfony\Component\HttpFoundation\FlashBag::NOTICE')`. `constant('Symfony\Component\HttpFoundation\SessionFlash\FlashBag::NOTICE')`.
* Session object * Session object

View File

@ -3,8 +3,6 @@
namespace Symfony\Bridge\Doctrine\HttpFoundation; namespace Symfony\Bridge\Doctrine\HttpFoundation;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
use Symfony\Component\HttpFoundation\SessionStorage\AbstractSessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\AbstractSessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\SessionSaveHandlerInterface; use Symfony\Component\HttpFoundation\SessionStorage\SessionSaveHandlerInterface;
use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\Connection;
@ -32,15 +30,13 @@ class DbalSessionStorage extends AbstractSessionStorage implements SessionSaveHa
* @param Connection $con An instance of Connection. * @param Connection $con An instance of Connection.
* @param string $tableName Table name. * @param string $tableName Table name.
* @param array $options Session configuration options * @param array $options Session configuration options
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
*/ */
public function __construct(Connection $con, $tableName = 'sessions', array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct(Connection $con, $tableName = 'sessions', array $options = array())
{ {
$this->con = $con; $this->con = $con;
$this->tableName = $tableName; $this->tableName = $tableName;
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
/** /**

View File

@ -6,8 +6,8 @@
<parameters> <parameters>
<parameter key="session.class">Symfony\Component\HttpFoundation\Session</parameter> <parameter key="session.class">Symfony\Component\HttpFoundation\Session</parameter>
<parameter key="session.flashbag.class">Symfony\Component\HttpFoundation\FlashBag</parameter> <parameter key="session.flashbag.class">Symfony\Component\HttpFoundation\SessionFlash\FlashBag</parameter>
<parameter key="session.attribute_bag.class">Symfony\Component\HttpFoundation\AttributeBag</parameter> <parameter key="session.attribute_bag.class">Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag</parameter>
<parameter key="session.storage.native_file.class">Symfony\Component\HttpFoundation\SessionStorage\NativeFileSessionStorage</parameter> <parameter key="session.storage.native_file.class">Symfony\Component\HttpFoundation\SessionStorage\NativeFileSessionStorage</parameter>
<parameter key="session.storage.null.class">Symfony\Component\HttpFoundation\SessionStorage\NullSessionStorage</parameter> <parameter key="session.storage.null.class">Symfony\Component\HttpFoundation\SessionStorage\NullSessionStorage</parameter>
<parameter key="session.storage.native_memcache.class">Symfony\Component\HttpFoundation\SessionStorage\NativeMemcacheSessionStorage</parameter> <parameter key="session.storage.native_memcache.class">Symfony\Component\HttpFoundation\SessionStorage\NativeMemcacheSessionStorage</parameter>
@ -25,6 +25,8 @@
<services> <services>
<service id="session" class="%session.class%"> <service id="session" class="%session.class%">
<argument type="service" id="session.storage" /> <argument type="service" id="session.storage" />
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session.flash_bag" class="%session.flashbag.class%" public="false" /> <service id="session.flash_bag" class="%session.flashbag.class%" public="false" />
@ -35,58 +37,42 @@
<service id="session.storage.mock_file" class="%session.storage.mock_file.class%" public="false"> <service id="session.storage.mock_file" class="%session.storage.mock_file.class%" public="false">
<argument>%kernel.cache_dir%/sessions</argument> <argument>%kernel.cache_dir%/sessions</argument>
<argument>%session.storage.options%</argument> <argument>%session.storage.options%</argument>
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session.storage.native_file" class="%session.storage.native_file.class%" public="false"> <service id="session.storage.native_file" class="%session.storage.native_file.class%" public="false">
<argument>%kernel.cache_dir%/sessions</argument> <argument>%kernel.cache_dir%/sessions</argument>
<argument>%session.storage.options%</argument> <argument>%session.storage.options%</argument>
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session.storage.native_memcache" class="%session.storage.native_memcache.class%" public="false"> <service id="session.storage.native_memcache" class="%session.storage.native_memcache.class%" public="false">
<argument>tcp://127.0.0.1:11211?persistent=0</argument> <argument>tcp://127.0.0.1:11211?persistent=0</argument>
<argument>%session.storage.options%</argument> <argument>%session.storage.options%</argument>
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session.storage.native_memcached" class="%session.storage.native_memcached.class%" public="false"> <service id="session.storage.native_memcached" class="%session.storage.native_memcached.class%" public="false">
<argument>127.0.0.1:11211</argument> <argument>127.0.0.1:11211</argument>
<argument>%session.storage.options%</argument> <argument>%session.storage.options%</argument>
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session.storage.memcache" class="%session.storage.memcache.class%" public="false"> <service id="session.storage.memcache" class="%session.storage.memcache.class%" public="false">
<argument type="service" id="session.memcache" /> <argument type="service" id="session.memcache" />
<argument>tcp://127.0.0.1:11211?persistent=0</argument> <argument>tcp://127.0.0.1:11211?persistent=0</argument>
<argument>%session.storage.options%</argument> <argument>%session.storage.options%</argument>
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session.storage.memcached" class="%session.storage.memcached.class%" public="false"> <service id="session.storage.memcached" class="%session.storage.memcached.class%" public="false">
<argument type="service" id="session.memcached" /> <argument type="service" id="session.memcached" />
<argument>tcp://127.0.0.1:11211?persistent=0</argument> <argument>tcp://127.0.0.1:11211?persistent=0</argument>
<argument>%session.storage.options%</argument> <argument>%session.storage.options%</argument>
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session.storage.native_sqlite" class="%session.storage.native_sqlite.class%" public="false"> <service id="session.storage.native_sqlite" class="%session.storage.native_sqlite.class%" public="false">
<argument>%kernel.cache_dir%/sf2_sqlite_sess.db</argument> <argument>%kernel.cache_dir%/sf2_sqlite_sess.db</argument>
<argument>%session.storage.options%</argument> <argument>%session.storage.options%</argument>
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session.storage.null" class="%session.storage.null.class%" public="false"> <service id="session.storage.null" class="%session.storage.null.class%" public="false">
<argument>%session.storage.options%</argument> <argument>%session.storage.options%</argument>
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service> </service>
<service id="session_listener" class="%session_listener.class%"> <service id="session_listener" class="%session_listener.class%">

View File

@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
use Symfony\Component\Templating\Helper\Helper; use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
/** /**
* SessionHelper provides read-only access to the session attributes. * SessionHelper provides read-only access to the session attributes.

View File

@ -15,8 +15,8 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session; use Symfony\Component\HttpFoundation\Session;
use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper; use Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
class SessionHelperTest extends \PHPUnit_Framework_TestCase class SessionHelperTest extends \PHPUnit_Framework_TestCase
{ {

View File

@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Bundle\TwigBundle\TwigEngine; use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\HttpFoundation\AutoExpireFlashBag; use Symfony\Component\HttpFoundation\SessionFlash\AutoExpireFlashBag;
/** /**
* WebDebugToolbarListener injects the Web Debug Toolbar. * WebDebugToolbarListener injects the Web Debug Toolbar.

View File

@ -1,24 +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 Symfony\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\SessionStorage\AttributeInterface;
/**
* Attributes store.
*
* @author Drak <drak@zikula.org>
*/
interface AttributeBagInterface extends SessionBagInterface, AttributeInterface
{
}

View File

@ -12,7 +12,11 @@
namespace Symfony\Component\HttpFoundation; namespace Symfony\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\SessionStorage\SessionStorageInterface; use Symfony\Component\HttpFoundation\SessionStorage\SessionStorageInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBagInterface;
use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
use Symfony\Component\HttpFoundation\SessionBagInterface;
/** /**
* Session. * Session.
@ -35,10 +39,14 @@ class Session implements SessionInterface
* Constructor. * Constructor.
* *
* @param SessionStorageInterface $storage A SessionStorageInterface instance. * @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)
*/ */
public function __construct(SessionStorageInterface $storage) public function __construct(SessionStorageInterface $storage, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
{ {
$this->storage = $storage; $this->storage = $storage;
$this->registerBag($attributes ?: new AttributeBag());
$this->registerBag($flashes ?: new FlashBag());
} }
/** /**
@ -64,7 +72,7 @@ class Session implements SessionInterface
*/ */
public function has($name) public function has($name)
{ {
return $this->storage->getAttributes()->has($name); return $this->storage->getBag('attributes')->has($name);
} }
/** /**
@ -79,7 +87,7 @@ class Session implements SessionInterface
*/ */
public function get($name, $default = null) public function get($name, $default = null)
{ {
return $this->storage->getAttributes()->get($name, $default); return $this->storage->getBag('attributes')->get($name, $default);
} }
/** /**
@ -92,7 +100,7 @@ class Session implements SessionInterface
*/ */
public function set($name, $value) public function set($name, $value)
{ {
$this->storage->getAttributes()->set($name, $value); $this->storage->getBag('attributes')->set($name, $value);
} }
/** /**
@ -104,7 +112,7 @@ class Session implements SessionInterface
*/ */
public function all() public function all()
{ {
return $this->storage->getAttributes()->all(); return $this->storage->getBag('attributes')->all();
} }
/** /**
@ -116,7 +124,7 @@ class Session implements SessionInterface
*/ */
public function replace(array $attributes) public function replace(array $attributes)
{ {
$this->storage->getAttributes()->replace($attributes); $this->storage->getBag('attributes')->replace($attributes);
} }
/** /**
@ -128,7 +136,7 @@ class Session implements SessionInterface
*/ */
public function remove($name) public function remove($name)
{ {
return $this->storage->getAttributes()->remove($name); return $this->storage->getBag('attributes')->remove($name);
} }
/** /**
@ -138,7 +146,7 @@ class Session implements SessionInterface
*/ */
public function clear() public function clear()
{ {
$this->storage->getAttributes()->clear(); $this->storage->getBag('attributes')->clear();
} }
/** /**
@ -218,13 +226,23 @@ class Session implements SessionInterface
$this->storage = $storage; $this->storage = $storage;
} }
public function registerBag(SessionBagInterface $bag)
{
$this->storage->registerBag($bag);
}
public function getBag($name)
{
return $this->storage->getBag($name);
}
/** /**
* Gets all flash messages. * Gets the flashbag interface.
* *
* @return FlashBagInterface * @return FlashBagInterface
*/ */
public function getFlashes() public function getFlashes()
{ {
return $this->storage->getFlashes(); return $this->getBag('flashes');
} }
} }

View File

@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\HttpFoundation; namespace Symfony\Component\HttpFoundation\SessionAttribute;
/** /**
* This class relates to session attribute storage * This class relates to session attribute storage
*/ */
class AttributeBag implements AttributeBagInterface class AttributeBag implements AttributeBagInterface
{ {
private $name = 'attributes';
/** /**
* @var string * @var string
*/ */
@ -36,6 +38,19 @@ class AttributeBag implements AttributeBagInterface
$this->storageKey = $storageKey; $this->storageKey = $storageKey;
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -114,6 +129,9 @@ class AttributeBag implements AttributeBagInterface
*/ */
public function clear() public function clear()
{ {
$return = $this->attributes;
$this->attributes = array(); $this->attributes = array();
return $return;
} }
} }

View File

@ -9,14 +9,16 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionAttribute;
use Symfony\Component\HttpFoundation\SessionBagInterface;
/** /**
* Interface for the session. * Attributes store.
* *
* @author Drak <drak@zikula.org> * @author Drak <drak@zikula.org>
*/ */
interface AttributeInterface interface AttributeBagInterface extends SessionBagInterface
{ {
/** /**
* Checks if an attribute is defined. * Checks if an attribute is defined.
@ -65,9 +67,4 @@ interface AttributeInterface
* @param string $name * @param string $name
*/ */
function remove($name); function remove($name);
/**
* Clears all attributes.
*/
function clear();
} }

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\HttpFoundation; namespace Symfony\Component\HttpFoundation\SessionAttribute;
/** /**
* This class provides structured storage of session attributes using * This class provides structured storage of session attributes using
@ -110,7 +110,10 @@ class NamespacedAttributeBag extends AttributeBag
*/ */
public function clear() public function clear()
{ {
$return = $this->attributes;
$this->attributes = array(); $this->attributes = array();
return $return;
} }
/** /**

View File

@ -18,6 +18,13 @@ namespace Symfony\Component\HttpFoundation;
*/ */
interface SessionBagInterface interface SessionBagInterface
{ {
/**
* Gets this bag's name
*
* @return string
*/
function getName();
/** /**
* Initializes the Bag * Initializes the Bag
* *
@ -31,4 +38,11 @@ interface SessionBagInterface
* @return string * @return string
*/ */
function getStorageKey(); function getStorageKey();
/**
* Clears out data from bag.
*
* @return mixed Whatever data was contained.
*/
function clear();
} }

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\HttpFoundation; namespace Symfony\Component\HttpFoundation\SessionFlash;
/** /**
* AutoExpireFlashBag flash message container. * AutoExpireFlashBag flash message container.
@ -18,6 +18,8 @@ namespace Symfony\Component\HttpFoundation;
*/ */
class AutoExpireFlashBag implements FlashBagInterface class AutoExpireFlashBag implements FlashBagInterface
{ {
private $name = 'flashes';
/** /**
* Flash messages. * Flash messages.
* *
@ -43,6 +45,19 @@ class AutoExpireFlashBag implements FlashBagInterface
$this->flashes = array('display' => array(), 'new' => array()); $this->flashes = array('display' => array(), 'new' => array());
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -149,4 +164,15 @@ class AutoExpireFlashBag implements FlashBagInterface
{ {
return $this->storageKey; return $this->storageKey;
} }
/**
* {@inheritdoc}
*/
public function clear()
{
$return = $this->popAll();
$this->flashes = array('display' => array(), 'new' => array());
return $return;
}
} }

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\HttpFoundation; namespace Symfony\Component\HttpFoundation\SessionFlash;
/** /**
* FlashBag flash message container. * FlashBag flash message container.
@ -18,6 +18,8 @@ namespace Symfony\Component\HttpFoundation;
*/ */
class FlashBag implements FlashBagInterface class FlashBag implements FlashBagInterface
{ {
private $name = 'flashes';
/** /**
* Flash messages. * Flash messages.
* *
@ -42,6 +44,19 @@ class FlashBag implements FlashBagInterface
$this->storageKey = $storageKey; $this->storageKey = $storageKey;
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -135,4 +150,12 @@ class FlashBag implements FlashBagInterface
{ {
return $this->storageKey; return $this->storageKey;
} }
/**
* {@inheritdoc}
*/
public function clear()
{
return $this->popAll();
}
} }

View File

@ -9,7 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\HttpFoundation; namespace Symfony\Component\HttpFoundation\SessionFlash;
use Symfony\Component\HttpFoundation\SessionBagInterface;
/** /**
* FlashBagInterface. * FlashBagInterface.

View File

@ -12,14 +12,14 @@
namespace Symfony\Component\HttpFoundation; namespace Symfony\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\SessionStorage\AttributeInterface; use Symfony\Component\HttpFoundation\SessionStorage\AttributeInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
/** /**
* Interface for the session. * Interface for the session.
* *
* @author Drak <drak@zikula.org> * @author Drak <drak@zikula.org>
*/ */
interface SessionInterface extends AttributeInterface, \Serializable interface SessionInterface extends \Serializable
{ {
/** /**
* Starts the session storage. * Starts the session storage.
@ -56,6 +56,59 @@ interface SessionInterface extends AttributeInterface, \Serializable
*/ */
function save(); function save();
/**
* Checks if an attribute is defined.
*
* @param string $name The attribute name
*
* @return Boolean true if the attribute is defined, false otherwise
*/
function has($name);
/**
* Returns an attribute.
*
* @param string $name The attribute name
* @param mixed $default The default value if not found.
*
* @return mixed
*/
function get($name, $default = null);
/**
* Sets an attribute.
*
* @param string $name
* @param mixed $value
*/
function set($name, $value);
/**
* Returns attributes.
*
* @return array Attributes
*/
function all();
/**
* Sets attributes.
*
* @param array $attributes Attributes
*/
function replace(array $attributes);
/**
* Removes an attribute.
*
* @param string $name
*/
function remove($name);
/**
* Clears all attributes.
*/
function clear();
/** /**
* Gets the flashbag interface. * Gets the flashbag interface.
* *

View File

@ -11,10 +11,10 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\AttributeBagInterface; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBagInterface;
use Symfony\Component\HttpFoundation\SessionBagInterface; use Symfony\Component\HttpFoundation\SessionBagInterface;
/** /**
@ -25,14 +25,11 @@ use Symfony\Component\HttpFoundation\SessionBagInterface;
abstract class AbstractSessionStorage implements SessionStorageInterface abstract class AbstractSessionStorage implements SessionStorageInterface
{ {
/** /**
* @var \Symfony\Component\HttpFoundation\FlashBagInterface * Array of SessionBagInterface
*
* @var array
*/ */
protected $flashBag; protected $bags;
/**
* @var \Symfony\Component\HttpFoundation\AttributeBagInterface
*/
protected $attributeBag;
/** /**
* @var array * @var array
@ -87,43 +84,15 @@ abstract class AbstractSessionStorage implements SessionStorageInterface
* upload_progress.min-freq, "1" * upload_progress.min-freq, "1"
* url_rewriter.tags, "a=href,area=href,frame=src,form=,fieldset=" * url_rewriter.tags, "a=href,area=href,frame=src,form=,fieldset="
* *
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
* @param array $options Session configuration options. * @param array $options Session configuration options.
*/ */
public function __construct(AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null, array $options = array()) public function __construct(array $options = array())
{ {
$this->attributeBag = $attributes ?: new AttributeBag();
$this->flashBag = $flashes ?: new FlashBag();
$this->setOptions($options); $this->setOptions($options);
$this->registerSaveHandlers(); $this->registerSaveHandlers();
$this->registerShutdownFunction(); $this->registerShutdownFunction();
} }
/**
* {@inheritdoc}
*/
public function getFlashes()
{
if ($this->options['auto_start'] && !$this->started) {
$this->start();
}
return $this->flashBag;
}
/**
* {@inheritdoc}
*/
public function getAttributes()
{
if ($this->options['auto_start'] && !$this->started) {
$this->start();
}
return $this->attributeBag;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -194,8 +163,9 @@ abstract class AbstractSessionStorage implements SessionStorageInterface
public function clear() public function clear()
{ {
// clear out the bags // clear out the bags
$this->attributeBag->clear(); foreach ($this->bags as $bag) {
$this->flashBag->popAll(); $bag->clear();
}
// clear out the session // clear out the session
$_SESSION = array(); $_SESSION = array();
@ -204,6 +174,38 @@ abstract class AbstractSessionStorage implements SessionStorageInterface
$this->loadSession(); $this->loadSession();
} }
/**
* Register a SessionBagInterface for use.
*
* @param SessionBagInterface $bag
*/
public function registerBag(SessionBagInterface $bag)
{
$this->bags[$bag->getName()] = $bag;
}
/**
* Gets a bag by name.
*
* @param string $name
*
* @return SessionBagInterface
*
* @throws \InvalidArgumentException
*/
public function getBag($name)
{
if (!isset($this->bags[$name])) {
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
}
if ($this->options['auto_start'] && !$this->started) {
$this->start();
}
return $this->bags[$name];
}
/** /**
* Sets session.* ini variables. * Sets session.* ini variables.
* *
@ -326,22 +328,16 @@ abstract class AbstractSessionStorage implements SessionStorageInterface
* PHP takes the return value from the sessionRead() handler, unserializes it * PHP takes the return value from the sessionRead() handler, unserializes it
* and populates $_SESSION with the result automatically. * and populates $_SESSION with the result automatically.
*/ */
protected function loadSession() protected function loadSession(array &$session = null)
{ {
$this->link($this->attributeBag, $_SESSION); if (null === $session) {
$this->link($this->flashBag, $_SESSION); $session = &$_SESSION;
} }
/** foreach ($this->bags as $bag) {
* Link a bag to the session.
*
* @param SessionBagInterface $bag
* @param array &$array
*/
protected function link(SessionBagInterface $bag, array &$array)
{
$key = $bag->getStorageKey(); $key = $bag->getStorageKey();
$array[$key] = isset($array[$key]) ? $array[$key] : array(); $session[$key] = isset($session[$key]) ? $session[$key] : array();
$bag->initialize($array[$key]); $bag->initialize($session[$key]);
}
} }
} }

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* MemcacheSessionStorage. * MemcacheSessionStorage.
* *
@ -48,12 +45,10 @@ class MemcacheSessionStorage extends AbstractSessionStorage implements SessionSa
* @param \Memcache $memcache A \Memcache instance * @param \Memcache $memcache A \Memcache instance
* @param array $memcacheOptions An associative array of Memcachge options * @param array $memcacheOptions An associative array of Memcachge options
* @param array $options Session configuration options. * @param array $options Session configuration options.
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
* *
* @see AbstractSessionStorage::__construct() * @see AbstractSessionStorage::__construct()
*/ */
public function __construct(\Memcache $memcache, array $memcacheOptions = array(), array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct(\Memcache $memcache, array $memcacheOptions = array(), array $options = array())
{ {
$this->memcache = $memcache; $this->memcache = $memcache;
@ -72,7 +67,7 @@ class MemcacheSessionStorage extends AbstractSessionStorage implements SessionSa
$this->memcacheOptions = $memcacheOptions; $this->memcacheOptions = $memcacheOptions;
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
protected function addServer(array $server) protected function addServer(array $server)

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* MemcachedSessionStorage. * MemcachedSessionStorage.
* *
@ -41,12 +38,10 @@ class MemcachedSessionStorage extends AbstractSessionStorage implements SessionS
* @param \Memcached $memcached A \Memcached instance * @param \Memcached $memcached A \Memcached instance
* @param array $memcachedOptions An associative array of Memcached options * @param array $memcachedOptions An associative array of Memcached options
* @param array $options Session configuration options. * @param array $options Session configuration options.
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
* *
* @see AbstractSessionStorage::__construct() * @see AbstractSessionStorage::__construct()
*/ */
public function __construct(\Memcached $memcache, array $memcachedOptions = array(), array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct(\Memcached $memcache, array $memcachedOptions = array(), array $options = array())
{ {
$this->memcached = $memcached; $this->memcached = $memcached;
@ -66,7 +61,7 @@ class MemcachedSessionStorage extends AbstractSessionStorage implements SessionS
$this->memcacheOptions = $memcachedOptions; $this->memcacheOptions = $memcachedOptions;
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
/** /**

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* MockArraySessionStorage mocks the session for unit tests. * MockArraySessionStorage mocks the session for unit tests.
* *
@ -36,31 +33,11 @@ class MockArraySessionStorage extends AbstractSessionStorage
/** /**
* @var array * @var array
*/ */
private $attributes = array(); private $sessionData = array();
/** public function setSessionData(array $array)
* @var array
*/
private $flashes = array();
/**
* Injects array of attributes to simulate retrieval of existing session.
*
* @param array $array
*/
public function setAttributes(array $array)
{ {
$this->attributes = $array; $this->sessionData = $array;
}
/**
* Injects array of flashes to simulate retrieval of existing session.
*
* @param array $array
*/
public function setFlashes(array $array)
{
$this->flashes = $array;
} }
/** /**
@ -73,14 +50,15 @@ class MockArraySessionStorage extends AbstractSessionStorage
} }
$this->started = true; $this->started = true;
$this->attributeBag->initialize($this->attributes); $this->loadSession($this->sessionData);
$this->flashBag->initialize($this->flashes);
$this->sessionId = $this->generateSessionId(); $this->sessionId = $this->generateSessionId();
session_id($this->sessionId); session_id($this->sessionId);
return true; return true;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -117,6 +95,23 @@ class MockArraySessionStorage extends AbstractSessionStorage
$this->closed = false; $this->closed = false;
} }
/**
* {@inheritdoc}
*/
public function clear()
{
// clear out the bags
foreach ($this->bags as $bag) {
$bag->clear();
}
// clear out the session
$this->sessionData = array();
// reconnect the bags to the session
$this->loadSession($this->sessionData);
}
/** /**
* Generates a session ID. * Generates a session ID.
* *

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* MockFileSessionStorage is used to mock sessions for * MockFileSessionStorage is used to mock sessions for
* functional testing when done in a single PHP process. * functional testing when done in a single PHP process.
@ -25,11 +22,6 @@ use Symfony\Component\HttpFoundation\FlashBagInterface;
*/ */
class MockFileSessionStorage extends MockArraySessionStorage class MockFileSessionStorage extends MockArraySessionStorage
{ {
/**
* @var array
*/
private $sessionData = array();
/** /**
* @var string * @var string
*/ */
@ -40,12 +32,10 @@ class MockFileSessionStorage extends MockArraySessionStorage
* *
* @param string $savePath Path of directory to save session files. * @param string $savePath Path of directory to save session files.
* @param array $options Session options. * @param array $options Session options.
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
* *
* @see AbstractSessionStorage::__construct() * @see AbstractSessionStorage::__construct()
*/ */
public function __construct($savePath = null, array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct($savePath = null, array $options = array())
{ {
if (null === $savePath) { if (null === $savePath) {
$savePath = sys_get_temp_dir(); $savePath = sys_get_temp_dir();
@ -57,7 +47,7 @@ class MockFileSessionStorage extends MockArraySessionStorage
$this->savePath = $savePath; $this->savePath = $savePath;
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
/** /**
@ -141,8 +131,6 @@ class MockFileSessionStorage extends MockArraySessionStorage
$filePath = $this->getFilePath(); $filePath = $this->getFilePath();
$this->sessionData = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : array(); $this->sessionData = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : array();
$this->link($this->attributeBag, $this->sessionData); $this->loadSession($this->sessionData);
$this->link($this->flashBag, $this->sessionData);
} }
} }

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* NativeFileSessionStorage. * NativeFileSessionStorage.
* *
@ -33,12 +30,10 @@ class NativeFileSessionStorage extends AbstractSessionStorage
* *
* @param string $savePath Path of directory to save session files. * @param string $savePath Path of directory to save session files.
* @param array $options Session configuration options. * @param array $options Session configuration options.
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
* *
* @see AbstractSessionStorage::__construct() * @see AbstractSessionStorage::__construct()
*/ */
public function __construct($savePath = null, array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct($savePath = null, array $options = array())
{ {
if (null === $savePath) { if (null === $savePath) {
$savePath = sys_get_temp_dir(); $savePath = sys_get_temp_dir();
@ -50,7 +45,7 @@ class NativeFileSessionStorage extends AbstractSessionStorage
$this->savePath = $savePath; $this->savePath = $savePath;
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
/** /**

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* NativeMemcacheSessionStorage. * NativeMemcacheSessionStorage.
* *
@ -33,19 +30,17 @@ class NativeMemcacheSessionStorage extends AbstractSessionStorage
* *
* @param string $savePath Path of memcache server. * @param string $savePath Path of memcache server.
* @param array $options Session configuration options. * @param array $options Session configuration options.
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
* *
* @see AbstractSessionStorage::__construct() * @see AbstractSessionStorage::__construct()
*/ */
public function __construct($savePath = 'tcp://127.0.0.1:11211?persistent=0', array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct($savePath = 'tcp://127.0.0.1:11211?persistent=0', array $options = array())
{ {
if (!extension_loaded('memcache')) { if (!extension_loaded('memcache')) {
throw new \RuntimeException('PHP does not have "memcache" session module registered'); throw new \RuntimeException('PHP does not have "memcache" session module registered');
} }
$this->savePath = $savePath; $this->savePath = $savePath;
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
/** /**

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* NativeMemcachedSessionStorage. * NativeMemcachedSessionStorage.
* *
@ -33,19 +30,17 @@ class NativeMemcachedSessionStorage extends AbstractSessionStorage
* *
* @param string $savePath Comma separated list of servers: e.g. memcache1.example.com:11211,memcache2.example.com:11211 * @param string $savePath Comma separated list of servers: e.g. memcache1.example.com:11211,memcache2.example.com:11211
* @param array $options Session configuration options. * @param array $options Session configuration options.
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for defaul FlashBag)
* *
* @see AbstractSessionStorage::__construct() * @see AbstractSessionStorage::__construct()
*/ */
public function __construct($savePath = '127.0.0.1:11211', array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct($savePath = '127.0.0.1:11211', array $options = array())
{ {
if (!extension_loaded('memcached')) { if (!extension_loaded('memcached')) {
throw new \RuntimeException('PHP does not have "memcached" session module registered'); throw new \RuntimeException('PHP does not have "memcached" session module registered');
} }
$this->savePath = $savePath; $this->savePath = $savePath;
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
/** /**

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* NativeSqliteSessionStorage. * NativeSqliteSessionStorage.
* *
@ -33,19 +30,17 @@ class NativeSqliteSessionStorage extends AbstractSessionStorage
* *
* @param string $dbPath Path to SQLite database file. * @param string $dbPath Path to SQLite database file.
* @param array $options Session configuration options. * @param array $options Session configuration options.
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for defaul FlashBag)
* *
* @see AbstractSessionStorage::__construct() * @see AbstractSessionStorage::__construct()
*/ */
public function __construct($dbPath, array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct($dbPath, array $options = array())
{ {
if (!extension_loaded('sqlite')) { if (!extension_loaded('sqlite')) {
throw new \RuntimeException('PHP does not have "sqlite" session module registered'); throw new \RuntimeException('PHP does not have "sqlite" session module registered');
} }
$this->dbPath = $dbPath; $this->dbPath = $dbPath;
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
/** /**

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* NullSessionStorage. * NullSessionStorage.
* *

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/** /**
* PdoSessionStorage. * PdoSessionStorage.
* *
@ -44,14 +41,12 @@ class PdoSessionStorage extends AbstractSessionStorage implements SessionSaveHan
* @param \PDO $pdo A \PDO instance * @param \PDO $pdo A \PDO instance
* @param array $dbOptions An associative array of DB options * @param array $dbOptions An associative array of DB options
* @param array $options Session configuration options * @param array $options Session configuration options
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for defaul FlashBag)
* *
* @throws \InvalidArgumentException When "db_table" option is not provided * @throws \InvalidArgumentException When "db_table" option is not provided
* *
* @see AbstractSessionStorage::__construct() * @see AbstractSessionStorage::__construct()
*/ */
public function __construct(\PDO $pdo, array $dbOptions = array(), array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) public function __construct(\PDO $pdo, array $dbOptions = array(), array $options = array())
{ {
if (!array_key_exists('db_table', $dbOptions)) { if (!array_key_exists('db_table', $dbOptions)) {
throw new \InvalidArgumentException('You must provide the "db_table" option for a PdoSessionStorage.'); throw new \InvalidArgumentException('You must provide the "db_table" option for a PdoSessionStorage.');
@ -64,7 +59,7 @@ class PdoSessionStorage extends AbstractSessionStorage implements SessionSaveHan
'db_time_col' => 'sess_time', 'db_time_col' => 'sess_time',
), $dbOptions); ), $dbOptions);
parent::__construct($attributes, $flashes, $options); parent::__construct($options);
} }
/** /**

View File

@ -27,7 +27,7 @@ namespace Symfony\Component\HttpFoundation\SessionStorage;
* automatically when PHP starts, but these can be overriden using * automatically when PHP starts, but these can be overriden using
* this command if you need anything other than PHP's default handling. * this command if you need anything other than PHP's default handling.
* *
* When the session starts, PHP will call the sessionRead() handler * When the session starts, PHP will call the readSession() handler
* which should return a string extactly as stored (which will have * which should return a string extactly as stored (which will have
* been encoded by PHP using a special session serializer session_decode() * been encoded by PHP using a special session serializer session_decode()
* which is different to the serialize() function. PHP will then populate * which is different to the serialize() function. PHP will then populate
@ -38,16 +38,16 @@ namespace Symfony\Component\HttpFoundation\SessionStorage;
* be stored. * be stored.
* *
* When a session is specifically destroyed, PHP will call the * When a session is specifically destroyed, PHP will call the
* sessionDestroy() handler with the session ID. This happens when the * sessionSession() handler with the session ID. This happens when the
* session is regenerated for example and th handler MUST delete the * session is regenerated for example and th handler MUST delete the
* session by ID from the persistent storage immediately. * session by ID from the persistent storage immediately.
* *
* PHP will call sessionGc() from time to time to expire any session * PHP will call sessionSession() from time to time to expire any session
* records according to the set max lifetime of a session. This routine * records according to the set max lifetime of a session. This routine
* should delete all records from persistent storage which were last * should delete all records from persistent storage which were last
* accessed longer than the $lifetime. * accessed longer than the $lifetime.
* *
* PHP sessionOpen() and sessionClose() are pretty much redundant and * PHP openSession() and closeSession() are pretty much redundant and
* can return true. * can return true.
* *
* @author Drak <drak@zikula.org> * @author Drak <drak@zikula.org>

View File

@ -11,8 +11,7 @@
namespace Symfony\Component\HttpFoundation\SessionStorage; namespace Symfony\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionBagInterface;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
/** /**
* SessionStorageInterface. * SessionStorageInterface.
@ -78,16 +77,14 @@ interface SessionStorageInterface
function clear(); function clear();
/** /**
* Gets the FlashBagInterface driver. * Gets a SessionBagInterface by name.
* *
* @return FlashBagInterface * @return SessionBagInterface
*/ */
function getFlashes(); function getBag($name);
/** /**
* Gets the AttributeBagInterface driver. * Registers a SessionBagInterface for use.
*
* @return AttributeBagInterface
*/ */
function getAttributes(); function registerBag(SessionBagInterface $bag);
} }

View File

@ -15,8 +15,6 @@ namespace Symfony\Tests\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage;
use Symfony\Component\HttpFoundation\Session; use Symfony\Component\HttpFoundation\Session;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\FlashBag;
use Symfony\Component\HttpFoundation\AttributeBag;
class RequestTest extends \PHPUnit_Framework_TestCase class RequestTest extends \PHPUnit_Framework_TestCase
{ {
@ -848,7 +846,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$request = new Request; $request = new Request;
$this->assertFalse($request->hasSession()); $this->assertFalse($request->hasSession());
$request->setSession(new Session(new MockArraySessionStorage(new AttributeBag(), new FlashBag()))); $request->setSession(new Session(new MockArraySessionStorage()));
$this->assertTrue($request->hasSession()); $this->assertTrue($request->hasSession());
} }
@ -859,7 +857,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($request->hasPreviousSession()); $this->assertFalse($request->hasPreviousSession());
$request->cookies->set(session_name(), 'foo'); $request->cookies->set(session_name(), 'foo');
$this->assertFalse($request->hasPreviousSession()); $this->assertFalse($request->hasPreviousSession());
$request->setSession(new Session(new MockArraySessionStorage(new AttributeBag(), new FlashBag()))); $request->setSession(new Session(new MockArraySessionStorage()));
$this->assertTrue($request->hasPreviousSession()); $this->assertTrue($request->hasPreviousSession());
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace Symfony\Tests\Component\HttpFoundation; namespace Symfony\Tests\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
/** /**

View File

@ -2,7 +2,7 @@
namespace Symfony\Tests\Component\HttpFoundation; namespace Symfony\Tests\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\NamespacedAttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\NamespacedAttributeBag;
/** /**
* Tests NamespacedAttributeBag * Tests NamespacedAttributeBag

View File

@ -11,8 +11,8 @@
namespace Symfony\Tests\Component\HttpFoundation; namespace Symfony\Tests\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\AutoExpireFlashBag as FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\AutoExpireFlashBag as FlashBag;
use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
/** /**
* AutoExpireFlashBagTest * AutoExpireFlashBagTest
@ -22,7 +22,7 @@ use Symfony\Component\HttpFoundation\FlashBagInterface;
class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var \Symfony\Component\HttpFoundation\FlashBagInterface * @var \Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface
*/ */
private $bag; private $bag;

View File

@ -11,8 +11,8 @@
namespace Symfony\Tests\Component\HttpFoundation; namespace Symfony\Tests\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
/** /**
* FlashBagTest * FlashBagTest
@ -22,7 +22,7 @@ use Symfony\Component\HttpFoundation\FlashBagInterface;
class FlashBagTest extends \PHPUnit_Framework_TestCase class FlashBagTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var \Symfony\Component\HttpFoundation\FlashBagInterface * @var \Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface
*/ */
private $bag; private $bag;

View File

@ -3,6 +3,8 @@
namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; namespace Symfony\Tests\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\AbstractSessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\AbstractSessionStorage;
use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\SessionStorage\SessionSaveHandlerInterface; use Symfony\Component\HttpFoundation\SessionStorage\SessionSaveHandlerInterface;
/** /**
@ -57,19 +59,27 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
*/ */
protected function getStorage() protected function getStorage()
{ {
return new CustomHandlerSessionStorage(); $storage = new CustomHandlerSessionStorage();
$storage->registerBag(new AttributeBag);
return $storage;
} }
public function testGetFlashBag() public function testBag()
{ {
$storage = $this->getStorage(); $storage = $this->getStorage();
$this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes()); $bag = new FlashBag();
$storage->registerBag($bag);
$this->assertSame($bag, $storage->getBag($bag->getName()));
} }
public function testGetAttributeBag() /**
* @expectedException \InvalidArgumentException
*/
public function testRegisterBagException()
{ {
$storage = $this->getStorage(); $storage = $this->getStorage();
$this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes()); $storage->getBag('non_existing');
} }
public function testGetId() public function testGetId()
@ -85,10 +95,10 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
$storage = $this->getStorage(); $storage = $this->getStorage();
$storage->start(); $storage->start();
$id = $storage->getId(); $id = $storage->getId();
$storage->getAttributes()->set('lucky', 7); $storage->getBag('attributes')->set('lucky', 7);
$storage->regenerate(); $storage->regenerate();
$this->assertNotEquals($id, $storage->getId()); $this->assertNotEquals($id, $storage->getId());
$this->assertEquals(7, $storage->getAttributes()->get('lucky')); $this->assertEquals(7, $storage->getBag('attributes')->get('lucky'));
} }
@ -97,10 +107,10 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
$storage = $this->getStorage(); $storage = $this->getStorage();
$storage->start(); $storage->start();
$id = $storage->getId(); $id = $storage->getId();
$storage->getAttributes()->set('legs', 11); $storage->getBag('attributes')->set('legs', 11);
$storage->regenerate(true); $storage->regenerate(true);
$this->assertNotEquals($id, $storage->getId()); $this->assertNotEquals($id, $storage->getId());
$this->assertEquals(11, $storage->getAttributes()->get('legs')); $this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
} }
public function testCustomSaveHandlers() public function testCustomSaveHandlers()

View File

@ -3,8 +3,8 @@
namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; namespace Symfony\Tests\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
/** /**
@ -29,17 +29,27 @@ class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase
*/ */
private $flashes; private $flashes;
private $data;
protected function setUp() protected function setUp()
{ {
$this->attributes = array('foo' => 'bar'); $this->attributes = new AttributeBag();
$this->flashes = array('notice' => 'hello'); $this->flashes = new FlashBag();
$this->storage = new MockArraySessionStorage(new AttributeBag(), new FlashBag());
$this->storage->setFlashes($this->flashes); $this->data = array(
$this->storage->setAttributes($this->attributes); $this->attributes->getStorageKey() => array('foo' => 'bar'),
$this->flashes->getStorageKey() => array('notice' => 'hello'),
);
$this->storage = new MockArraySessionStorage();
$this->storage->registerBag($this->flashes);
$this->storage->registerBag($this->attributes);
$this->storage->setSessionData($this->data);
} }
protected function tearDown() protected function tearDown()
{ {
$this->data = null;
$this->flashes = null; $this->flashes = null;
$this->attributes = null; $this->attributes = null;
$this->storage = null; $this->storage = null;
@ -61,14 +71,14 @@ class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase
$id = $this->storage->getId(); $id = $this->storage->getId();
$this->storage->regenerate(); $this->storage->regenerate();
$this->assertNotEquals($id, $this->storage->getId()); $this->assertNotEquals($id, $this->storage->getId());
$this->assertEquals($this->attributes, $this->storage->getAttributes()->all()); $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
$this->assertEquals($this->flashes, $this->storage->getFlashes()->all()); $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->all());
$id = $this->storage->getId(); $id = $this->storage->getId();
$this->storage->regenerate(true); $this->storage->regenerate(true);
$this->assertNotEquals($id, $this->storage->getId()); $this->assertNotEquals($id, $this->storage->getId());
$this->assertEquals($this->attributes, $this->storage->getAttributes()->all()); $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
$this->assertEquals($this->flashes, $this->storage->getFlashes()->all()); $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->all());
} }
public function testGetId() public function testGetId()

View File

@ -3,6 +3,8 @@
namespace Symfony\Test\Component\HttpFoundation\SessionStorage; namespace Symfony\Test\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\MockFileSessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\MockFileSessionStorage;
use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
/** /**
* Test class for MockFileSessionStorage. * Test class for MockFileSessionStorage.
@ -50,11 +52,11 @@ class MockFileSessionStorageTest extends \PHPUnit_Framework_TestCase
public function testRegenerate() public function testRegenerate()
{ {
$this->storage->start(); $this->storage->start();
$this->storage->getAttributes()->set('regenerate', 1234); $this->storage->getBag('attributes')->set('regenerate', 1234);
$this->storage->regenerate(); $this->storage->regenerate();
$this->assertEquals(1234, $this->storage->getAttributes()->get('regenerate')); $this->assertEquals(1234, $this->storage->getBag('attributes')->get('regenerate'));
$this->storage->regenerate(true); $this->storage->regenerate(true);
$this->assertEquals(1234, $this->storage->getAttributes()->get('regenerate')); $this->assertEquals(1234, $this->storage->getBag('attributes')->get('regenerate'));
} }
public function testGetId() public function testGetId()
@ -67,33 +69,37 @@ class MockFileSessionStorageTest extends \PHPUnit_Framework_TestCase
public function testSave() public function testSave()
{ {
$this->storage->start(); $this->storage->start();
$this->assertNotEquals('108', $this->storage->getAttributes()->get('new')); $this->assertNotEquals('108', $this->storage->getBag('attributes')->get('new'));
$this->assertFalse($this->storage->getFlashes()->has('newkey')); $this->assertFalse($this->storage->getBag('flashes')->has('newkey'));
$this->storage->getAttributes()->set('new', '108'); $this->storage->getBag('attributes')->set('new', '108');
$this->storage->getFlashes()->set('newkey', 'test'); $this->storage->getBag('flashes')->set('newkey', 'test');
$this->storage->save(); $this->storage->save();
$storage = $this->getStorage(); $storage = $this->getStorage();
$storage->start(); $storage->start();
$this->assertEquals('108', $storage->getAttributes()->get('new')); $this->assertEquals('108', $storage->getBag('attributes')->get('new'));
$this->assertTrue($storage->getFlashes()->has('newkey')); $this->assertTrue($storage->getBag('flashes')->has('newkey'));
$this->assertEquals('test', $storage->getFlashes()->get('newkey')); $this->assertEquals('test', $storage->getBag('flashes')->get('newkey'));
} }
public function testMultipleInstances() public function testMultipleInstances()
{ {
$storage1 = $this->getStorage(); $storage1 = $this->getStorage();
$storage1->start(); $storage1->start();
$storage1->getAttributes()->set('foo', 'bar'); $storage1->getBag('attributes')->set('foo', 'bar');
$storage1->save(); $storage1->save();
$storage2 = $this->getStorage(); $storage2 = $this->getStorage();
$storage2->start(); $storage2->start();
$this->assertEquals('bar', $storage2->getAttributes()->get('foo'), 'values persist between instances'); $this->assertEquals('bar', $storage2->getBag('attributes')->get('foo'), 'values persist between instances');
} }
private function getStorage(array $options = array()) private function getStorage(array $options = array())
{ {
return new MockFileSessionStorage($this->sessionDir, $options); $storage = new MockFileSessionStorage($this->sessionDir, $options);
$storage->registerBag(new FlashBag);
$storage->registerBag(new AttributeBag);
return $storage;
} }
} }

View File

@ -3,8 +3,8 @@
namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; namespace Symfony\Tests\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\NativeFileSessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\NativeFileSessionStorage;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
/** /**
* Test class for NativeFileSessionStorage. * Test class for NativeFileSessionStorage.
@ -15,23 +15,11 @@ use Symfony\Component\HttpFoundation\FlashBag;
*/ */
class NativeFileSessionStorageTest extends \PHPUnit_Framework_TestCase class NativeFileSessionStorageTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructDefaults()
{
$storage = new NativeFileSessionStorage();
$this->assertEquals('files', ini_get('session.save_handler'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes());
}
public function testSaveHandlers() public function testSaveHandlers()
{ {
$attributeBag = new AttributeBag(); $storage = new NativeFileSessionStorage(sys_get_temp_dir(), array('name' => 'TESTING'));
$flashBag = new FlashBag();
$storage = new NativeFileSessionStorage(sys_get_temp_dir(), array('name' => 'TESTING'), $attributeBag, $flashBag);
$this->assertEquals('files', ini_get('session.save_handler')); $this->assertEquals('files', ini_get('session.save_handler'));
$this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path')); $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
$this->assertEquals('TESTING', ini_get('session.name')); $this->assertEquals('TESTING', ini_get('session.name'));
$this->assertSame($attributeBag, $storage->getAttributes());
$this->assertSame($flashBag, $storage->getFlashes());
} }
} }

View File

@ -3,8 +3,8 @@
namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; namespace Symfony\Tests\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\NativeMemcacheSessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\NativeMemcacheSessionStorage;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
/** /**
* Test class for NativeMemcacheSessionStorage. * Test class for NativeMemcacheSessionStorage.
@ -15,31 +15,15 @@ use Symfony\Component\HttpFoundation\FlashBag;
*/ */
class NativeMemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase class NativeMemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructDefaults()
{
if (!extension_loaded('memcache')) {
$this->markTestSkipped('Skipped tests SQLite extension is not present');
}
$storage = new NativeMemcacheSessionStorage('tcp://127.0.0.1:11211?persistent=0');
$this->assertEquals('memcache', ini_get('session.save_handler'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes());
}
public function testSaveHandlers() public function testSaveHandlers()
{ {
if (!extension_loaded('memcache')) { if (!extension_loaded('memcache')) {
$this->markTestSkipped('Skipped tests SQLite extension is not present'); $this->markTestSkipped('Skipped tests SQLite extension is not present');
} }
$attributeBag = new AttributeBag(); $storage = new NativeMemcacheSessionStorage('tcp://127.0.0.1:11211?persistent=0', array('name' => 'TESTING'));
$flashBag = new FlashBag();
$storage = new NativeMemcacheSessionStorage('tcp://127.0.0.1:11211?persistent=0', array('name' => 'TESTING'), $attributeBag, $flashBag);
$this->assertEquals('memcache', ini_get('session.save_handler')); $this->assertEquals('memcache', ini_get('session.save_handler'));
$this->assertEquals('tcp://127.0.0.1:11211?persistent=0', ini_get('session.save_path')); $this->assertEquals('tcp://127.0.0.1:11211?persistent=0', ini_get('session.save_path'));
$this->assertEquals('TESTING', ini_get('session.name')); $this->assertEquals('TESTING', ini_get('session.name'));
$this->assertSame($attributeBag, $storage->getAttributes());
$this->assertSame($flashBag, $storage->getFlashes());
} }
} }

View File

@ -3,8 +3,8 @@
namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; namespace Symfony\Tests\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\NativeMemcachedSessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\NativeMemcachedSessionStorage;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
/** /**
* Test class for NativeMemcachedSessionStorage. * Test class for NativeMemcachedSessionStorage.
@ -15,40 +15,20 @@ use Symfony\Component\HttpFoundation\FlashBag;
*/ */
class NativeMemcachedSessionStorageTest extends \PHPUnit_Framework_TestCase class NativeMemcachedSessionStorageTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructDefaults()
{
if (!extension_loaded('memcached')) {
$this->markTestSkipped('Skipped tests SQLite extension is not present');
}
// test takes too long if memcached server is not running
ini_set('memcached.sess_locking', '0');
$storage = new NativeMemcachedSessionStorage('127.0.0.1:11211');
$this->assertEquals('memcached', ini_get('session.save_handler'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes());
}
public function testSaveHandlers() public function testSaveHandlers()
{ {
if (!extension_loaded('memcached')) { if (!extension_loaded('memcached')) {
$this->markTestSkipped('Skipped tests SQLite extension is not present'); $this->markTestSkipped('Skipped tests SQLite extension is not present');
} }
$attributeBag = new AttributeBag();
$flashBag = new FlashBag();
// test takes too long if memcached server is not running // test takes too long if memcached server is not running
ini_set('memcached.sess_locking', '0'); ini_set('memcached.sess_locking', '0');
$storage = new NativeMemcachedSessionStorage('127.0.0.1:11211', array('name' => 'TESTING'), $attributeBag, $flashBag); $storage = new NativeMemcachedSessionStorage('127.0.0.1:11211', array('name' => 'TESTING'));
$this->assertEquals('memcached', ini_get('session.save_handler')); $this->assertEquals('memcached', ini_get('session.save_handler'));
$this->assertEquals('127.0.0.1:11211', ini_get('session.save_path')); $this->assertEquals('127.0.0.1:11211', ini_get('session.save_path'));
$this->assertEquals('TESTING', ini_get('session.name')); $this->assertEquals('TESTING', ini_get('session.name'));
$this->assertSame($attributeBag, $storage->getAttributes());
$this->assertSame($flashBag, $storage->getFlashes());
} }
} }

View File

@ -3,8 +3,8 @@
namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; namespace Symfony\Tests\Component\HttpFoundation\SessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\NativeSqliteSessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\NativeSqliteSessionStorage;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
/** /**
* Test class for NativeSqliteSessionStorage. * Test class for NativeSqliteSessionStorage.
@ -15,32 +15,16 @@ use Symfony\Component\HttpFoundation\FlashBag;
*/ */
class NativeSqliteSessionStorageTest extends \PHPUnit_Framework_TestCase class NativeSqliteSessionStorageTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructDefaults()
{
if (!extension_loaded('sqlite')) {
$this->markTestSkipped('Skipped tests SQLite extension is not present');
}
$storage = new NativeSqliteSessionStorage(sys_get_temp_dir().'/sqlite.db');
$this->assertEquals('sqlite', ini_get('session.save_handler'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes());
}
public function testSaveHandlers() public function testSaveHandlers()
{ {
if (!extension_loaded('sqlite')) { if (!extension_loaded('sqlite')) {
$this->markTestSkipped('Skipped tests SQLite extension is not present'); $this->markTestSkipped('Skipped tests SQLite extension is not present');
} }
$attributeBag = new AttributeBag(); $storage = new NativeSqliteSessionStorage(sys_get_temp_dir().'/sqlite.db', array('name' => 'TESTING'));
$flashBag = new FlashBag();
$storage = new NativeSqliteSessionStorage(sys_get_temp_dir().'/sqlite.db', array('name' => 'TESTING'), $attributeBag, $flashBag);
$this->assertEquals('sqlite', ini_get('session.save_handler')); $this->assertEquals('sqlite', ini_get('session.save_handler'));
$this->assertEquals(sys_get_temp_dir().'/sqlite.db', ini_get('session.save_path')); $this->assertEquals(sys_get_temp_dir().'/sqlite.db', ini_get('session.save_path'));
$this->assertEquals('TESTING', ini_get('session.name')); $this->assertEquals('TESTING', ini_get('session.name'));
$this->assertSame($attributeBag, $storage->getAttributes());
$this->assertSame($flashBag, $storage->getFlashes());
} }
} }

View File

@ -13,14 +13,6 @@ use Symfony\Component\HttpFoundation\Session;
*/ */
class NullSessionStorageTest extends \PHPUnit_Framework_TestCase class NullSessionStorageTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructDefaults()
{
$storage = new NullSessionStorage();
$this->assertEquals('user', ini_get('session.save_handler'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes());
}
public function testSaveHandlers() public function testSaveHandlers()
{ {
$storage = new NullSessionStorage(); $storage = new NullSessionStorage();

View File

@ -12,10 +12,10 @@
namespace Symfony\Tests\Component\HttpFoundation; namespace Symfony\Tests\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\Session; use Symfony\Component\HttpFoundation\Session;
use Symfony\Component\HttpFoundation\FlashBag; use Symfony\Component\HttpFoundation\SessionFlash\FlashBag;
use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface;
use Symfony\Component\HttpFoundation\AttributeBag; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag;
use Symfony\Component\HttpFoundation\AttributeBagInterface; use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBagInterface;
use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage;
/** /**
@ -39,8 +39,8 @@ class SessionTest extends \PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
$this->storage = new MockArraySessionStorage(new AttributeBag(), new FlashBag()); $this->storage = new MockArraySessionStorage();
$this->session = new Session($this->storage); $this->session = new Session($this->storage, new AttributeBag(), new FlashBag());
} }
protected function tearDown() protected function tearDown()