[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Scheduler / TaskExecutor.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Scheduler;
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 * Task Executor
18 *
19 * Takes a \TYPO3\CMS\Extbase\Scheduler\Task and executes the CommandController command
20 * defined therein.
21 */
22 class TaskExecutor implements \TYPO3\CMS\Core\SingletonInterface {
23
24 /**
25 * @var \TYPO3\CMS\Extbase\Mvc\Cli\Request
26 */
27 protected $request;
28
29 /**
30 * @var \TYPO3\CMS\Extbase\Mvc\Cli\Response
31 */
32 protected $response;
33
34 /**
35 * @var \TYPO3\CMS\Extbase\Mvc\Dispatcher
36 */
37 protected $dispatcher;
38
39 /**
40 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
41 * @inject
42 */
43 protected $objectManager;
44
45 /**
46 * @var \TYPO3\CMS\Extbase\Mvc\Cli\CommandManager
47 * @inject
48 */
49 protected $commandManager;
50
51 /**
52 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
53 * @inject
54 */
55 protected $configurationManager;
56
57 /**
58 * Initialize Dispatcher
59 */
60 public function initializeObject() {
61 $this->dispatcher = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Dispatcher::class);
62 }
63
64 /**
65 * Initializes configuration manager, object container and reflection service
66 *
67 * @param array $configuration
68 * @return void
69 */
70 protected function initialize(array $configuration) {
71 // initialize unconsumed Request and Response
72 $this->request = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\Request::class);
73 $this->response = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\Response::class);
74 // initialize configuration
75 $this->configurationManager->setContentObject(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class));
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::class);
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::class);
90 $reflectionService->setDataCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('extbase_reflection'));
91 if (!$reflectionService->isInitialized()) {
92 $reflectionService->initialize();
93 }
94 }
95
96 /**
97 * Execute Task
98 *
99 * If errors occur during Task execution they are thrown as Exceptions which
100 * must be caught manually if you manually execute Tasks through your code.
101 *
102 * @param \TYPO3\CMS\Extbase\Scheduler\Task $task the task to execute
103 * @return void
104 */
105 public function execute(\TYPO3\CMS\Extbase\Scheduler\Task $task) {
106 $commandIdentifier = $task->getCommandIdentifier();
107 list($extensionKey, $controllerName, $commandName) = explode(':', $commandIdentifier);
108 $extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($extensionKey);
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
119 /**
120 * Resets framework singletons
121 *
122 * @return void
123 */
124 protected function shutdown() {
125 // shutdown
126 $persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
127 $persistenceManager->persistAll();
128 $reflectionService = $this->objectManager->get(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
129 $reflectionService->shutdown();
130 }
131 }