ExtensionService   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 71
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getExtensionConfiguration() 0 13 3
A getFullExtensionConfiguration() 0 12 3
A getExtensionRelativePath() 0 4 1
A isInDebugMode() 0 4 1
A getExtensionKey() 0 4 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\Service;
15
16
use Romm\Formz\Service\Traits\SelfInstantiateTrait;
17
use TYPO3\CMS\Core\SingletonInterface;
18
use TYPO3\CMS\Core\Utility\ArrayUtility;
19
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20
21
class ExtensionService implements SingletonInterface
22
{
23
    use SelfInstantiateTrait;
24
25
    const EXTENSION_KEY = 'formz';
26
27
    /**
28
     * @var array
29
     */
30
    private $extensionConfiguration;
31
32
    /**
33
     * Return the wanted extension configuration.
34
     *
35
     * @param string $configurationName
36
     * @return mixed
37
     */
38
    public function getExtensionConfiguration($configurationName)
39
    {
40
        $result = null;
41
        $extensionConfiguration = $this->getFullExtensionConfiguration();
42
43
        if (null === $configurationName) {
44
            $result = $extensionConfiguration;
45
        } elseif (ArrayUtility::isValidPath($extensionConfiguration, $configurationName, '.')) {
46
            $result = ArrayUtility::getValueByPath($extensionConfiguration, $configurationName, '.');
47
        }
48
49
        return $result;
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    protected function getFullExtensionConfiguration()
56
    {
57
        if (null === $this->extensionConfiguration) {
58
            $this->extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::EXTENSION_KEY]);
59
60
            if (false === $this->extensionConfiguration) {
61
                $this->extensionConfiguration = [];
62
            }
63
        }
64
65
        return $this->extensionConfiguration;
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getExtensionRelativePath()
72
    {
73
        return ExtensionManagementUtility::siteRelPath(self::EXTENSION_KEY);
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function isInDebugMode()
80
    {
81
        return (bool)$this->getExtensionConfiguration('debugMode');
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getExtensionKey()
88
    {
89
        return self::EXTENSION_KEY;
90
    }
91
}
92