| 1 |
<?php |
| 2 |
|
| 3 |
// Check the 'modules' directory... |
| 4 |
$modules_dir = dirname(__FILE__).'/modules'; |
| 5 |
|
| 6 |
$classes = array( |
| 7 |
'main' => array(), |
| 8 |
'sub' => array(), |
| 9 |
); |
| 10 |
|
| 11 |
$iterator = new DirectoryIterator($modules_dir); |
| 12 |
foreach($iterator as $dir){ |
| 13 |
$path = "$modules_dir/$dir"; |
| 14 |
$info = pathinfo($path); |
| 15 |
|
| 16 |
if ($dir != '.' && $dir != '..'){ |
| 17 |
// ... and include any PHP files, ... |
| 18 |
if (is_file($path) && $info['extension'] == 'php') { |
| 19 |
// Also include PHP files in the modules directory. |
| 20 |
$classes['main'][] = $path; |
| 21 |
|
| 22 |
// ... then check module subdirectories... |
| 23 |
} else if( is_dir($path)) { |
| 24 |
|
| 25 |
$subiterator = new DirectoryIterator($path); |
| 26 |
foreach($subiterator as $file) { |
| 27 |
$filepath = "$path/$file"; |
| 28 |
$pathinfo = pathinfo($filepath); |
| 29 |
|
| 30 |
// ... for more php files... |
| 31 |
if ($file != '.' && $file != '..' && is_file($filepath) && $pathinfo['extension'] == 'php') { |
| 32 |
// ... and load them. |
| 33 |
$classes['sub'][] = $filepath; |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
// Ok, now actually load them, and store the classpaths. |
| 41 |
$declared_classes = get_declared_classes(); |
| 42 |
foreach($classes as $type) { |
| 43 |
foreach($type as $path) { |
| 44 |
// Load the file |
| 45 |
include($path); |
| 46 |
|
| 47 |
// Check for new declared classes... |
| 48 |
$new_declared_classes = get_declared_classes(); |
| 49 |
foreach($new_declared_classes as $new_class) { |
| 50 |
if (!in_array($new_class, $declared_classes)) { |
| 51 |
// ... and store them. |
| 52 |
Entry::add_classpath($new_class, $path); |
| 53 |
} |
| 54 |
} |
| 55 |
$declared_classes = $new_declared_classes; |
| 56 |
} |
| 57 |
} |