3 * A generic controller class. You should extend this base class if you want to
4 * write your own controller. You get the advantage that you can use the pre and
7 * @author Roland Haeder <webmaster@ship-simu.org>
9 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
10 * @license GNU GPL 3.0 or any newer version
11 * @link http://www.ship-simu.org
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 class BaseController extends BaseFrameworkSystem implements Registerable {
28 * Pre filter chain instance
30 private $preFilterChain = null;
33 * Post filter chain instance
35 private $postFilterChain = null;
38 * Protected constructor
42 protected function __construct ($class) {
43 // Call parent constructor
44 parent::__construct($class);
47 $this->removeNumberFormaters();
48 $this->removeSystemArray();
50 // Initialize both filter chains
51 $this->preFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
52 $this->postFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
54 // Add this controller to the registry
55 Registry::getRegistry()->addInstance('controller', $this);
59 * Adds a filter to the pre filter chain
61 * @param $filterInstance An instance of a filter
64 public function addPreFilter (Filterable $filterInstance) {
66 $this->preFilterChain->addFilter($filterInstance);
70 * Adds a filter to the post filter chain
72 * @param $filterInstance An instance of a filter
75 public function addPostFilter (Filterable $filterInstance) {
76 // Add the post filter
77 $this->postFilterChain->addFilter($filterInstance);
81 * Executes all pre filters
83 * @param $requestInstance An instance of a request class
84 * @param $responseInstance An instance of a response class
87 protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) {
88 // Execute all pre filters
89 $this->preFilterChain->processFilters($requestInstance, $responseInstance);
93 * Executes all post filters
95 * @param $requestInstance An instance of a request class
96 * @param $responseInstance An instance of a response class
99 protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) {
100 // Execute all post filters
101 $this->postFilterChain->processFilters($requestInstance, $responseInstance);