From f68c0d147585336bb415878accdff5c2af6882f8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 6 Apr 2015 00:30:50 +0200 Subject: [PATCH] Introduced executeGenericPrePostCommand() which will execute a command with pre and post filters. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../class_ImageCodeCaptchaController.php | 19 +------ .../main/controller/class_BaseController.php | 50 +++++++++++++++---- .../class_ConsoleDefaultNewsController.php | 22 +------- inc/classes/main/controller/html/class_Html | 19 +------ .../html/class_HtmlConfirmController.php | 19 +------ .../html/class_HtmlDefaultNewsController.php | 22 +------- .../html/class_HtmlLoginController.php | 22 +------- .../html/class_HtmlLogoutDoneController.php | 22 +------- .../html/class_HtmlProblemController.php | 22 +------- .../html/class_HtmlRegisterController.php | 22 +------- 10 files changed, 58 insertions(+), 181 deletions(-) diff --git a/inc/classes/main/controller/captcha/class_ImageCodeCaptchaController.php b/inc/classes/main/controller/captcha/class_ImageCodeCaptchaController.php index d9a3f331..99b044e9 100644 --- a/inc/classes/main/controller/captcha/class_ImageCodeCaptchaController.php +++ b/inc/classes/main/controller/captcha/class_ImageCodeCaptchaController.php @@ -60,23 +60,8 @@ class ImageCodeCaptchaController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Execute pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // Get the command instance - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Execute post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index e604b54c..3b0d24c1 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -54,6 +54,36 @@ class BaseController extends BaseFrameworkSystem implements Registerable { Registry::getRegistry()->addInstance('controller', $this); } + /** + * Executes a command with pre and post filters + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + public function executeGenericPrePostCommand (Requestable $requestInstance, Responseable $responseInstance) { + // Get the command instance from the resolver by sending a request instance to the resolver + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); + + // Add more filters by the command + $commandInstance->addExtraFilters($this, $requestInstance); + + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + + // This request was valid! :-D + $requestInstance->requestIsValid(); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Run the post filters + $this->executePostFilters($requestInstance, $responseInstance); + + // Flush the response out + $responseInstance->flushBuffer(); + } + /** * Private method to initialize a given filter chain * @@ -110,6 +140,16 @@ class BaseController extends BaseFrameworkSystem implements Registerable { $this->addFilter(self::FILTER_CHAIN_POST_COMMAND, $filterInstance); } + /** + * Add a shutdown filter + * + * @param $filterInstance A Filterable class + * @return void + */ + public function addShutdownFilter (Filterable $filterInstance) { + $this->addFilter('shutdown', $filterInstance); + } + /** * Executes given filter chain chain * @@ -154,16 +194,6 @@ class BaseController extends BaseFrameworkSystem implements Registerable { $this->executeFilters(self::FILTER_CHAIN_POST_COMMAND, $requestInstance, $responseInstance); } - /** - * Add a shutdown filter - * - * @param $filterInstance A Filterable class - * @return void - */ - public function addShutdownFilter (Filterable $filterInstance) { - $this->addFilter('shutdown', $filterInstance); - } - /** * Executes all shutdown filters * diff --git a/inc/classes/main/controller/console/class_ConsoleDefaultNewsController.php b/inc/classes/main/controller/console/class_ConsoleDefaultNewsController.php index f0c02973..89ecb683 100644 --- a/inc/classes/main/controller/console/class_ConsoleDefaultNewsController.php +++ b/inc/classes/main/controller/console/class_ConsoleDefaultNewsController.php @@ -61,26 +61,8 @@ class ConsoleDefaultNewsController extends BaseController implements Controller * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the pre filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/html/class_Html b/inc/classes/main/controller/html/class_Html index 6d3708f3..e9a95a4d 100644 --- a/inc/classes/main/controller/html/class_Html +++ b/inc/classes/main/controller/html/class_Html @@ -61,23 +61,8 @@ class Html???Controller extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/html/class_HtmlConfirmController.php b/inc/classes/main/controller/html/class_HtmlConfirmController.php index 8e3147e2..ea3e7633 100644 --- a/inc/classes/main/controller/html/class_HtmlConfirmController.php +++ b/inc/classes/main/controller/html/class_HtmlConfirmController.php @@ -64,23 +64,8 @@ class HtmlConfirmController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/html/class_HtmlDefaultNewsController.php b/inc/classes/main/controller/html/class_HtmlDefaultNewsController.php index 36b0b96b..1d346b8a 100644 --- a/inc/classes/main/controller/html/class_HtmlDefaultNewsController.php +++ b/inc/classes/main/controller/html/class_HtmlDefaultNewsController.php @@ -61,26 +61,8 @@ class HtmlDefaultNewsController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/html/class_HtmlLoginController.php b/inc/classes/main/controller/html/class_HtmlLoginController.php index eef5b5ee..0db76a75 100644 --- a/inc/classes/main/controller/html/class_HtmlLoginController.php +++ b/inc/classes/main/controller/html/class_HtmlLoginController.php @@ -59,26 +59,8 @@ class HtmlLoginController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/html/class_HtmlLogoutDoneController.php b/inc/classes/main/controller/html/class_HtmlLogoutDoneController.php index 4f6f98be..b2f93a19 100644 --- a/inc/classes/main/controller/html/class_HtmlLogoutDoneController.php +++ b/inc/classes/main/controller/html/class_HtmlLogoutDoneController.php @@ -58,26 +58,8 @@ class HtmlLogoutDoneController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/html/class_HtmlProblemController.php b/inc/classes/main/controller/html/class_HtmlProblemController.php index 3a1551c6..f3c37356 100644 --- a/inc/classes/main/controller/html/class_HtmlProblemController.php +++ b/inc/classes/main/controller/html/class_HtmlProblemController.php @@ -58,26 +58,8 @@ class HtmlProblemController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/html/class_HtmlRegisterController.php b/inc/classes/main/controller/html/class_HtmlRegisterController.php index 0c957903..b1d5999a 100644 --- a/inc/classes/main/controller/html/class_HtmlRegisterController.php +++ b/inc/classes/main/controller/html/class_HtmlRegisterController.php @@ -58,26 +58,8 @@ class HtmlRegisterController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + // Generic pre-post command execution + $this->executeGenericPrePostCommand($requestInstance, $responseInstance); } } -- 2.30.2