3 namespace CoreFramework\Tests\Controller;
5 // Import framework stuff
6 use CoreFramework\Controller\BaseController;
9 * The default controller with news for e.g. home or news page
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class TestsConsoleDefaultNewsController extends BaseController implements Controller {
32 * Protected constructor
36 protected function __construct () {
37 // Call parent constructor
38 parent::__construct(__CLASS__);
40 // Init additional filter chains
42 foreach (array('bootstrap', 'activation','shutdown') as $filterChain) {
43 $this->initFilterChain($filterChain);
49 * Creates an instance of this class
51 * @param $resolverInstance An instance of a command resolver class
52 * @return $controllerInstance A prepared instance of this class
54 public static final function createTestsConsoleDefaultNewsController (CommandResolver $resolverInstance) {
55 // Create the instance
56 $controllerInstance = new TestsConsoleDefaultNewsController();
58 // Set the command resolver
59 $controllerInstance->setResolverInstance($resolverInstance);
61 // Add news filters to this controller
62 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter'));
63 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter'));
65 // Return the prepared instance
66 return $controllerInstance;
70 * Handles the given request and response
72 * @param $requestInstance An instance of a request class
73 * @param $responseInstance An instance of a response class
76 public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
77 // Get the command instance from the resolver by sending a request instance to the resolver
78 $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
80 // Add more filters by the command
81 $commandInstance->addExtraFilters($this, $requestInstance);
83 // Run the pre filters
84 $this->executePreFilters($requestInstance, $responseInstance);
86 // This request was valid! :-D
87 $requestInstance->requestIsValid();
89 // Execute the command
90 $commandInstance->execute($requestInstance, $responseInstance);
92 // Run the pre filters
93 $this->executePostFilters($requestInstance, $responseInstance);
95 // Flush the response out
96 $responseInstance->flushBuffer();
100 * Add a bootstrap filter
102 * @param $filterInstance A Filterable class
105 public function addBootstrapFilter (Filterable $filterInstance) {
106 $this->addFilter('bootstrap', $filterInstance);
110 * Executes all bootstrap filters
112 * @param $requestInstance A Requestable class
113 * @param $responseInstance A Responseable class
116 public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
117 $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
121 * Add a hub activation filter
123 * @param $filterInstance A Filterable class
126 public function addActivationFilter (Filterable $filterInstance) {
127 $this->addFilter('activation', $filterInstance);
131 * Executes all hub activation filters
133 * @param $requestInstance A Requestable class
134 * @param $responseInstance A Responseable class
137 public function executeActivationFilters (Requestable $requestInstance, Responseable $responseInstance) {
138 $this->executeFilters('activation', $requestInstance, $responseInstance);