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