1 | <?php |
||
21 | final class File |
||
|
|||
22 | { |
||
23 | /** |
||
24 | * @var DocBlock|null |
||
25 | */ |
||
26 | private $docBlock = null; |
||
27 | |||
28 | /** @var string $hash */ |
||
29 | private $hash; |
||
30 | |||
31 | /** @var string $name */ |
||
32 | private $name = null; |
||
33 | |||
34 | /** @var string $path */ |
||
35 | private $path = null; |
||
36 | |||
37 | /** @var string|null $source */ |
||
38 | private $source = null; |
||
39 | |||
40 | /** @var Fqsen[] $namespaces */ |
||
41 | private $namespaces = array(); |
||
42 | |||
43 | /** @var string[] $includes */ |
||
44 | private $includes = array(); |
||
45 | |||
46 | /** @var Function_[] $functions */ |
||
47 | private $functions = array(); |
||
48 | |||
49 | /** @var Constant[] $constants */ |
||
50 | private $constants = array(); |
||
51 | |||
52 | /** @var Class_[] $classes */ |
||
53 | private $classes = array(); |
||
54 | |||
55 | /** @var Interface_[] $interfaces */ |
||
56 | private $interfaces = array(); |
||
57 | |||
58 | /** @var Trait_[] $traits */ |
||
59 | private $traits = array(); |
||
60 | |||
61 | /** |
||
62 | * Initializes a new file descriptor with the given hash of its contents. |
||
63 | * |
||
64 | * @param string $hash An MD5 hash of the contents if this file. |
||
65 | * @param string $path |
||
66 | * @param string|null $source |
||
67 | * @param DocBlock $docBlock |
||
68 | */ |
||
69 | 7 | public function __construct($hash, $path, $source = null, DocBlock $docBlock = null) |
|
70 | { |
||
71 | 7 | $this->hash = $hash; |
|
72 | 7 | $this->path = $path; |
|
73 | 7 | $this->name = basename($path); |
|
74 | 7 | $this->source = $source; |
|
75 | 7 | $this->docBlock = $docBlock; |
|
76 | 7 | } |
|
77 | |||
78 | /** |
||
79 | * Returns the hash of the contents for this file. |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | 1 | public function getHash() |
|
87 | |||
88 | /** |
||
89 | * Retrieves the contents of this file. |
||
90 | * |
||
91 | * @return string|null |
||
92 | */ |
||
93 | 1 | public function getSource() |
|
97 | |||
98 | /** |
||
99 | * Returns the namespace fqsens that have been defined in this file. |
||
100 | * |
||
101 | * @return Fqsen[] |
||
102 | */ |
||
103 | 1 | public function getNamespaces() |
|
104 | { |
||
105 | 1 | return $this->namespaces; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Add namespace to file |
||
110 | * |
||
111 | * @param Fqsen $fqsen |
||
112 | */ |
||
113 | 1 | public function addNamespace(Fqsen $fqsen) |
|
114 | { |
||
115 | 1 | $this->namespaces[(string)$fqsen] = $fqsen; |
|
116 | 1 | } |
|
117 | |||
118 | /** |
||
119 | * Returns a list of all includes that have been declared in this file. |
||
120 | * |
||
121 | * @return string[] |
||
122 | */ |
||
123 | 1 | public function getIncludes() |
|
127 | |||
128 | /** |
||
129 | * @param string $include |
||
130 | * @return void |
||
131 | */ |
||
132 | 1 | public function addInclude($include) |
|
136 | |||
137 | /** |
||
138 | * Returns a list of constant descriptors contained in this file. |
||
139 | * |
||
140 | * @return Constant[] |
||
141 | */ |
||
142 | 1 | public function getConstants() |
|
146 | |||
147 | /** |
||
148 | * Add constant to this file. |
||
149 | * |
||
150 | * @param Constant $constant |
||
151 | * @return void |
||
152 | */ |
||
153 | 1 | public function addConstant(Constant $constant) |
|
157 | |||
158 | /** |
||
159 | * Returns a list of function descriptors contained in this file. |
||
160 | * |
||
161 | * @return Function_[] |
||
162 | */ |
||
163 | 1 | public function getFunctions() |
|
167 | |||
168 | /** |
||
169 | * Add function to this file. |
||
170 | * |
||
171 | * @param Function_ $function |
||
172 | * @return void |
||
173 | */ |
||
174 | 1 | public function addFunction(Function_ $function) |
|
178 | |||
179 | /** |
||
180 | * Returns a list of class descriptors contained in this file. |
||
181 | * |
||
182 | * @return Class_[] |
||
183 | */ |
||
184 | 1 | public function getClasses() |
|
188 | |||
189 | /** |
||
190 | * Add Class to this file. |
||
191 | * |
||
192 | * @param Class_ $class |
||
193 | * @return void |
||
194 | */ |
||
195 | 1 | public function addClass(Class_ $class) |
|
199 | |||
200 | /** |
||
201 | * Returns a list of interface descriptors contained in this file. |
||
202 | * |
||
203 | * @return Interface_[] |
||
204 | */ |
||
205 | 1 | public function getInterfaces() |
|
209 | |||
210 | /** |
||
211 | * Add interface to this file. |
||
212 | * |
||
213 | * @param Interface_ $interface |
||
214 | * @return void |
||
215 | */ |
||
216 | 1 | public function addInterface(Interface_ $interface) |
|
220 | |||
221 | /** |
||
222 | * Returns a list of trait descriptors contained in this file. |
||
223 | * |
||
224 | * @return Trait_[] |
||
225 | */ |
||
226 | 1 | public function getTraits() |
|
230 | |||
231 | /** |
||
232 | * Add trait to this file. |
||
233 | * |
||
234 | * @param Trait_ $trait |
||
235 | * @return void |
||
236 | */ |
||
237 | 1 | public function addTrait(Trait_ $trait) |
|
241 | |||
242 | /** |
||
243 | * Returns the file path relative to the project's root. |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | 1 | public function getPath() |
|
251 | /** |
||
252 | * Returns the DocBlock of the element if available |
||
253 | * |
||
254 | * @return null|DocBlock |
||
255 | */ |
||
256 | 1 | public function getDocBlock() |
|
260 | |||
261 | /** |
||
262 | * Returns the full name of this file |
||
263 | * |
||
264 | * @return string |
||
265 | */ |
||
266 | public function getName() |
||
270 | } |
||
271 |