2db45d86cc13bb3418461f6b2c2b8d62256832ae
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Core / ModuleRunner.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Core;
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 /**
18 * Dispatches a request
19 */
20 class ModuleRunner implements ModuleRunnerInterface {
21
22 /**
23 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
24 * @inject
25 */
26 protected $objectManager;
27
28 /**
29 * This method forwards the call to Bootstrap's run() method. This method is invoked by the mod.php
30 * function of TYPO3.
31 *
32 * @param string $moduleSignature
33 * @throws \RuntimeException
34 * @return bool TRUE, if the request request could be dispatched
35 * @see run()
36 */
37 public function callModule($moduleSignature) {
38 if (!isset($GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature])) {
39 return FALSE;
40 }
41 $moduleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature];
42
43 // Check permissions and exit if the user has no permission for entry
44 $GLOBALS['BE_USER']->modAccess($moduleConfiguration, TRUE);
45 $id = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
46 if ($id && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) {
47 // Check page access
48 $permClause = $GLOBALS['BE_USER']->getPagePermsClause(TRUE);
49 $access = is_array(\TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess((int)$id, $permClause));
50 if (!$access) {
51 throw new \RuntimeException('You don\'t have access to this page', 1289917924);
52 }
53 }
54
55 // BACK_PATH is the path from the typo3/ directory from within the
56 // directory containing the controller file. We are using mod.php dispatcher
57 // and thus we are already within typo3/ because we call typo3/mod.php
58 $GLOBALS['BACK_PATH'] = '';
59 $configuration = array(
60 'extensionName' => $moduleConfiguration['extensionName'],
61 'pluginName' => $moduleSignature
62 );
63 if (isset($moduleConfiguration['vendorName'])) {
64 $configuration['vendorName'] = $moduleConfiguration['vendorName'];
65 }
66
67 $bootstrap = $this->objectManager->get(\TYPO3\CMS\Extbase\Core\BootstrapInterface::class);
68 $content = $bootstrap->run('', $configuration);
69 print $content;
70
71 return TRUE;
72 }
73
74 }