-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryPathExtension.php
56 lines (36 loc) · 1.2 KB
/
QueryPathExtension.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
interface QueryPathExtension {
public function __construct(QueryPath $qp);
}
class QueryPathExtensionRegistry {
public static $useRegistry = TRUE;
protected static $extensionRegistry = array();
protected static $extensionMethodRegistry = array();
public static function extend($classname) {
self::$extensionRegistry[] = $classname;
$class = new ReflectionClass($classname);
$methods = $class->getMethods();
foreach ($methods as $method) {
self::$extensionMethodRegistry[$method->getName()] = $classname;
}
}
public static function hasMethod($name) {
return isset(self::$extensionMethodRegistry[$name]);
}
public static function hasExtension($name) {
return in_array($name, self::$extensionRegistry);
}
public static function getMethodClass($name) {
return self::$extensionMethodRegistry[$name];
}
public static function getExtensions(QueryPath $qp) {
$extInstances = array();
foreach (self::$extensionRegistry as $ext) {
$extInstances[$ext] = new $ext($qp);
}
return $extInstances;
}
public static function autoloadExtensions($boolean = TRUE) {
self::$useRegistry = $boolean;
}
}