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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
34 changes: 16 additions & 18 deletions src/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,25 @@ public function sessionExists()
if ($sid !== false && $this->getId()) {
return true;
}
if (headers_sent()) {
return true;
}
return false;
}

/**
* Start session
*
* if No sesion currently exists, attempt to start it. Calls
* {@link isValid()} once session_start() is called, and raises an
* if No sesion currently exists, attempt to start it. Calls
* {@link isValid()} once session_start() is called, and raises an
* exception if validation fails.
*
*
* @param bool $preserveStorage If set to true, current session storage will not be overwritten by the
* contents of $_SESSION.
* @return void
* @throws Exception
*/
public function start()
public function start($preserveStorage = false)
{
if ($this->sessionExists()) {
return;
Expand All @@ -107,7 +112,9 @@ public function start()
if ($storage instanceof Storage\SessionStorage
&& $_SESSION !== $storage
) {
$storage->fromArray($_SESSION);
if (!$preserveStorage){
$storage->fromArray($_SESSION);
}
$_SESSION = $storage;
}
}
Expand Down Expand Up @@ -257,9 +264,7 @@ public function regenerateId()
session_regenerate_id();
return $this;
}
$this->destroy();
session_regenerate_id();
$this->start();
return $this;
}

Expand Down Expand Up @@ -384,19 +389,12 @@ protected function _setSessionCookieLifetime($ttl)
return;
}

if ($this->sessionExists()) {
$this->destroy(array('send_expire_cookie' => false));

// Since a cookie was destroyed, we should regenerate the ID
$this->regenerateId();
}

// Now simply set the cookie TTL
// Set new cookie TTL
$config->setCookieLifetime($ttl);

if (!$this->sessionExists()) {
// Restart session if necessary
$this->start();
if ($this->sessionExists()) {
// There is a running session so we'll regenerate id to send a new cookie
$this->regenerateId();
}
}
}
5 changes: 3 additions & 2 deletions src/Storage/ArrayStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/
namespace Zend\Session\Storage;

use Zend\Session\Storage as Storable,
use ArrayObject,
Zend\Session\Storage as Storable,
Zend\Session\Exception;

/**
Expand All @@ -38,7 +39,7 @@
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ArrayStorage extends \ArrayObject implements Storable
class ArrayStorage extends ArrayObject implements Storable
{
/**
* Is storage marked immutable?
Expand Down
8 changes: 4 additions & 4 deletions src/ValidatorChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public function __construct(Storage $storage)
$validators = $storage->getMetadata('_VALID');
if ($validators) {
foreach ($validators as $validator => $data) {
$this->connect('session.validate', new $validator($data), 'isValid');
$this->attach('session.validate', new $validator($data), 'isValid');
}
}
}

/**
* Attach a handler to the session validator chain
* Attach a listener to the session validator chain
*
* @param string $event
* @param callback $context
Expand All @@ -86,8 +86,8 @@ public function attach($event, $callback, $priority = 1)
$this->getStorage()->setMetadata('_VALID', array($name => $data));
}

$handle = parent::connect($event, $callback, $priority);
return $handle;
$listener = parent::attach($event, $callback, $priority);
return $listener;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ protected function forceAutoloader()
* @see http://matthewturland.com/2010/08/19/process-isolation-in-phpunit/
* @param PHPUnit_Framework_TestResult $result
* @return void
*/
public function run(\PHPUnit_Framework_TestResult $result = NULL)
{
$this->setPreserveGlobalState(false);
return parent::run($result);
}
*/

public function testInstantiationStartsSession()
{
Expand Down
15 changes: 7 additions & 8 deletions test/SaveHandler/DbTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function setUp()
$this->markTestSkipped('Zend\Session\SaveHandler\DbTable tests are not enabled due to missing PDO_Sqlite extension');
}

$this->markTestSkipped('Skipped until Zend\Db is refactored, this tests assumptions are generally bad, more assertions are needed');
// $this->markTestSkipped('Skipped until Zend\Db is refactored, this tests assumptions are generally bad, more assertions are needed');

$this->manager = $manager = new TestManager();
$this->_saveHandlerTableConfig['manager'] = $this->manager;
Expand All @@ -109,8 +109,8 @@ public function tearDown()
public function testConfigPrimaryAssignmentFullConfig()
{
$sh = new DbTable($this->_saveHandlerTableConfig);
$this->assertType('Zend\Db\Table\AbstractTable', $sh);
$this->assertType('Zend\Session\Manager', $sh->getManager());
$this->assertInstanceOf('Zend\Db\Table\AbstractTable', $sh);
$this->assertInstanceOf('Zend\Session\Manager', $sh->getManager());
}

public function testConstructorThrowsExceptionGivenConfigAsNull()
Expand All @@ -137,8 +137,8 @@ public function testTableEmptyNamePullFromSavePath()
$this->manager->getConfig()->setSavePath(__DIR__);

$this->setExpectedException(
'Zend\Session\SaveHandler\Exception\InvalidArgumentException',
'xxx'
'Zend\Session\SaveHandler\Exception',
'path'
);
$this->_usedSaveHandlers[] = $saveHandler = new DbTable($config);
}
Expand Down Expand Up @@ -217,9 +217,8 @@ public function testDifferentArraySize()
array_pop($config[DbTable::PRIMARY_ASSIGNMENT]);

$this->setExpectedException(
'Zend\Session\SaveHandler\Exception\RuntimeException',
'Configuration must define \'dataColumn\' which names the session table data column'
);
'Zend\Session\SaveHandler\Exception\RuntimeException'
);
$this->_usedSaveHandlers[] = $saveHandler = new DbTable($config);
}

Expand Down
16 changes: 11 additions & 5 deletions test/SessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function testDestroyDoesNotClearSessionStorageByDefault()
$storage = $this->manager->getStorage();
$storage['foo'] = 'bar';
$this->manager->destroy();
$this->manager->start();
$this->assertTrue(isset($storage['foo']));
$this->assertEquals('bar', $storage['foo']);
}

Expand Down Expand Up @@ -622,10 +622,16 @@ public function testForgetMeShouldSendCookieWithZeroTimestamp()
public function testStartingSessionThatFailsAValidatorShouldRaiseException()
{
$chain = $this->manager->getValidatorChain();
$chain->connect('session.validate', function() {
return false;
});
$this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'xxx');
$chain->attach('session.validate', array($this, 'validateSession'));
$this->setExpectedException('Zend\Session\Exception\RuntimeException', 'failed');
$this->manager->start();
}

/**
* @see testStartingSessionThatFailsAValidatorShouldRaiseException()
*/
public static function validateSession()
{
return false;
}
}

0 comments on commit ae0f13d

Please sign in to comment.