05bb6e286f7091a191e6bec2830976cd8ac844c9
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Widget / WidgetRequestBuilder.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\Widget;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Builds the WidgetRequest if an AJAX widget is called.
21 */
22 class WidgetRequestBuilder extends \TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder
23 {
24 /**
25 * @var \TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder
26 */
27 private $ajaxWidgetContextHolder;
28
29 /**
30 * @param \TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder $ajaxWidgetContextHolder
31 */
32 public function injectAjaxWidgetContextHolder(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder $ajaxWidgetContextHolder)
33 {
34 $this->ajaxWidgetContextHolder = $ajaxWidgetContextHolder;
35 }
36
37 /**
38 * Builds a widget request object from the raw HTTP information
39 *
40 * @return \TYPO3\CMS\Fluid\Core\Widget\WidgetRequest The widget request as an object
41 */
42 public function build()
43 {
44 $request = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class);
45 $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
46 $request->setBaseUri(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
47 $request->setMethod(isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null);
48 if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
49 $request->setArguments(GeneralUtility::_POST());
50 } else {
51 $request->setArguments(GeneralUtility::_GET());
52 }
53 $rawGetArguments = GeneralUtility::_GET();
54 if (isset($rawGetArguments['action'])) {
55 $request->setControllerActionName($rawGetArguments['action']);
56 }
57 $widgetContext = $this->ajaxWidgetContextHolder->get($rawGetArguments['fluid-widget-id']);
58 $request->setWidgetContext($widgetContext);
59 return $request;
60 }
61 }