|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Util\Configuration; |
|
4
|
|
|
|
|
5
|
|
|
abstract class AbstractConfigurationReader |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
protected $classes = []; |
|
9
|
|
|
|
|
10
|
|
|
protected function introspectClass(ConfigurableObjectInterface $object) |
|
11
|
|
|
{ |
|
12
|
|
|
$originalReflectionClass = $reflectionClass = new \ReflectionClass($object); |
|
13
|
|
|
$this->addClass($reflectionClass->getName()); |
|
|
|
|
|
|
14
|
|
|
while (($class = $reflectionClass->getParentClass()) !== false) { |
|
15
|
|
|
$this->addClass($class->getName()); |
|
16
|
|
|
foreach ($class->getInterfaceNames() as $interface) { |
|
17
|
|
|
$this->addClass($interface); |
|
18
|
|
|
$reflectionInterface = new \ReflectionClass($interface); |
|
19
|
|
|
$interfaces = $reflectionInterface->getInterfaceNames(); |
|
20
|
|
|
foreach ($interfaces as $interface) { |
|
21
|
|
|
$this->addClass($interface); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
$reflectionClass = $class; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
foreach ($originalReflectionClass->getInterfaceNames() as $name){ |
|
28
|
|
|
$this->addClass($name); |
|
29
|
|
|
$interfaces[] = $name; |
|
|
|
|
|
|
30
|
|
|
$reflectionInterface = new \ReflectionClass($name); |
|
31
|
|
|
$theseInterfaces = $reflectionInterface->getInterfaceNames(); |
|
32
|
|
|
$theseInterfaces = array_reverse($theseInterfaces); |
|
33
|
|
|
foreach ($theseInterfaces as $interface) { |
|
34
|
|
|
$this->addClass($interface); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->classes = array_reverse($this->classes); |
|
39
|
|
|
return $this->classes; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function addClass($name) |
|
43
|
|
|
{ |
|
44
|
|
|
if (!in_array($name, $this->classes)) { |
|
45
|
|
|
$this->classes[] = $name; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function recursivelyIntrospectInterface($interfaceName) |
|
50
|
|
|
{ |
|
51
|
|
|
$allInterfaces = []; |
|
52
|
|
|
$reflectionInterface = new \ReflectionClass($interfaceName); |
|
53
|
|
|
$interfaces = $reflectionInterface->getInterfaces(); |
|
54
|
|
|
foreach ($interfaces as $interface) { |
|
55
|
|
|
$interfaceList = $this->recursivelyIntrospectInterface($interface); |
|
56
|
|
|
$allInterfaces = array_merge($allInterfaces, $interfaceList); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
while (($parentInterface = $reflectionInterface->getParentClass()) != false) { |
|
60
|
|
|
$allInterfaces[] = $parentInterface->getName(); |
|
61
|
|
|
$interfaceList = $this->recursivelyIntrospectInterface($parentInterface->getName()); |
|
62
|
|
|
$allInterfaces = array_merge($allInterfaces, $interfaceList); |
|
63
|
|
|
$reflectionInterface = $parentInterface; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $allInterfaces; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
abstract public function configure(ConfigurableObjectInterface $object); |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|