*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class BaseController extends BaseFrameworkSystem {
+class BaseController extends BaseFrameworkSystem implements Registerable {
/**
- * Instance of a CommandResolver class
+ * Generic filter chains
*/
- private $resolverInstance = null;
-
- /**
- * Pre filter chain instance
- */
- private $preFilterChain = null;
-
- /**
- * Post filter chain instance
- */
- private $postFilterChain = null;
+ private $filterChains = array();
/**
* Protected constructor
*
+ * @param $className Name of the class
* @return void
*/
- protected function __construct ($class) {
+ protected function __construct ($className) {
// Call parent constructor
- parent::__construct($class);
+ parent::__construct($className);
// Clean up a little
$this->removeNumberFormaters();
$this->removeSystemArray();
// Initialize both filter chains
- $this->preFilterChain = FilterChain::createFilterChain();
- $this->postFilterChain = FilterChain::createFilterChain();
- }
+ $this->initFilterChain('pre');
+ $this->initFilterChain('post');
- /**
- * Getter for a command resolver instance
- *
- * @return $resolverInstance An instance of a command resolver class
- */
- public final function getResolverInstance () {
- return $this->resolverInstance;
+ // Add this controller to the registry
+ Registry::getRegistry()->addInstance('controller', $this);
}
/**
- * Setter for a command resolver instance
+ * Private method to initialize a given filter chain
*
- * @param $resolverInstance An instance of a command resolver class
+ * @param $filterChain Name of the filter chain
* @return void
*/
- public final function setResolverInstance (CommandResolver $resolverInstance) {
- $this->resolverInstance = $resolverInstance;
+ private function initFilterChain ($filterChain) {
+ $this->filterChains[$filterChain] = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
}
/**
*/
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);
}
}