Completed
Push — cleanup-service ( 79a539...af4cdb )
by Romain
02:30
created

Core::sanitizeString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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\SingletonInterface;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
use TYPO3\CMS\Extbase\Object\ObjectManager;
20
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
21
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
22
23
/**
24
 * Class containing general functions.
25
 */
26
class Core implements SingletonInterface
27
{
28
    /**
29
     * @var Core
30
     */
31
    protected static $instance;
32
33
    /**
34
     * @var ObjectManagerInterface
35
     */
36
    protected $objectManager;
37
38
    /**
39
     * @return Core
40
     */
41
    public static function get()
42
    {
43
        if (null === self::$instance) {
44
            /** @var ObjectManager $objectManager */
45
            $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
46
47
            self::$instance = $objectManager->get(self::class);
48
        }
49
50
        return self::$instance;
51
    }
52
53
    /**
54
     * Shortcut for object manager `get()` function.
55
     *
56
     * @param string $className
57
     * @return object
58
     */
59
    public static function instantiate($className)
60
    {
61
        $objectManager = self::get()->getObjectManager();
62
63
        return call_user_func_array([$objectManager, 'get'], func_get_args());
64
    }
65
66
    /**
67
     * @return ObjectManagerInterface
68
     */
69
    public function getObjectManager()
70
    {
71
        return $this->objectManager;
72
    }
73
74
    /**
75
     * @param ObjectManagerInterface $objectManager
76
     */
77
    public function injectObjectManager(ObjectManagerInterface $objectManager)
78
    {
79
        $this->objectManager = $objectManager;
80
    }
81
82
    /**
83
     * @return TypoScriptFrontendController
84
     */
85
    public function getPageController()
86
    {
87
        return $GLOBALS['TSFE'];
88
    }
89
90
    /**
91
     * @return BackendUserAuthentication
92
     */
93
    public function getBackendUser()
94
    {
95
        return $GLOBALS['BE_USER'];
96
    }
97
}
98