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

Localization::useTableNameFileBase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 6
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