1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
abstract class AbstractListCommand extends SilverstripeCommand |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
public function fire() |
7
|
|
|
{ |
8
|
|
|
$this->table($this->getTableHeaders(), $this->getTableData()); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
abstract function getClassName(); |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @return array |
15
|
|
|
*/ |
16
|
|
|
protected function getTableData() |
17
|
|
|
{ |
18
|
|
|
$classes = ClassInfo::subclassesFor($this->getClassName()); |
19
|
|
|
|
20
|
|
|
unset($classes[$this->getClassName()]); |
21
|
|
|
|
22
|
|
|
foreach ($classes as $key => $class) { |
|
|
|
|
23
|
|
|
$classes[$class] = [ |
24
|
|
|
$class, |
25
|
|
|
implode("\n", (array) $this->getExtensions($class)), |
26
|
|
|
implode(" => ", (array) $this->getParentClasses($class)), |
27
|
|
|
$this->getModule($class), |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
ksort($classes); |
32
|
|
|
|
33
|
|
|
return $classes; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
protected function getTableHeaders() |
41
|
|
|
{ |
42
|
|
|
return ['ClassName', 'Extensions', 'Extends', 'Module']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param $className |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
protected function getExtensions($className) |
50
|
|
|
{ |
51
|
|
|
return (array)Config::inst()->get($className, 'extensions', Config::UNINHERITED); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $className |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
protected function getModule($className) |
59
|
|
|
{ |
60
|
|
|
$reflection = new \ReflectionClass($className); |
61
|
|
|
$file = $reflection->getFileName(); |
62
|
|
|
|
63
|
|
|
$path = str_replace([BASE_PATH.'/'], '', $file); |
64
|
|
|
$parts = explode(DIRECTORY_SEPARATOR, $path); |
65
|
|
|
|
66
|
|
|
return (string)array_shift($parts); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $className |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
protected function getParentClasses($className) |
74
|
|
|
{ |
75
|
|
|
return ClassInfo::ancestry($className); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.