-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
59 lines (45 loc) · 1.24 KB
/
bootstrap.php
File metadata and controls
59 lines (45 loc) · 1.24 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
class Autoloader {
public function includeFile($nameSpace) {
$path = str_replace('_', '/', $nameSpace) . '.php';
$fileExists = self::fileExists($nameSpace);
$skip = array(
'PHPUnit.*'
);
foreach ($skip as $pattern) {
if (preg_match('~'.$pattern.'~i', $nameSpace)) {
return false;
}
}
if (false === $fileExists) {
self::throwException($nameSpace);
}
include_once $path;
}
private static function throwException($nameSpace) {
$msg = 'The file to class-name: "' . $nameSpace . '" does not exists in our supported environment include paths.';
throw new Autoloader_Exception($msg);
}
public static function fileExists($nameSpace) {
$path = str_replace('_', '/', $nameSpace) . '.php';
// check of valid file
$fileExists = false;
$includePaths = explode(':', get_include_path());
foreach ($includePaths as $currentPath) {
$testFile = $currentPath . '/' . $path;
if (is_readable($testFile)) {
$fileExists = true;
break;
}
}
return $fileExists;
}
}
class Autoloader_Exception extends Exception {
}
$strIncludePath = get_include_path() . ':' . dirname(__FILE__) . DIRECTORY_SEPARATOR;
set_include_path($strIncludePath);
spl_autoload_register(array(
new Autoloader(),
'includeFile'
));