-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrapper.php
60 lines (47 loc) · 1.5 KB
/
Bootstrapper.php
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
60
<?php
namespace FormHelper;
class Bootstrapper {
protected $includePath;
public function __construct($includePath) {
$this->includePath = $includePath;
}
public function setIncludePath($includePath) {
$this->includePath = $this->convertPath($includePath);
}
/**
* Converts a path specific to the environment the framework is running in
* @param String path to be converted
*/
public static function convertPath($path) {
//convert path to current OS
$properOsPath = str_replace('\\', DIRECTORY_SEPARATOR, $path);
return $properOsPath;
}
/**
* Main autoloading method. Autoloading requests get made to this method.
* @param $className String name of class
*/
public function loadRules($className) {
//build the file location path
$class = $this->convertPath($this->includePath . DIRECTORY_SEPARATOR . $className) . '.php';
if (file_exists($class)) {
//require the file
require $class;
return true;
}
return false;
}
/**
* Registers this instance on the autoload stack
*/
public function register() {
spl_autoload_register(array($this, 'loadRules'));
}
/**
* Unregisters this instance from the autoload stack
*/
public function unRegister() {
spl_autoload_unregister(array($this, 'loadRules'));
}
}
?>