Skip to content

Commit cf49c0c

Browse files
committed
General update
- Update comments - Add .gitignore - Add more information - Small code fixes
1 parent d4d69ec commit cf49c0c

File tree

10 files changed

+202
-175
lines changed

10 files changed

+202
-175
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.log
2+
vendor

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
![Melabuai Logo](https://raw.githubusercontent.com/prod3v3loper/syntaxo/master/img/icon-MB.png "Melabuai Brand")
44

55
![Language](https://img.shields.io/github/languages/top/prod3v3loper/php-auto-autoloader.svg?style=flat "Language")
6-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/90539baa57ba4ea1beb8451090f42547)](https://www.codacy.com/app/prod3v3loper/php-auto-autoloader?utm_source=github.com&utm_medium=referral&utm_content=prod3v3loper/php-auto-autoloader&utm_campaign=Badge_Grade)
76
[![Build Status](https://travis-ci.org/prod3v3loper/syntaxo.svg?branch=master "Build Status")](https://travis-ci.org/prod3v3loper/syntaxo "Build Status")
87
![Repo Size](https://img.shields.io/github/repo-size/prod3v3loper/php-auto-autoloader.svg?style=flat "Repo size")
98
![Code SIze](https://img.shields.io/github/languages/code-size/prod3v3loper/php-auto-autoloader.svg?style=flat "Code size")
@@ -57,15 +56,18 @@ This is the vendor autoloader invites our autoloader and now we do not need to s
5756
`index.php`
5857
```php
5958
<?php
59+
// Define the document root project folder
6060
define('MBT_DOCUMENT_ROOT', __DIR__);
61+
62+
// Load the autoloader
6163
require_once __DIR__ . '/vendor/autoload.php';
6264
new \Aautoloder\Loader(array(MBT_DOCUMENT_ROOT));
6365
?>
6466
<!DOCTYPE html>
6567
<html>
6668
<head>
6769
<meta charset="UTF-8">
68-
<title>MB tnado Ai - Autoload</title>
70+
<title>Prod3v3loper - Autoload</title>
6971
</head>
7072
<body>
7173
<?php
@@ -100,15 +102,18 @@ So we use it without a vendor and can start a direct call.
100102
`index.php`
101103
```php
102104
<?php
105+
// Define the document root project folder
103106
define('MBT_DOCUMENT_ROOT', __DIR__);
107+
108+
// Load the autoloader
104109
require_once './autoload/src/Loader.php';
105110
new \Aautoloder\Loader(array(MBT_DOCUMENT_ROOT));
106111
?>
107112
<!DOCTYPE html>
108113
<html>
109114
<head>
110115
<meta charset="UTF-8">
111-
<title>MB tnado Ai - Autoload</title>
116+
<title>Prod3v3loper - Autoload</title>
112117
</head>
113118
<body>
114119
<?php
@@ -263,6 +268,6 @@ possible.
263268

264269
# License
265270

266-
[MIT](https://github.com/prod3v3loper/php-auto-autoloader/blob/master/LICENSE) - [prod3v3loper](https://www.tnado.com/author/prod3v3loper/)
271+
[MIT](https://github.com/prod3v3loper/php-auto-autoloader/blob/master/LICENSE) - [prod3v3loper](https://www.prod3v3loper.com/)
267272

268273
</div>

autoload/log/_2019_01_31.log

Lines changed: 0 additions & 1 deletion
This file was deleted.

autoload/src/Loader.php

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace Aautoloder;
66

@@ -13,88 +13,86 @@
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
292289
define('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

Comments
 (0)