Skip to content

Commit

Permalink
[HttpFoundation] Remove hard coded assumptions and replace with API c…
Browse files Browse the repository at this point in the history
…alls.
  • Loading branch information
Drak committed Mar 15, 2012
1 parent 9a5fc65 commit eb9bf05
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/Symfony/Component/HttpFoundation/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class Session implements SessionInterface
*/
protected $storage;

/**
* @var string
*/
private $flashName;

/**
* @var string
*/
private $attributeName;

/**
* Constructor.
*
Expand All @@ -46,8 +56,14 @@ class Session implements SessionInterface
public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
{
$this->storage = $storage ?: new NativeSessionStorage();
$this->registerBag($attributes ?: new AttributeBag());
$this->registerBag($flashes ?: new FlashBag());

$attributeBag = $attributes ?: new AttributeBag();
$this->attributeName = $attributeBag->getName();
$this->registerBag($attributeBag);

$flashBag = $flashes ?: new FlashBag();
$this->flashName = $flashBag->getName();
$this->registerBag($flashBag);
}

/**
Expand All @@ -63,55 +79,55 @@ public function start()
*/
public function has($name)
{
return $this->storage->getBag('attributes')->has($name);
return $this->storage->getBag($this->attributeName)->has($name);
}

/**
* {@inheritdoc}
*/
public function get($name, $default = null)
{
return $this->storage->getBag('attributes')->get($name, $default);
return $this->storage->getBag($this->attributeName)->get($name, $default);
}

/**
* {@inheritdoc}
*/
public function set($name, $value)
{
$this->storage->getBag('attributes')->set($name, $value);
$this->storage->getBag($this->attributeName)->set($name, $value);
}

/**
* {@inheritdoc}
*/
public function all()
{
return $this->storage->getBag('attributes')->all();
return $this->storage->getBag($this->attributeName)->all();
}

/**
* {@inheritdoc}
*/
public function replace(array $attributes)
{
$this->storage->getBag('attributes')->replace($attributes);
$this->storage->getBag($this->attributeName)->replace($attributes);
}

/**
* {@inheritdoc}
*/
public function remove($name)
{
return $this->storage->getBag('attributes')->remove($name);
return $this->storage->getBag($this->attributeName)->remove($name);
}

/**
* {@inheritdoc}
*/
public function clear()
{
$this->storage->getBag('attributes')->clear();
$this->storage->getBag($this->attributeName)->clear();
}

/**
Expand Down Expand Up @@ -201,7 +217,7 @@ public function getBag($name)
*/
public function getFlashBag()
{
return $this->getBag('flashes');
return $this->getBag($this->flashName);
}

// the following methods are kept for compatibility with Symfony 2.0 (they will be removed for Symfony 2.3)
Expand Down

0 comments on commit eb9bf05

Please sign in to comment.