-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoLoader.php
More file actions
31 lines (28 loc) · 940 Bytes
/
autoLoader.php
File metadata and controls
31 lines (28 loc) · 940 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
30
31
<?php
class autoLoader
{
private $system_root;
public function __construct($root)
{
// ルートディレクトリの設定
$this->system_root = $root;
}
public function register()
{
spl_autoload_register(array($this, 'myLoader'));
}
public function myLoader($class)
{
// 最初のスラッシュを含めるかどうかは適宜調整(ここでは取り除く)
$classNamespace = ltrim($class, '\\');
// バックスラッシュを右に倒してルートと拡張子を結合
$classFileName = $this->system_root . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classNamespace) . '.php';
// クラスファイルが存在して読み込めるか確認
if (is_readable($classFileName)) {
require_once $classFileName;
return true;
} else {
return false;
}
}
}