use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
/**
- * 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 $hasBeenStarted;
/**
- * 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)
*/
public function has($name)
{
- return $this->storage->getBag($this->attributeName)->has($name);
+ return $this->getAttributeBag()->has($name);
}
/**
*/
public function get($name, $default = null)
{
- return $this->storage->getBag($this->attributeName)->get($name, $default);
+ return $this->getAttributeBag()->get($name, $default);
}
/**
*/
public function set($name, $value)
{
- $this->storage->getBag($this->attributeName)->set($name, $value);
+ $this->getAttributeBag()->set($name, $value);
}
/**
*/
public function all()
{
- return $this->storage->getBag($this->attributeName)->all();
+ return $this->getAttributeBag()->all();
}
/**
*/
public function replace(array $attributes)
{
- $this->storage->getBag($this->attributeName)->replace($attributes);
+ $this->getAttributeBag()->replace($attributes);
}
/**
*/
public function remove($name)
{
- return $this->storage->getBag($this->attributeName)->remove($name);
+ return $this->getAttributeBag()->remove($name);
}
/**
*/
public function clear()
{
- $this->storage->getBag($this->attributeName)->clear();
+ $this->getAttributeBag()->clear();
}
/**
*/
public function getIterator()
{
- return new \ArrayIterator($this->storage->getBag($this->attributeName)->all());
+ return new \ArrayIterator($this->getAttributeBag()->all());
}
/**
*/
public function count()
{
- return count($this->storage->getBag($this->attributeName)->all());
+ return count($this->getAttributeBag()->all());
+ }
+
+ /**
+ * @return bool
+ *
+ * @internal
+ */
+ public function hasBeenStarted()
+ {
+ return $this->hasBeenStarted;
+ }
+
+ /**
+ * @return bool
+ *
+ * @internal
+ */
+ public function isEmpty()
+ {
+ foreach ($this->data as &$data) {
+ if (!empty($data)) {
+ return false;
+ }
+ }
+
+ return true;
}
/**
*/
public function registerBag(SessionBagInterface $bag)
{
- $this->storage->registerBag($bag);
+ $this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->hasBeenStarted));
}
/**
*/
public function getBag($name)
{
- return $this->storage->getBag($name);
+ return $this->storage->getBag($name)->getBag();
}
/**
{
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);
+ }
}