X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fcontroller%2Fclass_BaseController.php;h=2a1c50f97c0b5a18267c4bd067f8b1d9287941df;hp=69fa4d154669961f2f8b39156ccfea78c1bfa20b;hb=90e103cb445f53c4ebd18c3f43dff51cbf0aae73;hpb=c6d73b0e3246efc824cb98338d4be7ee5bc9f308 diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index 69fa4d15..2a1c50f9 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -6,7 +6,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -29,6 +29,9 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ private $filterChains = array(); + // Exception constants + const EXCEPTION_FILTER_CHAIN_INVALID = 0xf10; + /** * Protected constructor * @@ -57,10 +60,21 @@ class BaseController extends BaseFrameworkSystem implements Registerable { * @param $filterChain Name of the filter chain * @return void */ - private function initFilterChain ($filterChain) { + protected function initFilterChain ($filterChain) { $this->filterChains[$filterChain] = ObjectFactory::createObjectByConfiguredName('filter_chain_class'); } + /** + * Adds a filter to a given filter group + * + * @param $filterGroup Group of the filter + * @param $filterInstance An instance of a filter + * @return void + */ + protected function addFilter ($filterGroup, Filterable $filterInstance) { + $this->filterChains[$filterGroup]->addFilter($filterInstance); + } + /** * Adds a filter to the pre filter chain * @@ -69,7 +83,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ public function addPreFilter (Filterable $filterInstance) { // Add the pre filter - $this->filterChains['pre']->addFilter($filterInstance); + $this->addFilter('pre', $filterInstance); } /** @@ -80,7 +94,27 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ public function addPostFilter (Filterable $filterInstance) { // Add the post filter - $this->filterChains['post']->addFilter($filterInstance); + $this->addFilter('post', $filterInstance); + } + + /** + * Executes given filter chain group + * + * @param $filterGroup Group of the filter to execute + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + * @throws InvalidFilterChainException If the filter chain is invalid + */ + protected function executeFilters ($filterGroup, Requestable $requestInstance, Responseable $responseInstance) { + // Test if the filter is there + if (!isset($this->filterChains[$filterGroup])) { + // Throw an exception here + throw new InvalidFilterChainException(array($this, $filterGroup), self::EXCEPTION_FILTER_CHAIN_INVALID); + } // END - if + + // Run all filters + $this->filterChains[$filterGroup]->processFilters($requestInstance, $responseInstance); } /** @@ -92,7 +126,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) { // Execute all pre filters - $this->filterChains['pre']->processFilters($requestInstance, $responseInstance); + $this->executeFilters('pre', $requestInstance, $responseInstance); } /** @@ -104,7 +138,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) { // Execute all post filters - $this->filterChains['post']->processFilters($requestInstance, $responseInstance); + $this->executeFilters('post', $requestInstance, $responseInstance); } }