* renamed TcaMapper to ObjectRelationalMapper
[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_ObjectRelationalMapper.php');
35
36 // FIXME
37 // require_once(t3lib_extMgm::extPath('blogexample') . 'Classes/Controller/TX_Blogexample_Controller_PostsController.php');
38
39 /**
40 * Creates a request an dispatches it to the controller which was specified by TS Setup, Flexform,
41 * or Extension Configuration (ExtConf), and returns the content to the v4 framework.
42 *
43 * @version $Id:$
44 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
45 */
46 class TX_EXTMVC_Dispatcher {
47
48 /**
49 * @var TX_EXTMVC_Configuration_Manager A reference to the configuration manager
50 */
51 protected $configurationManager;
52
53 /**
54 * @var TX_EXTMVC_Web_RequestBuilder
55 */
56 protected $requestBuilder;
57
58 /**
59 * @var ArrayObject The raw GET parameters
60 */
61 protected $getParameters;
62
63 /**
64 * @var ArrayObject The raw POST parameters
65 */
66 protected $postParameters;
67
68 /**
69 * Constructs this dispatcher
70 *
71 * @author Jochen Rau <jochen.rau@typoplanet.de>
72 */
73 public function __construct() {
74 $this->arguments = new ArrayObject;
75 }
76
77 /**
78 * Creates a request an dispatches it to a controller.
79 *
80 * @param String $content The content
81 * @param array|NULL $configuration The TS configuration array
82 * @return String $content The processed content
83 * @author Robert Lemke <robert@typo3.org>
84 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
85 * @author Jochen Rau <jochen.rau@typoplanet.de>
86 */
87 public function dispatch($content, $configuration) {
88 // debug($configuration);
89 // TODO instantiate the configurationManager
90
91 $request = t3lib_div::makeInstance('TX_EXTMVC_Web_Request');
92 $request->setControllerExtensionKey($configuration['extension']);
93 $request->setControllerName($configuration['controller']);
94 $request->setControllerActionName($configuration['action']);
95
96 $response = t3lib_div::makeInstance('TX_EXTMVC_Web_Response');
97
98 $controllerObjectName = $request->getControllerObjectName();
99 $controller = t3lib_div::makeInstance($controllerObjectName);
100
101 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);
102 // $getParameters = t3lib_div::_GET();
103 // $postParameters = t3lib_div::_POST();
104 // $settings = $this->configurationManager->getSettings($extensionKey);
105 // $controller->injectSettings($this->configurationManager->getSettings($request->getControllerExtensionKey()));
106 $session = t3lib_div::makeInstance('TX_EXTMVC_Persistence_Session');
107 try {
108 $controller->processRequest($request, $response);
109 } catch (TX_EXTMVC_Exception_StopAction $ignoredException) {
110 }
111 $session->commit();
112 $session->clear();
113
114 $GLOBALS['TSFE']->additionalHeaderData[$request->getControllerExtensionKey()] = implode("\n", $response->getAdditionalHeaderTags());
115
116 return $response->getContent();
117 }
118
119 }
120 ?>