*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*/
private $filterChains = array();
+ // Exception constants
+ const EXCEPTION_FILTER_CHAIN_INVALID = 0xf10;
+
/**
* Protected constructor
*
// Call parent constructor
parent::__construct($className);
- // Clean up a little
- $this->removeNumberFormaters();
- $this->removeSystemArray();
-
// Initialize both filter chains
$this->initFilterChain('pre');
$this->initFilterChain('post');
* @param $filterChain Name of the filter chain
* @return void
*/
- private function initFilterChain ($filterChain) {
+ protected function initFilterChain ($filterChain) {
+ //* DEBUG: */ $this->debugOutput('CONTROLLER: ' . $filterChain . ' init: START');
$this->filterChains[$filterChain] = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
+ //* DEBUG: */ $this->debugOutput('CONTROLLER: ' . $filterChain . ' init: FINISHED');
}
/**
- * Adds a filter to a given filter group
+ * Adds a filter to a given filter chain
*
- * @param $filterGroup Group of the filter
+ * @param $filterChain Chain of the filter
* @param $filterInstance An instance of a filter
* @return void
+ * @throws InvalidFilterChainException If the filter chain is invalid
*/
- protected function add addFilter ($filterGroup, Filterable $filterInstance) {
- $this->filterChains[$filterGroup]->addFilter($filterInstance);
+ protected function addFilter ($filterChain, Filterable $filterInstance) {
+ //* DEBUG: */ $this->debugOutput('CONTROLLER: ' . $filterChain . ',' . $filterInstance->__toString(). ' add: START');
+
+ // Test if the filter is there
+ if (!isset($this->filterChains[$filterChain])) {
+ // Throw an exception here
+ throw new InvalidFilterChainException(array($this, $filterChain), self::EXCEPTION_FILTER_CHAIN_INVALID);
+ } // END - if
+
+ // Add the filter
+ $this->filterChains[$filterChain]->addFilter($filterInstance);
+ //* DEBUG: */ $this->debugOutput('CONTROLLER: ' . $filterChain . ',' . $filterInstance->__toString(). ' add: FINISH');
}
/**
}
/**
- * Executes given filter chain group
+ * Executes given filter chain chain
*
- * @param $filterGroup Group of the filter to execute
+ * @param $filterChain Chain 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) {
- $this->filterChains[$filterGroup]->processFilters($requestInstance, $responseInstance);
+ protected function executeFilters ($filterChain, Requestable $requestInstance, Responseable $responseInstance) {
+ // Test if the filter is there
+ if (!isset($this->filterChains[$filterChain])) {
+ // Throw an exception here
+ throw new InvalidFilterChainException(array($this, $filterChain), self::EXCEPTION_FILTER_CHAIN_INVALID);
+ } // END - if
+
+ // Run all filters
+ $this->filterChains[$filterChain]->processFilters($requestInstance, $responseInstance);
}
/**