Completed
Push — master ( 86d3fe...d815fa )
by Tim
10:20
created

Localization   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 34
ccs 0
cts 4
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assureLabel() 0 11 2
A useTableNameFileBase() 0 5 2
1
<?php
2
/**
3
 * handler to create the labels.
4
 */
5
6
namespace HDNET\Autoloader\Hooks;
7
8
use HDNET\Autoloader\Localization\LanguageHandler;
9
use TYPO3\CMS\Core\Utility\GeneralUtility;
10
11
/**
12
 * handler to create the labels.
13
 *
14
 * @hook TYPO3_CONF_VARS|EXTCONF|autoloader|assureLabel
15
 */
16
class Localization
17
{
18
    /**
19
     * Take care that the label exists.
20
     *
21
     * @param string $key key in the localization file
22
     * @param string $extensionName
23
     * @param string $default default value of the label
24
     * @param array $arguments arguments are being passed over to vsprintf
25
     * @param string $tableName The tablename of the given table (null, in non table context)
26
     */
27
    public function assureLabel($key, $extensionName, &$default, $arguments, $tableName)
28
    {
29
        $overrideBaseName = null;
30
        if($this->useTableNameFileBase()) {
31
            $overrideBaseName = $tableName;
32
        }
33
34
        /** @var LanguageHandler $languageHandler */
35
        $languageHandler = GeneralUtility::makeInstance(LanguageHandler::class);
36
        $default = $languageHandler->handle($key, $extensionName, $default, $arguments, $overrideBaseName);
37
    }
38
39
    /**
40
     * Check if table name file base is used
41
     *
42
     * @return bool
43
     */
44
    protected function useTableNameFileBase()
45
    {
46
        $configuration = unserialize((string)$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['autoloader']);
47
        return isset($configuration['enableLanguageFileOnTableBase']) ? (bool)$configuration['enableLanguageFileOnTableBase'] : false;
48
    }
49
}
50