forked from TomFrost/Hydrogen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hydrogen.inc.php
56 lines (45 loc) · 1.31 KB
/
hydrogen.inc.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
<?php
/*
* Copyright (c) 2009 - 2010, Frosted Design
* All rights reserved.
*
*************************************************************************
* Hydrogen loader. require_once() this file from any php page that can
* be loaded directly. This file will autoload any other hydrogen classes
* as they're used, so no others requires are necessary.
*/
namespace hydrogen;
function load($namespace) {
$path_args = explode ( '\\', $namespace );
$path_count = count ( $path_args );
$ns_path = explode('\\', $namespace); //define BASE in your root path
for($i = 0; $i < $path_count; $i ++) {
$ns_path .= $path_args[$i];
if (! (($i + 1) == $path_count)) {
$ns_path .= '/';
}
}
$loc = $ns_path;
if ( is_dir( $loc ) && !is_dir( $loc . '.php' ) ) {
//Requre all files in directory ending with ".php"
$scripts = array();
//glob is faster than readdir etc, so why not!
foreach ( glob( $loc . '/*.php' ) as $f ) {
$scripts[] = $f;
}
if ( is_array( $scripts ) && count( $scripts ) > 0 ) {
foreach ( $scripts as $f ) {
loadPath( $loc . $f );
}
}
return;
}
loadPath($loc . '.php');
return;
}
function loadPath($absPath) {
return include_once($absPath);
}
spl_autoload_register(__NAMESPACE__ . '\load');
include(__DIR__ . DIRECTORY_SEPARATOR . 'hydrogen.autoconfig.php');
?>