LEPTON CMS 7.3.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 foreach($aLookUpFilenames as $sTempFilename)
151 {
152 if(true === file_exists( $lookUpPath.$sTempFilename ) )
153 {
154 require $lookUpPath.$sTempFilename;
155 $bFoundFile = true;
156 break;
157 }
158 }
159
160 if(false === $bFoundFile)
161 {
162 continue;
163 }
164
165 $tempName = "MOD_".strtoupper($sTempModuleDirectory);
166 if(isset(${$tempName}))
167 {
168 static::$instance->language = ${$tempName};
169 $bExitGraceful = true;
170 break;
171 }
172 }
173
174 if(true === $bExitGraceful)
175 {
176 break;
177 }
178 }
179 }
180 }
181 }
182
183
187 protected function getParents(): void
188 {
189 // First the class itself
190 static::$instance->parents[] = get_class(static::$instance);
191
192 // Now the parents
193 $aTempParents = class_parents(static::$instance, true);
194 foreach($aTempParents as $sParentName)
195 {
196 static::$instance->parents[] = $sParentName;
197 }
198 }
199
203 abstract protected function initialize();
204
205}
static getInstance(mixed $value=null)
getMainClassNames(string $anyClassname)