TYPO3 CMS  TYPO3_6-2
TaskExecutor.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $request;
28 
32  protected $response;
33 
37  protected $dispatcher;
38 
43  protected $objectManager;
44 
49  protected $commandManager;
50 
56 
60  public function initializeObject() {
61  $this->dispatcher = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Dispatcher');
62  }
63 
70  protected function initialize(array $configuration) {
71  // initialize unconsumed Request and Response
72  $this->request = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Request');
73  $this->response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Response');
74  // initialize configuration
75  $this->configurationManager->setContentObject(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'));
76  $this->configurationManager->setConfiguration($configuration);
77  // configure object container
78  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
79  if (isset($frameworkConfiguration['objects'])) {
80  $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
81  foreach ($frameworkConfiguration['objects'] as $classNameWithDot => $classConfiguration) {
82  if (isset($classConfiguration['className'])) {
83  $originalClassName = rtrim($classNameWithDot, '.');
84  $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
85  }
86  }
87  }
88  // initialize reflection
89  $reflectionService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
90  $reflectionService->setDataCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('extbase_reflection'));
91  if (!$reflectionService->isInitialized()) {
92  $reflectionService->initialize();
93  }
94  }
95 
105  public function execute(\TYPO3\CMS\Extbase\Scheduler\Task $task) {
106  $commandIdentifier = $task->getCommandIdentifier();
107  list($extensionKey, $controllerName, $commandName) = explode(':', $commandIdentifier);
109  $this->initialize(array('extensionName' => $extensionName));
110  // execute command
111  $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
112  $this->request->setControllerObjectName($command->getControllerClassName());
113  $this->request->setControllerCommandName($command->getControllerCommandName());
114  $this->request->setArguments($task->getArguments());
115  $this->dispatcher->dispatch($this->request, $this->response);
116  $this->shutdown();
117  }
118 
124  protected function shutdown() {
125  // shutdown
126  $persistenceManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
127  $persistenceManager->persistAll();
128  $reflectionService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
129  $reflectionService->shutdown();
130  }
131 }
execute(\TYPO3\CMS\Extbase\Scheduler\Task $task)