Completed
Push — prefer-dir ( c7f89d )
by Robin
12:57
created

TimeZoneProvider::get()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.9777
c 0
b 0
f 0
cc 6
nc 4
nop 1
1
<?php
2
/**
3
 * Copyright (c) 2015 Robin Appelman <[email protected]>
4
 * This file is licensed under the Licensed under the MIT license:
5
 * http://opensource.org/licenses/MIT
6
 */
7
8
namespace Icewind\SMB;
9
10
class TimeZoneProvider implements ITimeZoneProvider {
11
	/**
12
	 * @var string[]
13
	 */
14
	private $timeZones = [];
15
16
	/**
17
	 * @var ISystem
18
	 */
19
	private $system;
20
21
	/**
22
	 * @param ISystem $system
23
	 */
24
	public function __construct(ISystem $system) {
25
		$this->system = $system;
26
	}
27
28
	public function get($host) {
29
		if (!isset($this->timeZones[$host])) {
30
			$net = $this->system->getNetPath();
31
			// for local domain names we can assume same timezone
32
			if ($net && $host && strpos($host, '.') !== false) {
33
				$command = sprintf('%s time zone -S %s',
34
					$net,
35
					escapeshellarg($host)
36
				);
37
				$timeZone = exec($command);
38
				if (!$timeZone) {
39
					$timeZone = date_default_timezone_get();
40
				}
41
				$this->timeZones[$host] = $timeZone;
42
			} else { // fallback to server timezone
43
				$this->timeZones[$host] = date_default_timezone_get();
44
			}
45
		}
46
		return $this->timeZones[$host];
47
	}
48
}
49