forked from k1p0d/zeus_reports_len
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repository.class.php
60 lines (46 loc) · 1.73 KB
/
Repository.class.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
# coded by Rotem Kerner
# http://www.kerneronsec.com/
class Repository_Exception extends Exception{};
abstract class Repository{
static $namespace = '';
public static function getAll(){
if(empty(static::$namespace)){
throw new Repository_Exception("static \$namespace variable must be set");
}
$classes = Namespace_Reflector::getClasses(static::$namespace);
$classInstances = array();
foreach($classes as $class){
array_push($classInstances,new $class());
}
return $classInstances;
}
public static function getByName($name){
if(empty(static::$namespace)){
throw new Repository_Exception("static \$namespace variable must be set");
}
if(Namespace_Reflector::classExist(static::$namespace, $name)){
$className = '\\'. static::$namespace .'\\'. $name;
return new $className();
}
return false;
# maybe one day... if we wont recode all thia in python.
}
}
class Namespace_Reflector{ # kinda hacky but comfortable
static function getClasses($namespace){
$classnames = array();
foreach(get_declared_classes() as $name){
if(substr($name,0,strlen($namespace)) == $namespace){
array_push($classnames, $name);
}
}
if(count($classnames)){
return $classnames;
}
}
static function classExist($namespace, $class){
return class_exists('\\' . $namespace . '\\' . $class);
}
}
?>