forked from wikimedia/mediawiki-extensions-SemanticGenealogy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools.php
41 lines (36 loc) · 877 Bytes
/
Tools.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
<?php
class Tools {
/**
* Find the subclasses of that superclass in one directory
*
* @param string $dir
* @param string $superClass
*
* @return array an array of $classes subclass of the superClass
*/
public static function getSubclassesOf( $dir, $superClass ) {
$classes = [];
foreach ( new DirectoryIterator( $dir ) as $file ) {
if ( $file->isDot() ) {
continue;
}
if ( !$file->isFile() ) {
continue;
}
if ( !preg_match( "#.php$#", $file->getFilename() ) ) {
continue;
}
require_once $file->getPathname();
$className = $file->getBasename( '.php' );
try {
$classRef = new ReflectionClass( $className );
} catch ( ReflectionException $e ) {
continue;
}
if ( !$classRef->isAbstract() && $classRef->isSubclassOf( $superClass ) ) {
$classes[] = new $className;
}
}
return $classes;
}
}