LEPTON CMS 7.2.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_custom.php",
131 "EN.php"
132 ];
133
134 foreach( static::$instance->parents as $sClassNameTop)
135 {
136 // strip namespace
137 $aTemp = explode("\\", $sClassNameTop);
138 $bExitGraceful = false;
139 foreach( $aTemp as $sClassName )
140 {
141 $aMainClassNames = $this->getMainClassNames( $sClassName );
142
143 foreach($aMainClassNames as $sTempModuleDirectory)
144 {
145 $lookUpPath = LEPTON_PATH."/modules/".$sTempModuleDirectory."/languages/";
146
147 $bFoundFile = false;
148
149 foreach($aLookUpFilenames as $sTempFilename)
150 {
151 if(true === file_exists( $lookUpPath.$sTempFilename ) )
152 {
153 require $lookUpPath.$sTempFilename;
154 $bFoundFile = true;
155 break;
156 }
157 }
158
159 if(false === $bFoundFile)
160 {
161 continue;
162 }
163
164 $tempName = "MOD_".strtoupper($sTempModuleDirectory);
165 if(isset(${$tempName}))
166 {
167 static::$instance->language = ${$tempName};
168 $bExitGraceful = true;
169 break;
170 }
171 }
172
173 if(true === $bExitGraceful)
174 {
175 break;
176 }
177 }
178 }
179 }
180 }
181
182
186 protected function getParents(): void
187 {
188 // First the class itself
189 static::$instance->parents[] = get_class(static::$instance);
190
191 // Now the parents
192 $aTempParents = class_parents(static::$instance, true);
193 foreach($aTempParents as $sParentName)
194 {
195 static::$instance->parents[] = $sParentName;
196 }
197 }
198
202 abstract protected function initialize();
203
204}
static getInstance(mixed $value=null)
getMainClassNames(string $anyClassname)