1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace BrowscapPHP\Helper; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* class to load the browscap.ini |
8
|
|
|
*/ |
9
|
|
|
final class IniLoader implements IniLoaderInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The location from which download the ini file. The placeholder for the file should be represented by a %s. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private const REMOTE_INI_URI = 'http://browscap.org/stream?q=%q'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The location to use to check out if a new version of the browscap.ini file is available. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private const REMOTE_TIME_URI = 'http://browscap.org/version'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private const REMOTE_VERSION_URI = 'http://browscap.org/version-number'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $remoteFilename = IniLoaderInterface::PHP_INI; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* sets the name of the local ini file |
37
|
|
|
* |
38
|
|
|
* @param string $name the file name |
39
|
|
|
* |
40
|
|
|
* @throws \BrowscapPHP\Helper\Exception |
41
|
|
|
*/ |
42
|
2 |
|
public function setRemoteFilename(string $name) : void |
43
|
|
|
{ |
44
|
2 |
|
if (empty($name)) { |
45
|
1 |
|
throw new Exception( |
46
|
1 |
|
'the filename can not be empty', |
47
|
1 |
|
Exception::INI_FILE_MISSING |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
$this->remoteFilename = $name; |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* returns the of the remote location for updating the ini file |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
1 |
|
public function getRemoteIniUrl() : string |
60
|
|
|
{ |
61
|
1 |
|
return str_replace('%q', $this->remoteFilename, self::REMOTE_INI_URI); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* returns the of the remote location for checking the version of the ini file |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
1 |
|
public function getRemoteTimeUrl() : string |
70
|
|
|
{ |
71
|
1 |
|
return self::REMOTE_TIME_URI; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* returns the of the remote location for checking the version of the ini file |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getRemoteVersionUrl() : string |
80
|
|
|
{ |
81
|
|
|
return self::REMOTE_VERSION_URI; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|