Completed
Push — master ( 416cb1...222de5 )
by Anton
03:44
created

Map::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 14
rs 9.2
cc 4
eloc 6
nc 4
nop 0
1
<?php
2
3
namespace Utils {
4
5
	use Explorer, Url;
6
7
	class Map {
8
9
		private $map = [];
10
11
		# Constructor
12
13
		public function __construct() {
14
15
			$file_name = (DIR_SYSTEM_DATA . 'Map.xml');
16
17
			if (false !== ($map_xml = Explorer::xml($file_name))) {
18
19
				foreach ($map_xml->item as $item) {
20
21
					$item = new Map\Item($item->path, $item->handler);
22
23
					if ($item->parsed()) $this->map[] = $item;
24
				}
25
			}
26
		}
27
28
		# Get handler by url
29
30
		public function handler(Url $url) {
31
32
			foreach ($this->map as $item) {
33
34
				if (false !== ($handler = $item->handler($url->path()))) return $handler;
35
			}
36
37
			# ------------------------
38
39
			return false;
40
		}
41
	}
42
}
43