TYPO3 API  SVNRelease
Bootstrap.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU Lesser General Public License as published by the *
00008  * Free Software Foundation, either version 3 of the License, or (at your *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00014  * General Public License for more details.                               *
00015  *                                                                        *
00016  * You should have received a copy of the GNU Lesser General Public       *
00017  * License along with the script.                                         *
00018  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 /**
00024  * This is the bootstrap for Ajax Widget responses
00025  *
00026  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00027  */
00028 class Tx_Fluid_Core_Widget_Bootstrap {
00029 
00030     /**
00031      * Back reference to the parent content object
00032      * This has to be public as it is set directly from TYPO3
00033      *
00034      * @var tslib_cObj
00035      */
00036     public $cObj;
00037 
00038     /**
00039      * @var Tx_Extbase_Object_ObjectManagerInterface
00040      */
00041     protected $objectManager;
00042 
00043     /**
00044      * @param string $content The content
00045      * @param array $configuration The TS configuration array
00046      * @return string $content The processed content
00047      */
00048     public function run($content, $configuration) {
00049         $this->initializeClassLoader();
00050         $this->objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
00051         $this->initializeConfiguration($configuration);
00052         $this->configureObjectManager();
00053         $ajaxWidgetContextHolder = $this->objectManager->get('Tx_Fluid_Core_Widget_AjaxWidgetContextHolder');
00054 
00055         $widgetIdentifier = t3lib_div::_GET('fluid-widget-id');
00056         $widgetContext = $ajaxWidgetContextHolder->get($widgetIdentifier);
00057         $configuration['extensionName'] = $widgetContext->getParentExtensionName();
00058         $configuration['pluginName'] = $widgetContext->getParentPluginName();
00059 
00060         $extbaseBootstrap = $this->objectManager->get('Tx_Extbase_Core_Bootstrap');
00061         $extbaseBootstrap->cObj = $this->cObj;
00062         return $extbaseBootstrap->run($content, $configuration);
00063     }
00064 
00065     /**
00066      * Initializes the autoload mechanism of Extbase. This is supplement to the core autoloader.
00067      *
00068      * @return void
00069      * @see initialize()
00070      */
00071     protected function initializeClassLoader() {
00072         if (!class_exists('Tx_Extbase_Utility_ClassLoader', FALSE)) {
00073             require(t3lib_extmgm::extPath('extbase') . 'Classes/Utility/ClassLoader.php');
00074         }
00075 
00076         $classLoader = new Tx_Extbase_Utility_ClassLoader();
00077         spl_autoload_register(array($classLoader, 'loadClass'));
00078     }
00079 
00080     /**
00081      * Initializes the Object framework.
00082      *
00083      * @return void
00084      * @see initialize()
00085      */
00086     public function initializeConfiguration($configuration) {
00087         $this->configurationManager = $this->objectManager->get('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00088         $contentObject = isset($this->cObj) ? $this->cObj : t3lib_div::makeInstance('tslib_cObj');
00089         $this->configurationManager->setContentObject($contentObject);
00090         $this->configurationManager->setConfiguration($configuration);
00091     }
00092 
00093     /**
00094      * Configures the object manager object configuration from
00095      * config.tx_extbase.objects
00096      *
00097      * @return void
00098      * @see initialize()
00099      * @todo this is duplicated code (see Tx_Extbase_Core_Bootstrap::configureObjectManager())
00100      */
00101     public function configureObjectManager() {
00102         $typoScriptSetup = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
00103         if (!is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
00104             return;
00105         }
00106         $objectContainer = t3lib_div::makeInstance('Tx_Extbase_Object_Container_Container');
00107         foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
00108             if (isset($classConfiguration['className'])) {
00109                 $originalClassName = rtrim($classNameWithDot, '.');
00110                 $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
00111             }
00112         }
00113     }
00114 }
00115 
00116 ?>