2 /***************************************************************
5 * (c) 2010 Jochen Rau <jochen.rau@typoplanet.de>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
26 * Creates a request an dispatches it to the controller which was specified
27 * by TS Setup, Flexform and returns the content to the v4 framework.
29 * This class is the main entry point for extbase extensions.
34 class Tx_Extbase_Core_Bootstrap
{
37 * Back reference to the parent content object
38 * This has to be public as it is set directly from TYPO3
45 * The application context
51 * @var Tx_Extbase_Configuration_ConfigurationManager
53 protected $configurationManager;
56 * @var Tx_Extbase_Object_ObjectManagerInterface
58 protected $objectManager;
61 * @var t3lib_cache_Manager
63 protected $cacheManager;
66 * @var Tx_Extbase_Reflection_Service
68 protected $reflectionService;
71 * @var Tx_Extbase_Persistence_Manager
73 protected $persistenceManager;
78 protected $isInitialized = FALSE;
81 * Explicitly initializes all necessary Extbase objects by invoking the various initialize* methods.
83 * Usually this method is only called from unit tests or other applications which need a more fine grained control over
84 * the initialization and request handling process. Most other applications just call the run() method.
86 * @param array $configuration The TS configuration array
91 public function initialize($configuration) {
92 if (!isset($configuration['extensionName']) ||
strlen($configuration['extensionName']) === 0) {
93 throw new RuntimeException('Invalid configuration: "extensionName" is not set', 1290623020);
95 if (!isset($configuration['pluginName']) ||
strlen($configuration['pluginName']) === 0) {
96 throw new RuntimeException('Invalid configuration: "pluginName" is not set', 1290623027);
98 $this->initializeClassLoader();
99 $this->initializeObjectManager();
100 $this->initializeConfiguration($configuration);
101 $this->configureObjectManager();
102 $this->initializeCache();
103 $this->initializeReflection();
104 $this->initializePersistence();
105 $this->initializeBackwardsCompatibility();
106 $this->isInitialized
= TRUE;
110 * Initializes the autoload mechanism of Extbase. This is supplement to the core autoloader.
115 protected function initializeClassLoader() {
116 if (!class_exists('Tx_Extbase_Utility_ClassLoader', FALSE)) {
117 require(t3lib_extmgm
::extPath('extbase') . 'Classes/Utility/ClassLoader.php');
120 $classLoader = new Tx_Extbase_Utility_ClassLoader();
121 spl_autoload_register(array($classLoader, 'loadClass'));
125 * Initializes the Object framework.
130 protected function initializeObjectManager() {
131 $this->objectManager
= t3lib_div
::makeInstance('Tx_Extbase_Object_ObjectManager');
135 * Initializes the Object framework.
140 public function initializeConfiguration($configuration) {
141 $this->configurationManager
= $this->objectManager
->get('Tx_Extbase_Configuration_ConfigurationManagerInterface');
142 $contentObject = isset($this->cObj
) ?
$this->cObj
: t3lib_div
::makeInstance('tslib_cObj');
143 $this->configurationManager
->setContentObject($contentObject);
144 $this->configurationManager
->setConfiguration($configuration);
148 * Configures the object manager object configuration from
149 * config.tx_extbase.objects
154 public function configureObjectManager() {
155 $typoScriptSetup = $this->configurationManager
->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface
::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
156 if (!is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
159 $objectContainer = t3lib_div
::makeInstance('Tx_Extbase_Object_Container_Container');
160 foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
161 if (isset($classConfiguration['className'])) {
162 $originalClassName = rtrim($classNameWithDot, '.');
163 $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
169 * Initializes the cache framework
174 protected function initializeCache() {
175 t3lib_cache
::initializeCachingFramework();
176 $this->cacheManager
= $GLOBALS['typo3CacheManager'];
178 $this->cacheManager
->getCache('cache_extbase_reflection');
179 } catch (t3lib_cache_exception_NoSuchCache
$exception) {
180 $GLOBALS['typo3CacheFactory']->create(
181 'cache_extbase_reflection',
182 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_extbase_reflection']['frontend'],
183 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_extbase_reflection']['backend'],
184 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_extbase_reflection']['options']
190 * Initializes the Reflection Service
195 protected function initializeReflection() {
196 $this->reflectionService
= $this->objectManager
->get('Tx_Extbase_Reflection_Service');
197 $this->reflectionService
->setDataCache($this->cacheManager
->getCache('cache_extbase_reflection'));
198 if (!$this->reflectionService
->isInitialized()) {
199 $this->reflectionService
->initialize();
204 * Initializes the persistence framework
209 public function initializePersistence() {
210 $this->persistenceManager
= $this->objectManager
->get('Tx_Extbase_Persistence_Manager'); // singleton
214 * Initializes the backwards compatibility. This is necessary because the
215 * old Dispatcher provided several static methods.
220 protected function initializeBackwardsCompatibility() {
221 $dispatcher = t3lib_div
::makeInstance('Tx_Extbase_Dispatcher');
222 $dispatcher->injectConfigurationManager($this->configurationManager
);
223 $dispatcher->injectPersistenceManager($this->persistenceManager
);
227 * Runs the the Extbase Framework by resolving an appropriate Request Handler and passing control to it.
228 * If the Framework is not initialized yet, it will be initialized.
230 * @param string $content The content
231 * @param array $configuration The TS configuration array
232 * @return string $content The processed content
235 public function run($content, $configuration) {
236 //var_dump(Tx_Extbase_Utility_Extension::createAutoloadRegistryForExtension('extbase', t3lib_extMgm::extPath('extbase'), array(
237 // 'tx_extbase_basetestcase' => '$extensionClassesPath . \'../Tests/BaseTestCase.php\''
239 //die("autoload registry");
241 $this->initialize($configuration);
243 $requestHandlerResolver = $this->objectManager
->get('Tx_Extbase_MVC_RequestHandlerResolver');
244 $requestHandler = $requestHandlerResolver->resolveRequestHandler();
246 $response = $requestHandler->handleRequest();
248 // If response is NULL after handling the request we need to stop
249 // This happens for instance, when a USER object was converted to a USER_INT
250 // @see Tx_Extbase_MVC_Web_FrontendRequestHandler::handleRequest()
251 if ($response === NULL) {
252 $this->reflectionService
->shutdown();
255 if (count($response->getAdditionalHeaderData()) > 0) {
256 $GLOBALS['TSFE']->additionalHeaderData
[] = implode(chr(10), $response->getAdditionalHeaderData());
258 $response->sendHeaders();
259 $content = $response->getContent();
261 $this->resetSingletons();
266 * Resets global singletons for the next plugin
270 protected function resetSingletons() {
271 $this->persistenceManager
->persistAll();
272 $this->reflectionService
->shutdown();
276 * This method forwards the call to run(). This method is invoked by the mod.php
279 * @param string $moduleSignature
280 * @return boolean TRUE, if the request request could be dispatched
283 public function callModule($moduleSignature) {
284 if (!isset($GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature])) {
287 $moduleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature];
289 // Check permissions and exit if the user has no permission for entry
290 $GLOBALS['BE_USER']->modAccess($moduleConfiguration, TRUE);
291 if (t3lib_div
::_GP('id')) {
293 $permClause = $GLOBALS['BE_USER']->getPagePermsClause(TRUE);
294 $access = is_array(t3lib_BEfunc
::readPageAccess((integer)t3lib_div
::_GP('id'), $permClause));
296 throw new RuntimeException('You don\'t have access to this page', 1289917924);
300 // BACK_PATH is the path from the typo3/ directory from within the
301 // directory containing the controller file. We are using mod.php dispatcher
302 // and thus we are already within typo3/ because we call typo3/mod.php
303 $GLOBALS['BACK_PATH'] = '';
305 $configuration = array(
306 'extensionName' => $moduleConfiguration['extensionName'],
307 'pluginName' => $moduleSignature
309 $content = $this->run('', $configuration);