[BUGFIX] Expose IconFactory in ModuleTemplate rather than AbstractModule
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Module / AbstractModule.php
1 <?php
2 namespace TYPO3\CMS\Backend\Module;
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 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Template\ModuleTemplate;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * A backend module. This class may be used by extension backend modules
25 * to implement own actions and controllers. It initializes the module
26 * template and comes with a simple dispatcher method.
27 *
28 * @internal Experimental for now
29 */
30 class AbstractModule {
31
32 /**
33 * ModuleTemplate object
34 *
35 * @var ModuleTemplate
36 */
37 protected $moduleTemplate;
38
39 /**
40 * Constructor Method
41 */
42 public function __construct() {
43 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
44 }
45
46 /**
47 * PSR Request Object
48 *
49 * @var ServerRequestInterface
50 */
51 protected $request;
52
53 /**
54 * Central Request Dispatcher
55 *
56 * @param ServerRequestInterface $request PSR7 Request Object
57 * @param ResponseInterface $response PSR7 Response Object
58 *
59 * @return ResponseInterface
60 *
61 * @throws \InvalidArgumentException In case an action is not callable
62 */
63 public function processRequest(ServerRequestInterface $request, ResponseInterface $response) {
64 $methodName = $request->getQueryParams()['action'] ?: 'index';
65 if (!is_callable([$this, $methodName])) {
66 throw new \InvalidArgumentException(
67 'The method "' . $methodName . '" is not callable within "' . get_class($this) . '".',
68 1442736343
69 );
70 }
71 return $this->{$methodName}($request, $response);
72 }
73 }