From 2f04411275e1f4f377a3f708e0bd0402e41a536f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 15 Oct 2019 15:16:33 +0200 Subject: [PATCH] Make actions interceptable with yield --- library/Eagle/Web/Controller.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/library/Eagle/Web/Controller.php b/library/Eagle/Web/Controller.php index b1be2a3c..2715bdb1 100644 --- a/library/Eagle/Web/Controller.php +++ b/library/Eagle/Web/Controller.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Eagle\Web; +use Generator; use Icinga\Data\ResourceFactory; use Icinga\Module\Eagle\Widget\ViewModeSwitcher; use ipl\Stdlib\Contract\PaginationInterface; @@ -107,4 +108,33 @@ class Controller extends CompatController return $viewModeSwitcher; } + + public function dispatch($action) + { + // Notify helpers of action preDispatch state + $this->_helper->notifyPreDispatch(); + + $this->preDispatch(); + + if ($this->getRequest()->isDispatched()) { + // If pre-dispatch hooks introduced a redirect then stop dispatch + // @see ZF-7496 + if (! $this->getResponse()->isRedirect()) { + $interceptable = $this->$action(); + if ($interceptable instanceof Generator) { + foreach ($interceptable as $stopSignal) { + if ($stopSignal === true) { + break; + } + } + } + } + $this->postDispatch(); + } + + // whats actually important here is that this action controller is + // shutting down, regardless of dispatching; notify the helpers of this + // state + $this->_helper->notifyPostDispatch(); + } }