loadExtensionConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * SymfonyCommandController.
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 TYPO3\CMS\Core\Utility\ArrayUtility;
15
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
16
17
/**
18
 * SymfonyCommandController.
19
 */
20
class SymfonyCommandController implements LoaderInterface
21
{
22
    /**
23
     * Get all the complex data and information for the loader.
24
     * This return value will be cached and stored in the core_cache of TYPO3.
25
     * There is no file monitoring for this cache.
26
     *
27
     * @see https://docs.typo3.org/typo3cms/InsideTypo3Reference/CoreArchitecture/BackendModules/CliScripts/Index.html
28
     */
29
    public function prepareLoader(Loader $loader, int $type): array
30
    {
31
        $classNames = [];
32
        $commandConfigurationFile = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . 'Configuration/Commands.php';
33
34
        if (is_file($commandConfigurationFile)) {
35
            return [];
36
        }
37
38
        $commandPath = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . 'Classes/Command/';
39
        $controllers = FileUtility::getBaseFilesInDir($commandPath, 'php');
40
        foreach ($controllers as $controller) {
41
            $className = ClassNamingUtility::getFqnByPath(
42
                $loader->getVendorName(),
43
                $loader->getExtensionKey(),
44
                'Command/' . $controller
45
            );
46
            if (!$loader->isInstantiableClass($className)) {
47
                continue;
48
            }
49
50
            if (is_subclass_of($className, \Symfony\Component\Console\Command\Command::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Symfony\Component\Console\Command\Command::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
51
                $classNames[lcfirst($controller)] = $className;
52
            }
53
        }
54
55
        if (empty($classNames)) {
56
            return [];
57
        }
58
59
        $configuration = [];
60
        foreach ($classNames as $name => $class) {
61
            $configuration[$loader->getExtensionKey() . ':' . $name] = [
62
                'class' => $class,
63
            ];
64
        }
65
66
        $content = '<?php
67
// This file is geenrated by EXT:autoloader. If you delete this file, clear the System cache and autoloader will generate a new one ;)
68
69
return ' . ArrayUtility::arrayExport($configuration) . ';';
70
71
        FileUtility::writeFileAndCreateFolder($commandConfigurationFile, $content);
72
73
        return $classNames;
74
    }
75
76
    /**
77
     * Run the loading process for the ext_tables.php file.
78
     */
79
    public function loadExtensionTables(Loader $loader, array $loaderInformation): void
80
    {
81
    }
82
83
    /**
84
     * Run the loading process for the ext_localconf.php file.
85
     */
86
    public function loadExtensionConfiguration(Loader $loader, array $loaderInformation): void
87
    {
88
    }
89
}
90