[HttpFoundation] Remove hard coded assumptions and replace with API calls.
This commit is contained in:
parent
9a5fc659d7
commit
eb9bf05637
@ -36,6 +36,16 @@ class Session implements SessionInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $flashName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $attributeName;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +79,7 @@ class Session implements SessionInterface
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
return $this->storage->getBag('attributes')->has($name);
|
||||
return $this->storage->getBag($this->attributeName)->has($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +87,7 @@ class Session implements SessionInterface
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
return $this->storage->getBag('attributes')->get($name, $default);
|
||||
return $this->storage->getBag($this->attributeName)->get($name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +95,7 @@ class Session implements SessionInterface
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
$this->storage->getBag('attributes')->set($name, $value);
|
||||
$this->storage->getBag($this->attributeName)->set($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +103,7 @@ class Session implements SessionInterface
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->storage->getBag('attributes')->all();
|
||||
return $this->storage->getBag($this->attributeName)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +111,7 @@ class Session implements SessionInterface
|
||||
*/
|
||||
public function replace(array $attributes)
|
||||
{
|
||||
$this->storage->getBag('attributes')->replace($attributes);
|
||||
$this->storage->getBag($this->attributeName)->replace($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +119,7 @@ class Session implements SessionInterface
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
return $this->storage->getBag('attributes')->remove($name);
|
||||
return $this->storage->getBag($this->attributeName)->remove($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +127,7 @@ class Session implements SessionInterface
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->storage->getBag('attributes')->clear();
|
||||
$this->storage->getBag($this->attributeName)->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,7 +217,7 @@ class Session implements SessionInterface
|
||||
*/
|
||||
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)
|
||||
|
Reference in New Issue
Block a user