StaticTyposcript::prepareLoader()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 16
cp 0
rs 8.5866
c 0
b 0
f 0
cc 7
nc 4
nop 2
crap 56
1
<?php
2
3
/**
4
 * Loading Slots.
5
 */
6
declare(strict_types = 1);
7
8
namespace HDNET\Autoloader\Loader;
9
10
use HDNET\Autoloader\Loader;
11
use HDNET\Autoloader\LoaderInterface;
12
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
15
/**
16
 * Loading Slots.
17
 */
18
class StaticTyposcript implements LoaderInterface
19
{
20
    /**
21
     * Get all the complex data for the loader.
22
     * This return value will be cached and stored in the database
23
     * There is no file monitoring for this cache.
24
     */
25
    public function prepareLoader(Loader $loader, int $type): array
26
    {
27
        $tsConfiguration = [];
28
        $extPath = ExtensionManagementUtility::extPath($loader->getExtensionKey());
29
        $baseDir = $extPath . 'Configuration/TypoScript/';
30
        if (!is_dir($baseDir)) {
31
            return $tsConfiguration;
32
        }
33
        $typoScriptFolder = GeneralUtility::getAllFilesAndFoldersInPath([], $baseDir, '', true, 99, '(.*)\\.(.*)');
34
        $extensionName = GeneralUtility::underscoredToUpperCamelCase($loader->getExtensionKey());
35
36
        foreach ($typoScriptFolder as $folder) {
37
            if (is_file($folder . 'setup.txt') || is_file($folder . 'constants.txt') || is_file($folder . 'setup.typoscript') || is_file($folder . 'constants.typoscript')) {
38
                $setupName = $extensionName . '/' . str_replace($baseDir, '', $folder);
39
                $setupName = implode(' - ', GeneralUtility::trimExplode('/', $setupName, true));
40
                $folder = str_replace($extPath, '', $folder);
41
                $tsConfiguration[] = [
42
                    'path' => $folder,
43
                    'title' => $setupName,
44
                ];
45
            }
46
        }
47
48
        return $tsConfiguration;
49
    }
50
51
    /**
52
     * Run the loading process for the ext_tables.php file.
53
     */
54
    public function loadExtensionTables(Loader $loader, array $loaderInformation): void
55
    {
56
        foreach ($loaderInformation as $tsConfig) {
57
            ExtensionManagementUtility::addStaticFile($loader->getExtensionKey(), $tsConfig['path'], $tsConfig['title']);
58
        }
59
    }
60
61
    /**
62
     * Run the loading process for the ext_localconf.php file.
63
     */
64
    public function loadExtensionConfiguration(Loader $loader, array $loaderInformation): void
65
    {
66
    }
67
}
68