AlternativeImplementations   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 7
dl 0
loc 52
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareLoader() 0 25 3
A loadExtensionTables() 0 3 1
A loadExtensionConfiguration() 0 8 2
1
<?php
2
3
/**
4
 * Loading AlternativeImplementations.
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 HDNET\Autoloader\Utility\ClassNamingUtility;
13
use HDNET\Autoloader\Utility\FileUtility;
14
use HDNET\Autoloader\Utility\ReflectionUtility;
15
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Extbase\Object\Container\Container;
18
19
/**
20
 * Loading AlternativeImplementations.
21
 */
22
class AlternativeImplementations implements LoaderInterface
23
{
24
    /**
25
     * Get all the complex data for the loader.
26
     * This return value will be cached and stored in the database
27
     * There is no file monitoring for this cache.
28
     */
29
    public function prepareLoader(Loader $loader, int $type): array
30
    {
31
        $classNames = [];
32
        $alternativeImpPath = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . 'Classes/AlternativeImplementations/';
33
        $alternativeClasses = FileUtility::getBaseFilesInDir($alternativeImpPath, 'php');
34
35
        foreach ($alternativeClasses as $aic) {
36
            $aicClass = ClassNamingUtility::getFqnByPath(
37
                $loader->getVendorName(),
38
                $loader->getExtensionKey(),
39
                'AlternativeImplementations/' . $aic
40
            );
41
42
            if (!$loader->isInstantiableClass($aicClass)) {
43
                continue;
44
            }
45
46
            $classNames[] = [
47
                'originalName' => ReflectionUtility::getParentClassName($aicClass),
48
                'alternativeClassName' => $aicClass,
49
            ];
50
        }
51
52
        return $classNames;
53
    }
54
55
    /**
56
     * Run the loading process for the ext_tables.php file.
57
     */
58
    public function loadExtensionTables(Loader $loader, array $loaderInformation): void
59
    {
60
    }
61
62
    /**
63
     * Run the loading process for the ext_localconf.php file.
64
     */
65
    public function loadExtensionConfiguration(Loader $loader, array $loaderInformation): void
66
    {
67
        /** @var Container $objectManager */
68
        $objectManager = GeneralUtility::makeInstance(Container::class);
69
        foreach ($loaderInformation as $classInformation) {
70
            $objectManager->registerImplementation($classInformation['originalName'], $classInformation['alternativeClassName']);
71
        }
72
    }
73
}
74