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