Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions library/Zend/Mvc/Controller/Plugin/FlashMessenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use IteratorAggregate;
use Zend\Session\Container;
use Zend\Session\ManagerInterface as Manager;
use Zend\Session\SessionManager;
use Zend\Stdlib\SplQueue;

/**
Expand Down Expand Up @@ -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;
}
Expand Down
67 changes: 59 additions & 8 deletions library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand All @@ -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');
Expand Down Expand Up @@ -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;
}
}
16 changes: 9 additions & 7 deletions library/Zend/Session/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Zend\Session;

use Zend\EventManager\EventManagerInterface;
use Zend\Session\SaveHandler\SaveHandlerInterface;

/**
* Session ManagerInterface implementation utilizing ext/session
Expand Down Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ZendTest/Mvc/Controller/Plugin/FlashMessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 0 additions & 12 deletions tests/ZendTest/Session/SessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,6 @@ public function testCallingWriteCloseMarksStorageAsImmutable()
$this->assertTrue($storage->isImmutable());
}

/**
* @runInSeparateProcess
*/
public function testCallingDestructorMarksStorageAsImmutable()
{
$this->manager->start();
$storage = $this->manager->getStorage();
$storage['foo'] = 'bar';
$this->manager = null;
$this->assertTrue($storage->isImmutable());
}

/**
* @runInSeparateProcess
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
class TestSaveHandlerWithValidator implements SaveHandler
{
public function open($save_path, $name)
{return true;}
{
return true;
}

public function close()
{}
Expand Down