These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * ContextSensitiveHelp (CSH) based on smart objects. |
||
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\Localization\LanguageHandler; |
||
13 | use HDNET\Autoloader\Service\SmartObjectInformationService; |
||
14 | use HDNET\Autoloader\SmartObjectRegister; |
||
15 | use HDNET\Autoloader\Utility\ClassNamingUtility; |
||
16 | use HDNET\Autoloader\Utility\ModelUtility; |
||
17 | use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
||
18 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||
19 | |||
20 | /** |
||
21 | * ContextSensitiveHelp (CSH) based on smart objects. |
||
22 | */ |
||
23 | class ContextSensitiveHelps implements LoaderInterface |
||
24 | { |
||
25 | /** |
||
26 | * Get all the complex data for the loader. |
||
27 | * This return value will be cached and stored in the database |
||
28 | * There is no file monitoring for this cache. |
||
29 | * |
||
30 | * @param Loader $loader |
||
31 | * @param int $type |
||
32 | * |
||
33 | * @return array |
||
34 | */ |
||
35 | public function prepareLoader(Loader $loader, int $type): array |
||
36 | { |
||
37 | if (LoaderInterface::EXT_TABLES !== $type) { |
||
38 | return []; |
||
39 | } |
||
40 | $modelInformation = $this->findTableAndModelInformationForExtension($loader->getExtensionKey()); |
||
41 | |||
42 | $loaderInformation = []; |
||
43 | foreach ($modelInformation as $information) { |
||
44 | $table = $information['table']; |
||
45 | $path = $this->checkCshValues( |
||
46 | $loader->getExtensionKey(), |
||
47 | $information['table'], |
||
48 | $information['properties'] |
||
49 | ); |
||
50 | if (null !== $path) { |
||
51 | $loaderInformation[$table] = $path; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | return $loaderInformation; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Run the loading process for the ext_tables.php file. |
||
60 | * |
||
61 | * @param Loader $loader |
||
62 | * @param array $loaderInformation |
||
63 | */ |
||
64 | public function loadExtensionTables(Loader $loader, array $loaderInformation) |
||
65 | { |
||
66 | foreach ($loaderInformation as $table => $path) { |
||
67 | ExtensionManagementUtility::addLLrefForTCAdescr($table, $path); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Run the loading process for the ext_localconf.php file. |
||
73 | * |
||
74 | * @param \HDNET\Autoloader\Loader $loader |
||
75 | * @param array $loaderInformation |
||
76 | * |
||
77 | * @internal param \HDNET\Autoloader\Loader $autoLoader |
||
78 | */ |
||
79 | public function loadExtensionConfiguration(Loader $loader, array $loaderInformation) |
||
80 | { |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Find table and model information for the given extension key. |
||
85 | * |
||
86 | * @param string $extensionKey |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | protected function findTableAndModelInformationForExtension($extensionKey) |
||
91 | { |
||
92 | $information = []; |
||
93 | $register = SmartObjectRegister::getRegister(); |
||
94 | foreach ($register as $class) { |
||
95 | $parts = ClassNamingUtility::explodeObjectModelName($class); |
||
96 | if (GeneralUtility::camelCaseToLowerCaseUnderscored($parts['extensionName']) === $extensionKey && '' === ModelUtility::getTableNameByModelReflectionAnnotation($class)) { |
||
97 | $modelInformation = SmartObjectInformationService::getInstance() |
||
98 | ->getCustomModelFieldTca($class); |
||
99 | |||
100 | $information[] = [ |
||
101 | 'table' => ModelUtility::getTableNameByModelName($class), |
||
102 | 'properties' => \array_keys($modelInformation), |
||
103 | ]; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | return $information; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Check if the given file is already existing. |
||
112 | * |
||
113 | * @param string $extensionKey |
||
114 | * @param string $table |
||
115 | * @param array $properties |
||
116 | * |
||
117 | * @return string|null |
||
118 | */ |
||
119 | protected function checkCshValues($extensionKey, $table, array $properties) |
||
120 | { |
||
121 | $baseFileName = 'locallang_csh_' . $table; |
||
122 | /** @var LanguageHandler $languageHandler */ |
||
123 | $languageHandler = GeneralUtility::makeInstance(LanguageHandler::class); |
||
124 | foreach ($properties as $property) { |
||
125 | $default = ''; |
||
126 | $languageHandler->handle($property . '.alttitle', $extensionKey, $default, null, $baseFileName); |
||
0 ignored issues
–
show
|
|||
127 | } |
||
128 | |||
129 | $checkPath = ['xlf', 'xml']; |
||
130 | foreach ($checkPath as $extension) { |
||
131 | $path = 'EXT:' . $extensionKey . '/Resources/Private/Language/' . $baseFileName . '.' . $extension; |
||
132 | if (\is_file(GeneralUtility::getFileAbsFileName($path))) { |
||
133 | return $path; |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: