Created
April 11, 2013 21:29
-
-
Save Majkl578/5367340 to your computer and use it in GitHub Desktop.
Variant of Presenter::restoreRequest() which ignores signals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Nette\Application\IResponse; | |
| use Nette\Application\Responses\ForwardResponse; | |
| use Nette\Application\UI\Presenter; | |
| trait RestoreRequestWithoutSignalTrait | |
| { | |
| /** | |
| * Restores current request to session. Ignores signals. | |
| * @param string | |
| * @return void | |
| * @author Michael Moravec | |
| */ | |
| public function restoreRequestWithoutSignal($key) | |
| { | |
| $this->onShutdown[__METHOD__] = function (Presenter $presenter, IResponse $response) { | |
| if (!$response instanceof ForwardResponse) { | |
| return; | |
| } | |
| $parameters = $response->getRequest()->getParameters(); | |
| unset($parameters[$presenter::SIGNAL_KEY]); | |
| $response->getRequest()->setParameters($parameters); | |
| }; | |
| $this->restoreRequest($key); | |
| // nothing happened, restore original behavior | |
| unset($this->onShutdown[__METHOD__]); | |
| } | |
| } | |
| class SomePresenter extends Presenter | |
| { | |
| use RestoreRequestWithoutSignalTrait; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment