-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassloader.php
More file actions
50 lines (40 loc) · 1.21 KB
/
Copy pathClassloader.php
File metadata and controls
50 lines (40 loc) · 1.21 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
<?php
/**
* @author Timo Stepputtis
*
*/
/**
* Excludes specified directories
*/
class MyRecursiveFilterIterator extends RecursiveFilterIterator {
public static $FILTERS = array ('pdf' );
public function accept( ) {
return ! in_array ( $this->current ( )->getFilename ( ), self::$FILTERS, true );
}
}
/**
* Loads all classes recursively
*/
class Classloader {
const BASE_DIR = __DIR__;
const searchDirs = array ('classes','controllers','models' );
/**
* Search for $className recursively
*
* @param string $className
*/
public static function load( $className ) {
foreach ( Classloader::searchDirs as &$cDir ) {
$dir = new RecursiveDirectoryIterator ( Classloader::BASE_DIR . DIRECTORY_SEPARATOR . $cDir, RecursiveDirectoryIterator::SKIP_DOTS );
$fItr = new MyRecursiveFilterIterator ( $dir );
$itr = new RecursiveIteratorIterator ( $fItr );
$regex = new RegexIterator ( $itr, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH );
foreach ( $regex as $filename ) {
if ( strstr ( $filename [0], $className ) ) {
require_once $filename [0];
}
}
}
}
}
?>