Completed
Push — master ( d29ed6...f07621 )
by Tim
09:53
created

StaticTyposcript   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 0
loc 61
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadExtensionTables() 0 6 2
A loadExtensionConfiguration() 0 3 1
B prepareLoader() 0 25 7
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
     * @param Loader $loader
26
     * @param int    $type
27
     *
28
     * @return array
29
     */
30
    public function prepareLoader(Loader $loader, int $type): array
31
    {
32
        $tsConfiguration = [];
33
        $extPath = ExtensionManagementUtility::extPath($loader->getExtensionKey());
34
        $baseDir = $extPath . 'Configuration/TypoScript/';
35
        if (!\is_dir($baseDir)) {
36
            return $tsConfiguration;
37
        }
38
        $typoScriptFolder = GeneralUtility::getAllFilesAndFoldersInPath([], $baseDir, '', true, 99, '(.*)\\.(.*)');
39
        $extensionName = GeneralUtility::underscoredToUpperCamelCase($loader->getExtensionKey());
40
41
        foreach ($typoScriptFolder as $folder) {
42
            if (\is_file($folder . 'setup.txt') || \is_file($folder . 'constants.txt') || \is_file($folder . 'setup.typoscript') || \is_file($folder . 'constants.typoscript')) {
43
                $setupName = $extensionName . '/' . \str_replace($baseDir, '', $folder);
44
                $setupName = \implode(' - ', GeneralUtility::trimExplode('/', $setupName, true));
45
                $folder = \str_replace($extPath, '', $folder);
46
                $tsConfiguration[] = [
47
                    'path' => $folder,
48
                    'title' => $setupName,
49
                ];
50
            }
51
        }
52
53
        return $tsConfiguration;
54
    }
55
56
    /**
57
     * Run the loading process for the ext_tables.php file.
58
     *
59
     * @param Loader $loader
60
     * @param array  $loaderInformation
61
     */
62
    public function loadExtensionTables(Loader $loader, array $loaderInformation)
63
    {
64
        foreach ($loaderInformation as $tsConfig) {
65
            ExtensionManagementUtility::addStaticFile($loader->getExtensionKey(), $tsConfig['path'], $tsConfig['title']);
66
        }
67
    }
68
69
    /**
70
     * Run the loading process for the ext_localconf.php file.
71
     *
72
     * @param Loader $loader
73
     * @param array  $loaderInformation
74
     */
75
    public function loadExtensionConfiguration(Loader $loader, array $loaderInformation)
76
    {
77
    }
78
}
79