Skip to content

Commit

Permalink
[HttpFoundation] removed deprecated session methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 23, 2013
1 parent 8ec3bfb commit fb81cb2
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 247 deletions.
19 changes: 1 addition & 18 deletions Session/Flash/FlashBag.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* @author Drak <drak@zikula.org> * @author Drak <drak@zikula.org>
*/ */
class FlashBag implements FlashBagInterface, \IteratorAggregate, \Countable class FlashBag implements FlashBagInterface, \IteratorAggregate
{ {
private $name = 'flashes'; private $name = 'flashes';


Expand Down Expand Up @@ -173,21 +173,4 @@ public function getIterator()
{ {
return new \ArrayIterator($this->all()); return new \ArrayIterator($this->all());
} }

/**
* Returns the number of flashes.
*
* This method does not work.
*
* @deprecated in 2.2, removed in 2.3
* @see https://github.com/symfony/symfony/issues/6408
*
* @return int The number of flashes
*/
public function count()
{
trigger_error(sprintf('%s() is deprecated since 2.2 and will be removed in 2.3', __METHOD__), E_USER_DEPRECATED);

return count($this->flashes);
}
} }
109 changes: 0 additions & 109 deletions Session/Session.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -249,113 +249,4 @@ public function getFlashBag()
{ {
return $this->getBag($this->flashName); return $this->getBag($this->flashName);
} }

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

/**
* @return array
*
* @deprecated since 2.1, will be removed from 2.3
*/
public function getFlashes()
{
trigger_error('getFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

$all = $this->getBag($this->flashName)->all();

$return = array();
if ($all) {
foreach ($all as $name => $array) {
if (is_numeric(key($array))) {
$return[$name] = reset($array);
} else {
$return[$name] = $array;
}
}
}

return $return;
}

/**
* @param array $values
*
* @deprecated since 2.1, will be removed from 2.3
*/
public function setFlashes($values)
{
trigger_error('setFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

foreach ($values as $name => $value) {
$this->getBag($this->flashName)->set($name, $value);
}
}

/**
* @param string $name
* @param string $default
*
* @return string
*
* @deprecated since 2.1, will be removed from 2.3
*/
public function getFlash($name, $default = null)
{
trigger_error('getFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

$return = $this->getBag($this->flashName)->get($name);

return empty($return) ? $default : reset($return);
}

/**
* @param string $name
* @param string $value
*
* @deprecated since 2.1, will be removed from 2.3
*/
public function setFlash($name, $value)
{
trigger_error('setFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

$this->getBag($this->flashName)->set($name, $value);
}

/**
* @param string $name
*
* @return Boolean
*
* @deprecated since 2.1, will be removed from 2.3
*/
public function hasFlash($name)
{
trigger_error('hasFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

return $this->getBag($this->flashName)->has($name);
}

/**
* @param string $name
*
* @deprecated since 2.1, will be removed from 2.3
*/
public function removeFlash($name)
{
trigger_error('removeFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

$this->getBag($this->flashName)->get($name);
}

/**
* @return array
*
* @deprecated since 2.1, will be removed from 2.3
*/
public function clearFlashes()
{
trigger_error('clearFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

return $this->getBag($this->flashName)->clear();
}
} }
14 changes: 0 additions & 14 deletions Tests/Session/Flash/FlashBagTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -133,20 +133,6 @@ public function testPeekAll()
); );
} }


/**
* @covers Symfony\Component\HttpFoundation\Session\Flash\FlashBag::count
* @expectedException \PHPUnit_Framework_Error_Deprecated
*/
public function testCount()
{
$flashes = array('hello' => 'world', 'beep' => 'boop', 'notice' => 'nope');
foreach ($flashes as $key => $val) {
$this->bag->set($key, $val);
}

$this->assertEquals(count($flashes), count($this->bag));
}

/** /**
* @covers Symfony\Component\HttpFoundation\Session\Flash\FlashBag::getIterator * @covers Symfony\Component\HttpFoundation\Session\Flash\FlashBag::getIterator
*/ */
Expand Down
106 changes: 0 additions & 106 deletions Tests/Session/SessionTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ protected function tearDown()
$this->session = null; $this->session = null;
} }


