TYPO3 CMS  TYPO3_6-2
Bootstrap.php
Go to the documentation of this file.
1 <?php
3 
23 
30  public $cObj;
31 
37  protected $context;
38 
43 
47  protected $objectManager;
48 
52  protected $cacheManager;
53 
57  protected $reflectionService;
58 
63 
76  public function initialize($configuration) {
77  if (!$this->isInCliMode()) {
78  if (!isset($configuration['extensionName']) || strlen($configuration['extensionName']) === 0) {
79  throw new \RuntimeException('Invalid configuration: "extensionName" is not set', 1290623020);
80  }
81  if (!isset($configuration['pluginName']) || strlen($configuration['pluginName']) === 0) {
82  throw new \RuntimeException('Invalid configuration: "pluginName" is not set', 1290623027);
83  }
84  }
85  $this->initializeObjectManager();
86  $this->initializeConfiguration($configuration);
87  $this->configureObjectManager();
88  $this->initializeCache();
89  $this->initializeReflection();
90  $this->initializePersistence();
91  }
92 
99  protected function initializeObjectManager() {
100  $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
101  }
102 
110  public function initializeConfiguration($configuration) {
111  $this->configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
113  $contentObject = isset($this->cObj) ? $this->cObj : \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
114  $this->configurationManager->setContentObject($contentObject);
115  $this->configurationManager->setConfiguration($configuration);
116  }
117 
125  public function configureObjectManager() {
126  $frameworkSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
127  if (!is_array($frameworkSetup['objects'])) {
128  return;
129  }
130  $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
131  foreach ($frameworkSetup['objects'] as $classNameWithDot => $classConfiguration) {
132  if (isset($classConfiguration['className'])) {
133  $originalClassName = rtrim($classNameWithDot, '.');
134  $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
135  }
136  }
137  }
138 
145  protected function initializeCache() {
146  $this->cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
147  }
148 
155  protected function initializeReflection() {
156  $this->reflectionService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
157  $this->reflectionService->setDataCache($this->cacheManager->getCache('extbase_reflection'));
158  if (!$this->reflectionService->isInitialized()) {
159  $this->reflectionService->initialize();
160  }
161  }
162 
169  public function initializePersistence() {
170  $this->persistenceManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
171  }
172 
182  public function run($content, $configuration) {
183  $this->initialize($configuration);
184  return $this->handleRequest();
185  }
186 
190  protected function handleRequest() {
192  $requestHandlerResolver = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\RequestHandlerResolver');
193  $requestHandler = $requestHandlerResolver->resolveRequestHandler();
194 
195  $response = $requestHandler->handleRequest();
196  // If response is NULL after handling the request we need to stop
197  // This happens for instance, when a USER object was converted to a USER_INT
198  // @see TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::handleRequest()
199  if ($response === NULL) {
200  $this->reflectionService->shutdown();
201  $content = '';
202  } else {
203  $content = $response->shutdown();
204  $this->resetSingletons();
205  $this->objectManager->get('TYPO3\CMS\Extbase\Service\CacheService')->clearCachesOfRegisteredPageIds();
206  }
207 
208  return $content;
209  }
210 
216  protected function resetSingletons() {
217  $this->persistenceManager->persistAll();
218  $this->reflectionService->shutdown();
219  }
220 
224  protected function isInCliMode() {
225  return (defined('TYPO3_cliMode') && TYPO3_cliMode);
226  }
227 }
run($content, $configuration)
Definition: Bootstrap.php:182