11<?php
22
3- declare (strict_types = 1 );
3+ declare (strict_types= 1 );
44
55namespace Aautoloder ;
66
1313 *
1414 * This autoloader class Loader have three methods inside that checks for classes
1515 *
16- * @author Samet Tarim ( prod3v3loper)
17- * @copyright (c) 2017, Samet Tarim
18- * @link https://www.tnado .com/
16+ * @author prod3v3loper
17+ * @copyright (c) 2024, prod3v3loper
18+ * @link https://www.prod3v3loper .com/
1919 * @package Melabuai
20- * @subpackage autoloader
21- * @since 1.0
20+ * @subpackage Autoloader
21+ * @version 1.1
22+ * @since 1.1
2223 * @see https://github.com/prod3v3loper/php-auto-autoloader
2324 */
24- class Loader extends LoaderHelper {
25-
25+ class Loader extends LoaderHelper
26+ {
2627 /**
2728 * Directory for loop
28- * @var type
29+ *
30+ * @var array $dir
2931 */
30- private $ dir = array () ;
32+ private $ dir = [] ;
3133
3234 /**
3335 * File for require class
34- * @var type
36+ *
37+ * @var array $file
3538 */
36- private $ file = '' ;
39+ private $ file = [] ;
3740
3841 /**
3942 * Empty Array for all forced Files and folders
40- * @var type
43+ *
44+ * @var array $list
4145 */
42- private $ list = array () ;
46+ private $ list = [] ;
4347
4448 /**
4549 * Found state
46- * @var type
50+ *
51+ * @var boolean $found
4752 */
4853 protected $ found = false ;
4954
5055 /**
5156 * Instance - interface, class, extends classes, abstract classes, trait
52- * @var type
57+ *
58+ * @var string $instance
5359 */
54- protected $ insatnce = '' ;
60+ protected $ instance = '' ;
5561
5662 /**
5763 * Namespace
58- * @var type
64+ *
65+ * @var string $namespace
5966 */
6067 protected $ namespace = '' ;
6168
62- /**
63- * Constructor
64- */
65- public function __construct (array $ dir ) {
66-
67- $ this ->dir = $ dir ; // Root path dir/folder to force recrusive
68- $ this ->action (); // Action
69+ public function __construct (array $ dir )
70+ {
71+ $ this ->dir = $ dir ;
72+ $ this ->action ();
6973
7074 if (!file_exists (MBT_CORE_AUTOLOAD_LOG_FOLDER )) {
7175 mkdir (MBT_CORE_AUTOLOAD_LOG_FOLDER , 0755 );
7276 }
7377 }
7478
7579 /**
76- * Action Handler
80+ * We register our autoloader
81+ *
82+ * @see http://php.net/manual/de/function.spl-autoload-register.php
7783 */
78- protected function action () {
79-
80- /**
81- * We register our autoloader
82- * @see http://php.net/manual/de/function.spl-autoload-register.php
83- */
84+ protected function action ()
85+ {
8486 if (version_compare (PHP_VERSION , '5.1.2 ' , '>= ' )) {
8587 if (version_compare (PHP_VERSION , '5.3.0 ' , '>= ' )) {
8688 spl_autoload_register (array ($ this , '__autoload ' ), true , true );
8789 } else {
8890 spl_autoload_register (array ($ this , '__autoload ' ));
8991 }
9092 } else {
91- // Add alert
9293 echo 'Ohhh NO Autoload exists, you use a PHP version under 5.1.2 ' ;
9394 }
9495
95- /**
96- * Control debug
97- */
9896 if (MBT_DEBUG_DISPLAY_AUTOLOAD == true ) {
9997 echo $ this ->logInfo ();
10098 }
@@ -104,10 +102,10 @@ protected function action() {
104102 * This function is the Loader, the heart from autoloader
105103 * Here we search with 3 different methods, the used classes, interfaces or even abstract classes
106104 *
107- * @param type $name
105+ * @param string $name
108106 */
109- protected function __autoload ($ name ) {
110-
107+ protected function __autoload ($ name )
108+ {
111109 // Start Site load time needs core performance
112110 $ timeA = start_time ();
113111
@@ -120,7 +118,7 @@ protected function __autoload($name) {
120118 if (file_exists ($ classFilePath ) && is_dir ($ classFilePath ) && !empty ($ this ->splitInsatnce (true ))) {
121119
122120 ### This is the fastest way ###
123- // $this->debugInfo['MB_AUTOLOAD_INSTANCE'][] = 'FAST';
121+ // $this->debugInfo['MB_AUTOLOAD_INSTANCE'][] = 'FAST';
124122
125123 /**
126124 * If so, then we create the class file.
@@ -146,7 +144,7 @@ protected function __autoload($name) {
146144 else {
147145
148146 ### This method is slightly slower than the first, so 0.03 - 0.05 seconds ###
149- // $this->debugInfo['MB_AUTOLOAD_INSTANCE'][] = 'MIDDLE';
147+ // $this->debugInfo['MB_AUTOLOAD_INSTANCE'][] = 'MIDDLE';
150148
151149 /**
152150 * This function namspace as folder path and force only this path for class file.
@@ -167,7 +165,7 @@ protected function __autoload($name) {
167165 } else {
168166
169167 ### This method is the slowest, but found class anything where ###
170- // $this->debugInfo['MB_AUTOLOAD_INSTANCE'][] = 'SLOW';
168+ // $this->debugInfo['MB_AUTOLOAD_INSTANCE'][] = 'SLOW';
171169
172170 /**
173171 * This method is the slowest, because it scans all your folders.
@@ -194,29 +192,28 @@ protected function __autoload($name) {
194192 $ this ->debugInfo [$ reuri ][$ name ] = $ endTimeA ;
195193
196194 file_put_contents (MBT_CORE_AUTOLOAD_LOG_LOGS , serialize ($ this ->debugInfo ), LOCK_EX );
197- // chmod(MBT_CORE_AUTOLOAD_LOG_LOGS, 0755);
195+ // chmod(MBT_CORE_AUTOLOAD_LOG_LOGS, 0755);
198196
199- /**
200- * Control debug
201- */
202197 if (MBT_DEBUG_DISPLAY_AUTOLOAD_SEARCH == true ) {
203- echo $ this ->getDebug ();
198+ echo $ this ->getDebug ();
204199 }
205200 }
206201
207202 /**
208203 * Loop all files and read it to found the instance class
209204 *
210- * @param type $filepath
205+ * @param string $filepath
211206 */
212- protected function readFile ($ filepath ) {
213-
207+ protected function readFile ($ filepath )
208+ {
214209 $ arr = array ();
215210 $ this ->file = $ this ->getFile ($ filepath );
216- if (false != $ this ->file ) {
211+ if (false != $ this ->file && is_array ( $ this -> file ) ) {
217212 foreach ($ this ->file as $ lineNum => $ line ) {
213+
218214 // Get actually namespace
219- // $this->getNamespace($line, $arr);
215+ // $this->getNamespace($line, $arr);
216+
220217 // Get actually class
221218 $ this ->getClass ($ filepath , $ line , $ arr , $ lineNum );
222219 if ($ lineNum > MBT_CORE_AUTOLOAD_READ_MAX_LINES || $ this ->found == true ) {
@@ -230,10 +227,10 @@ protected function readFile($filepath) {
230227 /**
231228 * Get class file
232229 *
233- * @return type
230+ * @return boolean|array
234231 */
235- public function getFile ($ filepath ) {
236-
232+ public function getFile ($ filepath )
233+ {
237234 $ return = false ;
238235 if (file_exists ($ filepath ) && is_file ($ filepath )) {
239236 $ return = file ($ filepath , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
@@ -244,12 +241,13 @@ public function getFile($filepath) {
244241 /**
245242 * Recursive all directorys in MBT_DOCUMENT_ROOT
246243 *
247- * @param type $dir
248- * @param type $results
249- * @return type
244+ * @param string $dir
245+ * @param array $results
246+ *
247+ * @return array
250248 */
251- public function loopDirectory ($ dir = NULL , array &$ results = array ()) {
252-
249+ public function loopDirectory ($ dir = NULL , array &$ results = array ())
250+ {
253251 if ($ dir == NULL ) {
254252 foreach ($ this ->dir as $ direct ) {
255253 $ dir = $ direct ;
@@ -272,10 +270,10 @@ public function loopDirectory($dir = NULL, array &$results = array()) {
272270 /**
273271 * Sort files and folders
274272 *
275- * @param type $path
273+ * @param string $path
276274 */
277- private function loopSort ($ path , array &$ results = array ()) {
278-
275+ private function loopSort ($ path , array &$ results = array ())
276+ {
279277 if (is_file ($ path )) {
280278 $ results ['files ' ][] = $ path ;
281279 }
@@ -285,9 +283,8 @@ private function loopSort($path, array &$results = array()) {
285283 $ this ->loopDirectory ($ path , $ results );
286284 }
287285 }
288-
289286}
290287
291288// Define web roots
292289define ('MBT_SERVER_ROOT ' , str_replace (MBT_DOCUMENT_ROOT , '' , str_replace (filter_input (INPUT_SERVER , 'DOCUMENT_ROOT ' ), '' , str_replace ("\\" , "/ " , MBT_DOCUMENT_ROOT ))));
293- define ('MBT_HTTP_ROOT ' , get_protocol () . get_host () . MBT_SERVER_ROOT );
290+ define ('MBT_HTTP_ROOT ' , get_protocol () . get_host () . MBT_SERVER_ROOT );
0 commit comments