1 | <?php |
||
28 | class FileReflection implements Reflection, ResultConvertible |
||
29 | { |
||
30 | |||
31 | private $filename; |
||
32 | |||
33 | /** |
||
34 | * @var \Zend\Code\Reflection\FileReflection |
||
35 | */ |
||
36 | private $reflection; |
||
37 | |||
38 | /** |
||
39 | * @var LineRange |
||
40 | */ |
||
41 | private $lineRange; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * @param string $filename |
||
46 | */ |
||
47 | public function __construct($filename) |
||
48 | { |
||
49 | $this->filename = $filename; |
||
50 | $this->reflection = new ZendFileReflection($this->filename, true); |
||
51 | |||
52 | $content = $this->reflection->getContents(); //$fileReflection->getEndLine() return null.... |
||
53 | $totalLineCount = substr_count(trim($content), PHP_EOL) + 1; |
||
54 | |||
55 | $this->lineRange = new LineRange(1, $totalLineCount); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function getIdentityName() |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function getName() |
||
73 | |||
74 | /** |
||
75 | * @return ReflectionCollection |
||
76 | */ |
||
77 | public function getClasses() |
||
78 | { |
||
79 | return $this->selectClassReflections(function (ZendClassReflection $reflection) { |
||
80 | return $reflection->isTrait(); |
||
81 | }); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @return ReflectionCollection |
||
86 | */ |
||
87 | public function getTraits() |
||
88 | { |
||
89 | return $this->selectClassReflections(function (ZendClassReflection $reflection) { |
||
90 | return $reflection->isTrait() === false; |
||
91 | }); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function getLineRange() |
||
101 | |||
102 | /** |
||
103 | * @param callable $filter |
||
104 | * @return ReflectionCollection |
||
105 | */ |
||
106 | private function selectClassReflections(Closure $filter) |
||
107 | { |
||
108 | $classes = $this->reflection->getClasses(); |
||
109 | |||
110 | $excludeInterface = function (ZendClassReflection $reflection) { |
||
111 | return $reflection->isInterface() === false; |
||
112 | }; |
||
113 | |||
114 | $createClassReflection = function (ZendClassReflection $reflection) { |
||
115 | return new ClassReflection($reflection->name); |
||
116 | }; |
||
117 | |||
118 | $reflections = new Sequence($classes); |
||
119 | $reflections = $reflections->filter($filter) |
||
120 | ->filter($excludeInterface) |
||
121 | ->map($createClassReflection); |
||
122 | |||
123 | return new ReflectionCollection($reflections->all()); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function convertToResult(LineResultSelectable $selector) |
||
133 | |||
134 | /** |
||
135 | * @return string |
||
136 | */ |
||
137 | public function __toString() |
||
141 | |||
142 | } |
||
143 |