1 | <?php |
||
31 | class NodeObject implements TreeishInterface |
||
32 | { |
||
33 | const TYPE_BLOB = 'blob'; |
||
34 | const TYPE_TREE = 'tree'; |
||
35 | const TYPE_LINK = 'commit'; |
||
36 | |||
37 | /** |
||
38 | * @var \GitElephant\Repository |
||
39 | */ |
||
40 | protected $repository; |
||
41 | |||
42 | /** |
||
43 | * permissions |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | private $permissions; |
||
48 | |||
49 | /** |
||
50 | * type |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | private $type; |
||
55 | |||
56 | /** |
||
57 | * sha |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | private $sha; |
||
62 | |||
63 | /** |
||
64 | * size |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | private $size; |
||
69 | |||
70 | /** |
||
71 | * name |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | private $name; |
||
76 | |||
77 | /** |
||
78 | * path |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | private $path; |
||
83 | |||
84 | /** |
||
85 | * create a Object from a single outputLine of the git ls-tree command |
||
86 | * |
||
87 | * @param \GitElephant\Repository $repository repository instance |
||
88 | * @param string $outputLine output from ls-tree command |
||
89 | * |
||
90 | * @see LsTreeCommand::tree |
||
91 | * @return NodeObject |
||
92 | */ |
||
93 | 8 | public static function createFromOutputLine(Repository $repository, string $outputLine) |
|
117 | |||
118 | /** |
||
119 | * Take a line and turn it in slices |
||
120 | * |
||
121 | * @param string $line a single line output from the git binary |
||
122 | * |
||
123 | * @return array |
||
124 | */ |
||
125 | 14 | public static function getLineSlices(string $line) |
|
153 | |||
154 | /** |
||
155 | * Class constructor |
||
156 | * |
||
157 | * @param \GitElephant\Repository $repository repository instance |
||
158 | * @param string $permissions node permissions |
||
159 | * @param string $type node type |
||
160 | * @param string $sha node sha |
||
161 | * @param string $size node size in bytes |
||
162 | * @param string $name node name |
||
163 | * @param string $path node path |
||
164 | */ |
||
165 | 14 | public function __construct( |
|
183 | |||
184 | /** |
||
185 | * toString magic method |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | 1 | public function __toString() |
|
193 | |||
194 | /** |
||
195 | * Mime Type getter |
||
196 | * |
||
197 | * @param string $basePath the base path of the repository |
||
198 | * |
||
199 | * @return string |
||
200 | */ |
||
201 | public function getMimeType(string $basePath) |
||
205 | |||
206 | /** |
||
207 | * get extension if it's a blob |
||
208 | * |
||
209 | * @return string|null |
||
210 | */ |
||
211 | public function getExtension() |
||
221 | |||
222 | /** |
||
223 | * whether the node is a tree |
||
224 | * |
||
225 | * @return bool |
||
226 | */ |
||
227 | 9 | public function isTree() |
|
231 | |||
232 | /** |
||
233 | * whether the node is a link |
||
234 | * |
||
235 | * @return bool |
||
236 | */ |
||
237 | public function isLink() |
||
241 | |||
242 | /** |
||
243 | * whether the node is a blob |
||
244 | * |
||
245 | * @return bool |
||
246 | */ |
||
247 | 1 | public function isBlob() |
|
251 | |||
252 | /** |
||
253 | * Full path getter |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | 12 | public function getFullPath() |
|
264 | |||
265 | /** |
||
266 | * permissions getter |
||
267 | * |
||
268 | * @return string |
||
269 | */ |
||
270 | public function getPermissions() |
||
274 | |||
275 | /** |
||
276 | * sha getter |
||
277 | * |
||
278 | * @return string |
||
279 | */ |
||
280 | 6 | public function getSha() |
|
284 | |||
285 | /** |
||
286 | * type getter |
||
287 | * |
||
288 | * @return string |
||
289 | */ |
||
290 | 13 | public function getType() |
|
294 | |||
295 | /** |
||
296 | * name getter |
||
297 | * |
||
298 | * @return string |
||
299 | */ |
||
300 | 5 | public function getName() |
|
304 | |||
305 | /** |
||
306 | * path getter |
||
307 | * |
||
308 | * @return string |
||
309 | */ |
||
310 | public function getPath() |
||
314 | |||
315 | /** |
||
316 | * size getter |
||
317 | * |
||
318 | * @return string |
||
319 | */ |
||
320 | public function getSize() |
||
324 | |||
325 | /** |
||
326 | * gets the last commit in this object |
||
327 | * |
||
328 | * @return Commit |
||
329 | */ |
||
330 | 3 | public function getLastCommit() |
|
336 | |||
337 | /** |
||
338 | * rev-parse command - often used to return a commit tag. |
||
339 | * |
||
340 | * @param array $options the options to apply to rev-parse |
||
341 | * |
||
342 | * @throws \RuntimeException |
||
343 | * @throws \InvalidArgumentException |
||
344 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
345 | * @return array |
||
346 | */ |
||
347 | 1 | public function revParse(array $options = []) |
|
355 | |||
356 | /* |
||
357 | * Repository setter |
||
358 | * |
||
359 | * @param \GitElephant\Repository $repository the repository variable |
||
360 | */ |
||
361 | 1 | public function setRepository(Repository $repository) |
|
365 | |||
366 | /** |
||
367 | * Repository getter |
||
368 | * |
||
369 | * @return \GitElephant\Repository |
||
370 | */ |
||
371 | 59 | public function getRepository() |
|
375 | } |
||
376 |