-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFwAutoLoader.php
More file actions
42 lines (34 loc) · 1.02 KB
/
Copy pathMyFwAutoLoader.php
File metadata and controls
42 lines (34 loc) · 1.02 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* 名前空間を用いたクラスオートローダです。
* 登録されたインクルードパスをルートとして
* 名前空間をそこからのディレクトリ構造として解釈します。
*
* @author kamekoopa
*/
class MyFwAutoLoader {
/**
* クラス探索の起点となるインクルードパスを追加します
*
* @access public
* @static
*
* @param string $inludePath 登録するインクルードパス
*/
public static function register($includePath){
//指定されたディレクトリの最後に / がついていなければつける
if(!preg_match('/^.*?\/$/', $includePath)){
$includePath = $includePath . "/";
}
$includePath = str_replace("\\", "/" , $includePath);
$function = function($className) use ($includePath){
$classFileName = $includePath . str_replace("\\", "/", $className) . ".php";
if( is_readable($classFileName) ){
require_once $classFileName;
}else{
return false;
}
};
spl_autoload_register($function);
}
}