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