forked from awmpietro/php-front-controller
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclass_autoloader.php
More file actions
executable file
·29 lines (27 loc) · 848 Bytes
/
Copy pathclass_autoloader.php
File metadata and controls
executable file
·29 lines (27 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
class Autoloader {
/**
* Include files and instantiate classes that are under default rules of the system like Controller, Models, Libs.
* These classes follow certain rules like to be namespaced, and this namepsace matches the directory name. The spl_autoload_register class auto instantiate the class.
* @params $className = string for the name of the class: "Namespace\ClassName"
*/
public static $file;
static public function loader($className) {
$path = explode("\\", $className);
$file = '';
$keys = array_keys($path);
$lastKey = array_pop($keys);
foreach($path as $key => $value){
if($key === $lastKey){
$file .= $value . ".php";
}else{
$file .= strtolower($value) . '/';
}
}
if (!file_exists($file)){
return FALSE;
}
include $file;
}
}
spl_autoload_register('Autoloader::loader');