[TASK] Streamline phpdoc annotations in EXT:fluid
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Widget / Bootstrap.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 /**
18 * This is the bootstrap for Ajax Widget responses
19 *
20 * @internal This class is only used internally by the widget framework.
21 */
22 class Bootstrap
23 {
24 /**
25 * Back reference to the parent content object
26 * This has to be public as it is set directly from TYPO3
27 *
28 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
29 */
30 public $cObj;
31
32 /**
33 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
34 */
35 protected $objectManager;
36
37 /**
38 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
39 */
40 protected $configurationManager;
41
42 /**
43 * @param string $content The content
44 * @param array $configuration The TS configuration array
45 * @return string $content The processed content
46 */
47 public function run($content, $configuration)
48 {
49 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
50 $this->initializeConfiguration($configuration);
51 $this->configureObjectManager(true);
52 $ajaxWidgetContextHolder = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder::class);
53 $widgetIdentifier = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('fluid-widget-id');
54 $widgetContext = $ajaxWidgetContextHolder->get($widgetIdentifier);
55 $configuration['extensionName'] = $widgetContext->getParentExtensionName();
56 $configuration['pluginName'] = $widgetContext->getParentPluginName();
57 $extbaseBootstrap = $this->objectManager->get(\TYPO3\CMS\Extbase\Core\Bootstrap::class);
58 $extbaseBootstrap->cObj = $this->cObj;
59 return $extbaseBootstrap->run($content, $configuration);
60 }
61
62 /**
63 * Initializes the Object framework.
64 *
65 * @param array $configuration
66 * @see initialize()
67 */
68 public function initializeConfiguration($configuration)
69 {
70 $this->configurationManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class);
71 /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject */
72 $contentObject = $this->cObj ?? \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
73 $this->configurationManager->setContentObject($contentObject);
74 $this->configurationManager->setConfiguration($configuration);
75 }
76
77 /**
78 * Configures the object manager object configuration from
79 * config.tx_extbase.objects
80 *
81 * @param $isInternalCall bool Set to true by Boostrap, not by extensions
82 * @see initialize()
83 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0
84 */
85 public function configureObjectManager(bool $isInternalCall = false)
86 {
87 if (!$isInternalCall) {
88 trigger_error(self::class . '->configureObjectManager() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
89 }
90 $typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
91 if (!is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
92 return;
93 }
94 trigger_error('Overriding object implementations via TypoScript settings config.tx_extbase.objects and plugin.tx_%plugin%.objects will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
95 $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
96 foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
97 if (isset($classConfiguration['className'])) {
98 $originalClassName = rtrim($classNameWithDot, '.');
99 $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
100 }
101 }
102 }
103 }