228e9768e40e65b4aa6553ecfaffe71a3649b008
[Packages/TYPO3.CMS.git] / typo3 / sysext / sys_note / Classes / Core / Bootstrap.php
1 <?php
2 namespace TYPO3\CMS\SysNote\Core;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
8 *
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Bootstrap for note module
30 *
31 * @author Kai Vogel <kai.vogel@speedprogs.de>
32 */
33 class Bootstrap {
34
35 /**
36 * Do not touch if you are not sure what you are doing!
37 * @var array
38 */
39 protected $extbaseConfiguration = array(
40 'vendorName' => 'TYPO3\\CMS',
41 'extensionName' => 'SysNote',
42 'pluginName' => 'Note',
43 );
44
45 /**
46 * @var array
47 */
48 protected $currentGetArguments;
49
50 /**
51 * Bootstrap extbase and execute controller
52 *
53 * @param string $controllerName Controller to execute
54 * @param string $actionName Action to run
55 * @param array $arguments Arguments to pass to the controller action
56 * @return string
57 */
58 public function run($controllerName, $actionName, array $arguments = array()) {
59 $arguments['controller'] = ucfirst(trim($controllerName));
60 $arguments['action'] = lcfirst(trim($actionName));
61 $this->overrideGetArguments($arguments);
62 /** @var $extbaseBootstrap \TYPO3\CMS\Extbase\Core\Bootstrap */
63 $extbaseBootstrap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Core\\Bootstrap');
64 $content = $extbaseBootstrap->run('', $this->extbaseConfiguration);
65 $this->revertGetArguments();
66 return $content;
67 }
68
69 /**
70 * Modify $_GET to force specific controller, action and arguments in
71 * extbase bootstrap process
72 *
73 * Note: Overwriting $_GET was the most simple solution here until extbase
74 * provides a clean way to force a controller and action in backend mode.
75 *
76 * @param array $arguments The arguments to set
77 * @return void
78 */
79 protected function overrideGetArguments(array $arguments) {
80 $this->currentGetArguments = $_GET;
81 $_GET['tx_sysnote_note'] = $arguments;
82 }
83
84 /**
85 * Revert previously backuped get arguments
86 *
87 * @return void
88 */
89 protected function revertGetArguments() {
90 if (is_array($this->currentGetArguments)) {
91 $_GET = $this->currentGetArguments;
92 }
93 }
94
95 }