3 * A console controller for the cruncher, which is our very first hub
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class HubConsoleCruncherController extends BaseController implements Controller {
27 * Protected constructor
31 protected function __construct () {
32 // Call parent constructor
33 parent::__construct(__CLASS__);
35 // Init additional filter chains
36 foreach (array('bootstrap','shutdown') as $filterChain) {
37 $this->initFilterChain($filterChain);
42 * Creates an instance of this class
44 * @param $resolverInstance An instance of a command resolver class
45 * @return $controllerInstance A prepared instance of this class
47 public static final function createHubConsoleCruncherController (CommandResolver $resolverInstance) {
48 // Create the instance
49 $controllerInstance = new HubConsoleCruncherController();
51 // Set the command resolver
52 $controllerInstance->setResolverInstance($resolverInstance);
54 // Return the prepared instance
55 return $controllerInstance;
59 * Handles the given request and response
61 * @param $requestInstance An instance of a request class
62 * @param $responseInstance An instance of a response class
65 public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
66 // Get the command instance from the resolver by sending a request instance to the resolver
67 $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
69 // Add more filters by the command
70 $commandInstance->addExtraFilters($this, $requestInstance);
72 // Run the pre filters
73 $this->executePreFilters($requestInstance, $responseInstance);
75 // This request was valid! :-D
76 $requestInstance->requestIsValid();
78 // Execute the command
79 $commandInstance->execute($requestInstance, $responseInstance);
81 // Run the pre filters
82 $this->executePostFilters($requestInstance, $responseInstance);
84 // Flush the response out
85 $responseInstance->flushBuffer();
89 * Add a bootstrap filter
91 * @param $filterInstance A Filterable class
94 public function addBootstrapFilter (Filterable $filterInstance) {
95 $this->addFilter('bootstrap', $filterInstance);
99 * Executes all bootstrap filters
101 * @param $requestInstance A Requestable class
102 * @param $responseInstance A Responseable class
105 public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
106 $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
110 * Add a shutdown filter
112 * @param $filterInstance A Filterable class
115 public function addShutdownFilter (Filterable $filterInstance) {
116 $this->addFilter('shutdown', $filterInstance);
120 * Executes all shutdown filters
122 * @param $requestInstance A Requestable class
123 * @param $responseInstance A Responseable class
126 public function executeShutdownFilters (Requestable $requestInstance, Responseable $responseInstance) {
127 $this->executeFilters('shutdown', $requestInstance, $responseInstance);