Completed
Pull Request — master (#6)
by Anton
03:55
created

Container::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4286
cc 3
eloc 5
nc 4
nop 1
1
<?php
2
3
namespace Modules\Filemanager\Utils {
4
5
	use Explorer;
6
7
	class Container {
8
9
		private $scheme = [], $path = '', $path_full = DIR_UPLOADS;
10
11
		# Constructor
12
13
		public function __construct(string $path = '') {
14
15
			$scheme = array_diff(preg_split('/[\/\\\\]+/', $path, -1, PREG_SPLIT_NO_EMPTY), ['.', '..']);
16
17
			$path = implode('/', $scheme); $path_full = (DIR_UPLOADS . (('' !== $path) ? ($path . '/') : ''));
18
19
			if (!Explorer::isDir($path_full)) return;
20
21
			$this->scheme = $scheme; $this->path = $path; $this->path_full = $path_full;
22
		}
23
24
		# Get breadcrumbs
25
26
		public function breadcrumbs() {
27
28
			$scheme = []; $breadcrumbs = [];
29
30
			if ([] !== $this->scheme) foreach ($this->scheme as $name) {
31
32
				$scheme[] = $name; $breadcrumbs[] = ['path' => implode('/', $scheme), 'name' => $name];
33
			}
34
35
			# ------------------------
36
37
			return $breadcrumbs;
38
		}
39
40
		# Return path
41
42
		public function path() {
43
44
			return $this->path;
45
		}
46
47
		# Return full path
48
49
		public function pathFull() {
50
51
			return $this->path_full;
52
		}
53
	}
54
}
55