public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}

return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}

public function testStart() public function testStart()
{ {
$this->assertEquals('', $this->session->getId()); $this->assertEquals('', $this->session->getId());
Expand Down Expand Up @@ -199,103 +190,6 @@ public function testGetFlashBag()
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface', $this->session->getFlashBag()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface', $this->session->getFlashBag());
} }


// deprecated since 2.1, will be removed from 2.3

public function testGetSetFlashes()
{
set_error_handler(array($this, "deprecationErrorHandler"));

$array = array('notice' => 'hello', 'error' => 'none');
$this->assertEquals(array(), $this->session->getFlashes());
$this->session->setFlashes($array);
$this->assertEquals($array, $this->session->getFlashes());
$this->assertEquals(array(), $this->session->getFlashes());
$this->session->getFlashBag()->add('notice', 'foo');

// test that BC works by only retrieving the first added.
$this->session->getFlashBag()->add('notice', 'foo2');
$this->assertEquals(array('notice' => 'foo'), $this->session->getFlashes());

restore_error_handler();
}

public function testGetFlashesWithArray()
{
set_error_handler(array($this, "deprecationErrorHandler"));

$array = array('notice' => 'hello', 'error' => 'none');
$this->assertEquals(array(), $this->session->getFlashes());
$this->session->setFlash('foo', $array);
$this->assertEquals(array('foo' => $array), $this->session->getFlashes());
$this->assertEquals(array(), $this->session->getFlashes());

$array = array('hello', 'foo');
$this->assertEquals(array(), $this->session->getFlashes());
$this->session->setFlash('foo', $array);
$this->assertEquals(array('foo' => 'hello'), $this->session->getFlashes());
$this->assertEquals(array(), $this->session->getFlashes());

restore_error_handler();
}

public function testGetSetFlash()
{
set_error_handler(array($this, "deprecationErrorHandler"));

$this->assertNull($this->session->getFlash('notice'));
$this->assertEquals('default', $this->session->getFlash('notice', 'default'));
$this->session->getFlashBag()->add('notice', 'foo');
$this->session->getFlashBag()->add('notice', 'foo2');

// test that BC works by only retrieving the first added.
$this->assertEquals('foo', $this->session->getFlash('notice'));
$this->assertNull($this->session->getFlash('notice'));

restore_error_handler();
}

public function testHasFlash()
{
set_error_handler(array($this, "deprecationErrorHandler"));

$this->assertFalse($this->session->hasFlash('notice'));
$this->session->setFlash('notice', 'foo');
$this->assertTrue($this->session->hasFlash('notice'));

restore_error_handler();
}

public function testRemoveFlash()
{
set_error_handler(array($this, "deprecationErrorHandler"));

$this->session->setFlash('notice', 'foo');
$this->session->setFlash('error', 'bar');
$this->assertTrue($this->session->hasFlash('notice'));
$this->session->removeFlash('error');
$this->assertTrue($this->session->hasFlash('notice'));
$this->assertFalse($this->session->hasFlash('error'));

restore_error_handler();
}

public function testClearFlashes()
{
set_error_handler(array($this, "deprecationErrorHandler"));

$this->assertFalse($this->session->hasFlash('notice'));
$this->assertFalse($this->session->hasFlash('error'));
$this->session->setFlash('notice', 'foo');
$this->session->setFlash('error', 'bar');
$this->assertTrue($this->session->hasFlash('notice'));
$this->assertTrue($this->session->hasFlash('error'));
$this->session->clearFlashes();
$this->assertFalse($this->session->hasFlash('notice'));
$this->assertFalse($this->session->hasFlash('error'));

restore_error_handler();
}

/** /**
* @covers Symfony\Component\HttpFoundation\Session\Session::getIterator * @covers Symfony\Component\HttpFoundation\Session\Session::getIterator
*/ */
Expand Down

0 comments on commit fb81cb2

Please sign in to comment.