3 * A generic controller class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class BaseController extends BaseFrameworkSystem {
26 * Instance of a CommandResolver class
28 private $resolverInstance = null;
31 * Pre filter chain instance
33 private $preFilterChain = null;
36 * Post filter chain instance
38 private $postFilterChain = null;
41 * Protected constructor
45 protected function __construct ($class) {
46 // Call parent constructor
47 parent::__construct($class);
50 $this->removeNumberFormaters();
51 $this->removeSystemArray();
53 // Initialize both filter chains
54 $this->preFilterChain = FilterChain::createFilterChain();
55 $this->postFilterChain = FilterChain::createFilterChain();
59 * Getter for a command resolver instance
62 * @return $resolverInstance An instance of a command resolver class
64 public final function getResolverInstance () {
65 return $this->resolverInstance;
69 * Setter for a command resolver instance
71 * @param $resolverInstance An instance of a command resolver class
74 public final function setResolverInstance (CommandResolver $resolverInstance) {
75 $this->resolverInstance = $resolverInstance;
79 * Adds a filter to the pre filter chain
81 * @param $filterInstance An instance of a filter
84 public function addPreFilter (Filterable $filterInstance) {
86 $this->preFilterChain->addFilter($filterInstance);
90 * Adds a filter to the post filter chain
92 * @param $filterInstance An instance of a filter
95 public function addPostFilter (Filterable $filterInstance) {
96 // Add the post filter
97 $this->postFilterChain->addFilter($filterInstance);
101 * Executes all pre filters
103 * @param $requestInstance An instance of a request class
104 * @param $responseInstance An instance of a response class
107 protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) {
108 $this->preFilterChain->processFilters($requestInstance, $responseInstance);
112 * Executes all post filters
114 * @param $requestInstance An instance of a request class
115 * @param $responseInstance An instance of a response class
118 protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) {
119 $this->postFilterChain->processFilters($requestInstance, $responseInstance);