Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2987'
Browse files Browse the repository at this point in the history
Close #2987
  • Loading branch information
weierophinney committed Nov 19, 2012
2 parents 8b75516 + f153662 commit 0a74c75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions library/Zend/Session/Container.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ public function offsetUnset($key)
unset($storage[$name][$key]); unset($storage[$name][$key]);
} }


/**
* Exchange the current array with another array or object.
*
* @param array|object $input
* @return array Returns the old array
* @see ArrayObject::exchangeArray()
*/
public function exchangeArray($input)
{
$storage = $this->verifyNamespace();
$name = $this->getName();

$old = $storage[$name];
$storage[$name] = $input;
return (array) $old;
}

/** /**
* Iterate over session container * Iterate over session container
* *
Expand Down
11 changes: 11 additions & 0 deletions tests/ZendTest/Session/ContainerTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -515,4 +515,15 @@ public function testValidationShouldNotRaiseErrorForMissingResponseObject()
$session->test = 42; $session->test = 42;
$this->assertEquals(42, $session->test); $this->assertEquals(42, $session->test);
} }

public function testExchangeArray()
{
$this->container->offsetSet('old', 'old');
$this->assertTrue($this->container->offsetExists('old'));

$old = $this->container->exchangeArray(array('new' => 'new'));
$this->assertArrayHasKey('old', $old, "'exchangeArray' doesn't return an array of old items");
$this->assertFalse($this->container->offsetExists('old'), "'exchangeArray' doesn't remove old items");
$this->assertTrue($this->container->offsetExists('new'), "'exchangeArray' doesn't add the new array items");
}
} }

0 comments on commit 0a74c75

Please sign in to comment.