1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 FormZ project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\Formz\Core; |
15
|
|
|
|
16
|
|
|
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; |
17
|
|
|
use TYPO3\CMS\Core\Database\DatabaseConnection; |
18
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
19
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
20
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
21
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; |
22
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class containing general functions. |
26
|
|
|
*/ |
27
|
|
|
class Core implements SingletonInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var Core |
31
|
|
|
*/ |
32
|
|
|
protected static $instance; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ObjectManagerInterface |
36
|
|
|
*/ |
37
|
|
|
protected $objectManager; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return Core |
41
|
|
|
*/ |
42
|
|
|
public static function get() |
43
|
|
|
{ |
44
|
|
|
if (null === self::$instance) { |
45
|
|
|
/** @var ObjectManager $objectManager */ |
46
|
|
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
47
|
|
|
|
48
|
|
|
self::$instance = $objectManager->get(self::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return self::$instance; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Shortcut for object manager `get()` function. |
56
|
|
|
* |
57
|
|
|
* @param string $className |
58
|
|
|
* @return object |
59
|
|
|
*/ |
60
|
|
|
public static function instantiate($className) |
61
|
|
|
{ |
62
|
|
|
$objectManager = self::get()->getObjectManager(); |
63
|
|
|
$args = func_get_args(); |
64
|
|
|
|
65
|
|
|
if (1 === count($args)) { |
66
|
|
|
return $objectManager->get($className); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return call_user_func_array([$objectManager, 'get'], $args); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return ObjectManagerInterface |
74
|
|
|
*/ |
75
|
|
|
public function getObjectManager() |
76
|
|
|
{ |
77
|
|
|
return $this->objectManager; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param ObjectManagerInterface $objectManager |
82
|
|
|
*/ |
83
|
|
|
public function injectObjectManager(ObjectManagerInterface $objectManager) |
84
|
|
|
{ |
85
|
|
|
$this->objectManager = $objectManager; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return TypoScriptFrontendController |
90
|
|
|
*/ |
91
|
|
|
public function getPageController() |
92
|
|
|
{ |
93
|
|
|
return $GLOBALS['TSFE']; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return BackendUserAuthentication |
98
|
|
|
*/ |
99
|
|
|
public function getBackendUser() |
100
|
|
|
{ |
101
|
|
|
return $GLOBALS['BE_USER']; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return DatabaseConnection |
106
|
|
|
*/ |
107
|
|
|
public function getDatabase() |
108
|
|
|
{ |
109
|
|
|
return $GLOBALS['TYPO3_DB']; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|