LEPTON CMS 7.4.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
lepton_abstract_frontend.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
26{
27
33 const NOT_SET_IN_INFO = "(unknown - not set in info.php)";
34
40 public array $language = [];
41
47 public array $parents = [];
48
54 public string $module_description = "";
55
60 public static $instance;
61
62
67 public static function getInstance(mixed $value = null): object
68 {
69 if (null === static::$instance)
70 {
71 static::$instance = new static();
72 static::$instance->getParents();
73 static::$instance->getLanguageFile();
74 static::$instance->initialize($value);
75 }
76 return static::$instance;
77 }
78
84 public static function getConstants(): array
85 {
86 // "static::class" here does the magic
87 $reflectionClass = new ReflectionClass(static::class);
88 return $reflectionClass->getConstants();
89 }
90
96 protected function getMainClassNames(string $anyClassname): array
97 {
98 $aElements = explode("_", $anyClassname);
99
100 $sTempName = array_shift($aElements);
101
102 $aReturnValue = [$sTempName];
103
104 foreach ($aElements as $term)
105 {
106 $sTempName .= "_" . $term;
107 $aReturnValue[] = $sTempName;
108 }
109
110 if (count($aReturnValue) > 1)
111 {
112 $aReturnValue = array_reverse($aReturnValue);
113 }
114
115 return $aReturnValue;
116 }
117
118
122 protected function getLanguageFile(): void
123 {
124 if(defined("LEPTON_PATH"))
125 {
126 $aLookUpFilenames = [
127 LANGUAGE."_add.php",
128 LANGUAGE."_custom.php",
129 LANGUAGE.".php",
130 "EN_add.php",
131 "EN_custom.php",
132 "EN.php"
133 ];
134
135 foreach( static::$instance->parents as $sClassNameTop)
136 {
137 // strip namespace
138 $aTemp = explode("\\", $sClassNameTop);
139 $bExitGraceful = false;
140 foreach ($aTemp as $sClassName)
141 {
142 $aMainClassNames = $this->getMainClassNames($sClassName);
143
144 foreach($aMainClassNames as $sTempModuleDirectory)
145 {
146 $lookUpPath = LEPTON_PATH."/modules/".$sTempModuleDirectory."/languages/";
147
148 $bFoundFile = false;
149
150 $sUsedFilename = "";
151 foreach ($aLookUpFilenames as $sTempFilename)
152 {
153 if (true === file_exists($lookUpPath.$sTempFilename))
154 {
155 require $lookUpPath.$sTempFilename;
156 $sUsedFilename = $sTempFilename;
157 $bFoundFile = true;
158 break;
159 }
160 }
161
162 if(false === $bFoundFile)
163 {
164 continue;
165 }
166
167 $tempName = "MOD_".strtoupper($sTempModuleDirectory);
168 if (isset(${$tempName}))
169 {
173 if (str_contains($sUsedFilename, "_add.php"))
174 {
175 $sDefaultFileName = str_replace("_add", "", $sUsedFilename);
176 $aLanguageAdd = ${$tempName};
177
178 require $lookUpPath.$sDefaultFileName;
179
180 ${$tempName} = array_merge(${$tempName}, $aLanguageAdd);
181 }
182
183 static::$instance->language = ${$tempName};
184 $bExitGraceful = true;
185 break;
186 }
187 }
188
189 if (true === $bExitGraceful)
190 {
191 break;
192 }
193 }
194 }
195 }
196 }
197
198
202 protected function getParents(): void
203 {
204 // First the class itself
205 static::$instance->parents[] = get_class(static::$instance);
206
207 // Now the parents
208 $aTempParents = class_parents(static::$instance, true);
209 foreach($aTempParents as $sParentName)
210 {
211 static::$instance->parents[] = $sParentName;
212 }
213 }
214
218 abstract protected function initialize();
219
220}
static getInstance(mixed $value=null)
getMainClassNames(string $anyClassname)