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;
/**
* @author Fabien Potencier <fabien@symfony.com>
private $flashName;
private $attributeName;
private $data = array();
- private $hasBeenStarted;
+ private $usageIndex = 0;
/**
* @param SessionStorageInterface $storage A SessionStorageInterface instance
*/
public function count()
{
- return count($this->getAttributeBag()->all());
+ return \count($this->getAttributeBag()->all());
}
/**
- * @return bool
+ * @return int
*
* @internal
*/
- public function hasBeenStarted()
+ public function getUsageIndex()
{
- return $this->hasBeenStarted;
+ return $this->usageIndex;
}
/**
*/
public function isEmpty()
{
+ if ($this->isStarted()) {
+ ++$this->usageIndex;
+ }
foreach ($this->data as &$data) {
if (!empty($data)) {
return false;
*/
public function setId($id)
{
- $this->storage->setId($id);
+ if ($this->storage->getId() !== $id) {
+ $this->storage->setId($id);
+ }
}
/**
*/
public function getMetadataBag()
{
+ ++$this->usageIndex;
+
return $this->storage->getMetadataBag();
}
*/
public function registerBag(SessionBagInterface $bag)
{
- $this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->hasBeenStarted));
+ $this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->usageIndex));
}
/**