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

Map::handler()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4286
cc 3
eloc 4
nc 3
nop 1
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