Completed
Push — cleanup-service ( 04bc88...8942e5 )
by Romain
02:11
created

ExtensionService::getFullExtensionConfiguration()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 0
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\ExtendedFacadeInstanceTrait;
17
use TYPO3\CMS\Core\SingletonInterface;
18
use TYPO3\CMS\Core\Utility\ArrayUtility;
19
20
class ExtensionService implements SingletonInterface
21
{
22
    use ExtendedFacadeInstanceTrait;
23
24
    const EXTENSION_KEY = 'formz';
25
26
    /**
27
     * @var array
28
     */
29
    private $extensionConfiguration;
30
31
    /**
32
     * Return the wanted extension configuration.
33
     *
34
     * @param string $configurationName
35
     * @return mixed
36
     */
37
    public function getExtensionConfiguration($configurationName)
38
    {
39
        $result = null;
40
        $extensionConfiguration = $this->getFullExtensionConfiguration();
41
42
        if (null === $configurationName) {
43
            $result = $extensionConfiguration;
44
        } elseif (ArrayUtility::isValidPath($extensionConfiguration, $configurationName, '.')) {
45
            $result = ArrayUtility::getValueByPath($extensionConfiguration, $configurationName, '.');
46
        }
47
48
        return $result;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    protected function getFullExtensionConfiguration()
55
    {
56
        if (null === $this->extensionConfiguration) {
57
            $this->extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::EXTENSION_KEY]);
58
59
            if (false === $this->extensionConfiguration) {
60
                $this->extensionConfiguration = [];
61
            }
62
        }
63
64
        return $this->extensionConfiguration;
65
    }
66
67
    /**
68
     * @return bool
69
     */
70
    public function isInDebugMode()
71
    {
72
        return (bool)$this->getExtensionConfiguration('debugMode');
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getExtensionKey()
79
    {
80
        return self::EXTENSION_KEY;
81
    }
82
}
83