* implemented support for additional header data
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / class.tx_extmvc_dispatcher.php
1 <?php
2 declare(ENCODING = 'utf-8');
3
4 /* *
5 * This script belongs to the FLOW3 framework. *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License as published by the *
9 * Free Software Foundation, either version 3 of the License, or (at your *
10 * option) any later version. *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 // TODO these statements become obsolete with the new autoloader -> remove them
25
26 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/TX_EXTMVC_Request.php');
27 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Web/TX_EXTMVC_Web_Request.php');
28 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/TX_EXTMVC_Response.php');
29 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Web/TX_EXTMVC_Web_Response.php');
30 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Controller/TX_EXTMVC_Controller_AbstractController.php');
31 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Controller/TX_EXTMVC_Controller_ActionController.php');
32 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/View/TX_EXTMVC_View_AbstractView.php');
33 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Persistence/TX_EXTMVC_Persistence_Session.php');
34 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Persistence/Mapper/TX_EXTMVC_Persistence_Mapper_TcaMapper.php');
35
36 // FIXME
37 require_once(t3lib_extMgm::extPath('blogexample') . 'Classes/Controller/TX_Blogexample_Controller_PostsController.php');
38 require_once(t3lib_extMgm::extPath('blogexample') . 'Classes/View/TX_Blogexample_View_PostsIndex.php');
39 require_once(t3lib_extMgm::extPath('blogexample') . 'Classes/View/TX_Blogexample_View_PostsShow.php');
40
41 /**
42 * Creates a request an dispatches it to the controller which was specified by TS Setup, Flexform,
43 * or Extension Configuration (ExtConf), and returns the content to the v4 framework.
44 *
45 * @version $Id:$
46 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
47 */
48 class TX_EXTMVC_Dispatcher {
49
50 /**
51 * @var TX_EXTMVC_Configuration_Manager A reference to the configuration manager
52 */
53 protected $configurationManager;
54
55 /**
56 * @var TX_EXTMVC_Web_RequestBuilder
57 */
58 protected $requestBuilder;
59
60 /**
61 * @var ArrayObject The raw GET parameters
62 */
63 protected $getParameters;
64
65 /**
66 * @var ArrayObject The raw POST parameters
67 */
68 protected $postParameters;
69
70 /**
71 * Constructs this dispatcher
72 *
73 * @author Jochen Rau <jochen.rau@typoplanet.de>
74 */
75 public function __construct() {
76 $this->arguments = new ArrayObject;
77 }
78
79 /**
80 * Creates a request an dispatches it to a controller.
81 *
82 * @param String $content The content
83 * @param array|NULL $configuration The TS configuration array
84 * @return String $content The processed content
85 * @author Robert Lemke <robert@typo3.org>
86 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
87 * @author Jochen Rau <jochen.rau@typoplanet.de>
88 */
89 public function dispatch($content, $configuration) {
90 // debug($configuration);
91 // TODO instantiate the configurationManager
92
93 $request = t3lib_div::makeInstance('TX_EXTMVC_Web_Request');
94 $request->setControllerExtensionKey($configuration['extension']);
95 $request->setControllerName($configuration['controller']);
96 $request->setControllerActionName($configuration['action']);
97
98 $response = t3lib_div::makeInstance('TX_EXTMVC_Web_Response');
99
100 $controllerObjectName = $request->getControllerObjectName();
101 $controller = t3lib_div::makeInstance($controllerObjectName);
102
103 if (!$controller instanceof TX_EXTMVC_Controller_AbstractController) throw new TX_EXTMVC_Exception_InvalidController('Invalid controller "' . $controllerObjectName . '". The controller must be a valid request handling controller.', 1202921619);
104 // $getParameters = t3lib_div::_GET();
105 // $postParameters = t3lib_div::_POST();
106 // $settings = $this->configurationManager->getSettings($extensionKey);
107 // $controller->injectSettings($this->configurationManager->getSettings($request->getControllerExtensionKey()));
108 $session = t3lib_div::makeInstance('TX_EXTMVC_Persistence_Session');
109 try {
110 $controller->processRequest($request, $response);
111 } catch (TX_EXTMVC_Exception_StopAction $ignoredException) {
112 }
113 $session->commit();
114 $session->clear();
115
116 $GLOBALS['TSFE']->additionalHeaderData[$request->getControllerExtensionKey()] = implode("\n", $response->getAdditionalHeaderTags());
117
118 return $response->getContent();
119 }
120
121 }
122 ?>