Skip to content

Some small cleanup and optimization of Session.php #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 15 additions & 46 deletions Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class Session implements \Serializable
/**
* Constructor.
*
* @param SessionStorageInterface $storage A SessionStorageInterface instance
* @param \Symfony\Component\HttpFoundation\SessionStorage\SessionStorageInterface $storage A SessionStorageInterface instance
* @return \Symfony\Component\HttpFoundation\Session
*
*/
public function __construct(SessionStorageInterface $storage)
{
Expand Down Expand Up @@ -109,10 +111,7 @@ public function get($name, $default = null)
*/
public function set($name, $value)
{
if (false === $this->started) {
$this->start();
}

$this->start();
$this->attributes[$name] = $value;
}

Expand All @@ -137,10 +136,7 @@ public function all()
*/
public function replace(array $attributes)
{
if (false === $this->started) {
$this->start();
}

$this->start();
$this->attributes = $attributes;
}

Expand All @@ -153,13 +149,8 @@ public function replace(array $attributes)
*/
public function remove($name)
{
if (false === $this->started) {
$this->start();
}

if (array_key_exists($name, $this->attributes)) {
unset($this->attributes[$name]);
}
$this->start();
unset($this->attributes[$name]);
}

/**
Expand All @@ -169,9 +160,7 @@ public function remove($name)
*/
public function clear()
{
if (false === $this->started) {
$this->start();
}
$this->start();

$this->attributes = array();
$this->flashes = array();
Expand Down Expand Up @@ -208,10 +197,7 @@ public function migrate()
*/
public function getId()
{
if (false === $this->started) {
$this->start();
}

$this->start();
return $this->storage->getId();
}

Expand All @@ -232,10 +218,7 @@ public function getFlashes()
*/
public function setFlashes($values)
{
if (false === $this->started) {
$this->start();
}

$this->start();
$this->flashes = $values;
$this->oldFlashes = array();
}
Expand All @@ -261,10 +244,7 @@ public function getFlash($name, $default = null)
*/
public function setFlash($name, $value)
{
if (false === $this->started) {
$this->start();
}

$this->start();
$this->flashes[$name] = $value;
unset($this->oldFlashes[$name]);
}
Expand All @@ -278,10 +258,7 @@ public function setFlash($name, $value)
*/
public function hasFlash($name)
{
if (false === $this->started) {
$this->start();
}

$this->start();
return array_key_exists($name, $this->flashes);
}

Expand All @@ -292,10 +269,7 @@ public function hasFlash($name)
*/
public function removeFlash($name)
{
if (false === $this->started) {
$this->start();
}

$this->start();
unset($this->flashes[$name]);
}

Expand All @@ -304,19 +278,14 @@ public function removeFlash($name)
*/
public function clearFlashes()
{
if (false === $this->started) {
$this->start();
}

$this->start();
$this->flashes = array();
$this->oldFlashes = array();
}

public function save()
{
if (false === $this->started) {
$this->start();
}
$this->start();

$this->flashes = array_diff_key($this->flashes, $this->oldFlashes);

Expand Down