*/
class BaseController extends BaseFrameworkSystem implements Registerable {
/**
- * Pre filter chain instance
+ * Generic filter chains
*/
- private $preFilterChain = null;
-
- /**
- * Post filter chain instance
- */
- private $postFilterChain = null;
+ private $filterChains = array();
/**
* Protected constructor
$this->removeSystemArray();
// Initialize both filter chains
- $this->preFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
- $this->postFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
+ $this->initFilterChain('pre');
+ $this->initFilterChain('post');
// Add this controller to the registry
Registry::getRegistry()->addInstance('controller', $this);
}
+ /**
+ * Private method to initialize a given filter chain
+ *
+ * @param $filterChain Name of the filter chain
+ * @return void
+ */
+ private function initFilterChain ($filterChain) {
+ $this->filterChains[$filterChain] = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
+ }
+
/**
* Adds a filter to the pre filter chain
*
*/
public function addPreFilter (Filterable $filterInstance) {
// Add the pre filter
- $this->preFilterChain->addFilter($filterInstance);
+ $this->filterChains['pre']->addFilter($filterInstance);
}
/**
*/
public function addPostFilter (Filterable $filterInstance) {
// Add the post filter
- $this->postFilterChain->addFilter($filterInstance);
+ $this->filterChains['post']->addFilter($filterInstance);
}
/**
*/
protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) {
// Execute all pre filters
- $this->preFilterChain->processFilters($requestInstance, $responseInstance);
+ $this->filterChains['pre']->processFilters($requestInstance, $responseInstance);
}
/**
*/
protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) {
// Execute all post filters
- $this->postFilterChain->processFilters($requestInstance, $responseInstance);
+ $this->filterChains['post']->processFilters($requestInstance, $responseInstance);
}
}