Skip to content
Browse files

Merge pull request #3452 branch 'hotfix/session-mutability'

  • Loading branch information...
2 parents 19f48e9 + 46100cd commit 28367e54eb08614350b47152f37acf3d20f7f179 @Maks3w committed
View
3 library/Zend/Mvc/Controller/Plugin/FlashMessenger.php
@@ -15,7 +15,6 @@
use IteratorAggregate;
use Zend\Session\Container;
use Zend\Session\ManagerInterface as Manager;
-use Zend\Session\SessionManager;
use Zend\Stdlib\SplQueue;
/**
@@ -79,7 +78,7 @@ public function setSessionManager(Manager $manager)
public function getSessionManager()
{
if (!$this->session instanceof Manager) {
- $this->setSessionManager(new SessionManager());
+ $this->setSessionManager(Container::getDefaultManager());
}
return $this->session;
}
View
67 library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php
@@ -13,6 +13,7 @@
use Zend\Mvc\Exception\RuntimeException;
use Zend\Session\Container;
+use Zend\Session\ManagerInterface as Manager;
/**
* Plugin to help facilitate Post/Redirect/Get (http://en.wikipedia.org/wiki/Post/Redirect/Get)
@@ -23,6 +24,56 @@
*/
class PostRedirectGet extends AbstractPlugin
{
+ /**
+ * @var Manager
+ */
+ protected $session;
+
+ /**
+ * Set the session manager
+ *
+ * @param Manager $manager
+ * @return FlashMessenger
+ */
+ public function setSessionManager(Manager $manager)
+ {
+ $this->session = $manager;
+ return $this;
+ }
+
+ /**
+ * Retrieve the session manager
+ *
+ * If none composed, lazy-loads a SessionManager instance
+ *
+ * @return Manager
+ */
+ public function getSessionManager()
+ {
+ if (!$this->session instanceof Manager) {
+ $this->setSessionManager(Container::getDefaultManager());
+ }
+ return $this->session;
+ }
+
+ /**
+ * Perform PRG logic
+ *
+ * If a null value is present for the $redirect, the current route is
+ * retrieved and use to generate the URL for redirect.
+ *
+ * If the request method is POST, creates a session container set to expire
+ * after 1 hop containing the values of the POST. It then redirects to the
+ * specified URL using a status 303.
+ *
+ * If the request method is GET, checks to see if we have values in the
+ * session container, and, if so, returns them; otherwise, it returns a
+ * boolean false.
+ *
+ * @param null|string $redirect
+ * @param bool $redirectToUrl
+ * @return \Zend\Http\Response|array|Traversable|false
+ */
public function __invoke($redirect = null, $redirectToUrl = false)
{
$controller = $this->getController();
@@ -36,7 +87,7 @@ public function __invoke($redirect = null, $redirectToUrl = false)
$params = $routeMatch->getParams();
}
- $container = new Container('prg_post1');
+ $container = new Container('prg_post1', $this->getSessionManager());
if ($request->isPost()) {
$container->setExpirationHops(1, 'post');
@@ -67,14 +118,14 @@ public function __invoke($redirect = null, $redirectToUrl = false)
$response->setStatusCode(303);
return $response;
- } else {
- if ($container->post !== null) {
- $post = $container->post;
- unset($container->post);
- return $post;
- }
+ }
- return false;
+ if ($container->post !== null) {
+ $post = $container->post;
+ unset($container->post);
+ return $post;
}
+
+ return false;
}
}
View
16 library/Zend/Session/SessionManager.php
@@ -11,7 +11,6 @@
namespace Zend\Session;
use Zend\EventManager\EventManagerInterface;
-use Zend\Session\SaveHandler\SaveHandlerInterface;
/**
* Session ManagerInterface implementation utilizing ext/session
@@ -43,14 +42,17 @@ class SessionManager extends AbstractManager
protected $validatorChain;
/**
- * Destructor
- * Ensures that writeClose is called.
+ * Constructor
*
- * @return void
+ * @param Config\ConfigInterface|null $config
+ * @param Storage\StorageInterface|null $storage
+ * @param SaveHandler\SaveHandlerInterface|null $saveHandler
+ * @throws Exception\RuntimeException
*/
- public function __destruct()
+ public function __construct(Config\ConfigInterface $config = null, Storage\StorageInterface $storage = null, SaveHandler\SaveHandlerInterface $saveHandler = null)
{
- $this->writeClose();
+ parent::__construct($config, $storage, $saveHandler);
+ register_shutdown_function(array($this, 'writeClose'));
}
/**
@@ -89,7 +91,7 @@ public function start($preserveStorage = false)
}
$saveHandler = $this->getSaveHandler();
- if ($saveHandler instanceof SaveHandlerInterface) {
+ if ($saveHandler instanceof SaveHandler\SaveHandlerInterface) {
// register the session handler with ext/session
$this->registerSaveHandler($saveHandler);
}
View
5 tests/ZendTest/Mvc/Controller/Plugin/FlashMessengerTest.php
@@ -27,6 +27,11 @@ public function setUp()
$this->helper->setSessionManager($this->session);
}
+ public function tearDown()
+ {
+ $this->session->getStorage()->clear();
+ }
+
public function seedMessages()
{
$helper = new FlashMessenger();
View
4 tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php
@@ -65,7 +65,9 @@ public function setUp()
$this->sessionManager->destroy();
$this->controller->setEvent($this->event);
- $this->controller->flashMessenger()->setSessionManager($this->sessionManager);
+ $plugins = $this->controller->getPluginManager();
+ $plugins->get('flashmessenger')->setSessionManager($this->sessionManager);
+ $plugins->get('prg')->setSessionManager($this->sessionManager);
}
public function testReturnsFalseOnIntialGet()
View
12 tests/ZendTest/Session/SessionManagerTest.php
@@ -329,18 +329,6 @@ public function testCallingWriteCloseMarksStorageAsImmutable()
/**
* @runInSeparateProcess
*/
- public function testCallingDestructorMarksStorageAsImmutable()
- {
- $this->manager->start();
- $storage = $this->manager->getStorage();
- $storage['foo'] = 'bar';
- $this->manager = null;
- $this->assertTrue($storage->isImmutable());
- }
-
- /**
- * @runInSeparateProcess
- */
public function testCallingWriteCloseShouldNotAlterSessionExistsStatus()
{
$this->manager->start();
View
4 tests/ZendTest/Session/TestAsset/TestSaveHandlerWithValidator.php
@@ -15,7 +15,9 @@
class TestSaveHandlerWithValidator implements SaveHandler
{
public function open($save_path, $name)
- {return true;}
+ {
+ return true;
+ }
public function close()
{}

0 comments on commit 28367e5

Please sign in to comment.
Something went wrong with that request. Please try again.