1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 1998-2015 Browser Capabilities Project |
4
|
|
|
* |
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a |
6
|
|
|
* copy of this software and associated documentation files (the "Software"), |
7
|
|
|
* to deal in the Software without restriction, including without limitation |
8
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
9
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the |
10
|
|
|
* Software is furnished to do so, subject to the following conditions: |
11
|
|
|
* |
12
|
|
|
* The above copyright notice and this permission notice shall be included |
13
|
|
|
* in all copies or substantial portions of the Software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
16
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21
|
|
|
* THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
* @category Browscap-PHP |
24
|
|
|
* @package Helper |
25
|
|
|
* @copyright 1998-2015 Browser Capabilities Project |
26
|
|
|
* @license http://www.opensource.org/licenses/MIT MIT License |
27
|
|
|
* @link https://github.com/browscap/browscap-php/ |
28
|
|
|
* @since added with version 3.0 |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
namespace BrowscapPHP\Helper; |
32
|
|
|
|
33
|
|
|
use FileLoader\Exception as LoaderException; |
34
|
|
|
use FileLoader\Loader; |
35
|
|
|
use GuzzleHttp\Client; |
36
|
|
|
use Psr\Log\LoggerInterface; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* class to load the browscap.ini |
40
|
|
|
* |
41
|
|
|
* @category Browscap-PHP |
42
|
|
|
* @package Helper |
43
|
|
|
* @author Thomas Müller <[email protected]> |
44
|
|
|
* @copyright Copyright (c) 1998-2015 Browser Capabilities Project |
45
|
|
|
* @version 3.0 |
46
|
|
|
* @license http://www.opensource.org/licenses/MIT MIT License |
47
|
|
|
* @link https://github.com/browscap/browscap-php/ |
48
|
|
|
*/ |
49
|
|
|
class IniLoader |
50
|
|
|
{ |
51
|
|
|
const PHP_INI_LITE = 'Lite_PHP_BrowscapINI'; |
52
|
|
|
const PHP_INI_FULL = 'Full_PHP_BrowscapINI'; |
53
|
|
|
const PHP_INI = 'PHP_BrowscapINI'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Options for update capabilities |
57
|
|
|
* |
58
|
|
|
* $remoteTimeUrl: The location to use to check out if a new version of the |
59
|
|
|
* browscap.ini file is available. |
60
|
|
|
* $remoteIniUrl: The location from which download the ini file. |
61
|
|
|
* The placeholder for the file should be represented by a %s. |
62
|
|
|
* $timeout: The timeout for the requests. |
63
|
|
|
*/ |
64
|
|
|
private $remoteIniUrl = 'http://browscap.org/stream?q=%q'; |
65
|
|
|
private $remoteTimeUrl = 'http://browscap.org/version'; |
66
|
|
|
private $remoteVersionUrl = 'http://browscap.org/version-number'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
private $remoteFilename = self::PHP_INI; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* sets the name of the local ini file |
75
|
|
|
* |
76
|
|
|
* @param string $name the file name |
77
|
|
|
* |
78
|
|
|
* @throws \BrowscapPHP\Helper\Exception |
79
|
|
|
* @return \BrowscapPHP\Helper\IniLoader |
80
|
|
|
*/ |
81
|
|
|
public function setRemoteFilename($name = null) |
82
|
|
|
{ |
83
|
|
|
if (empty($name)) { |
84
|
|
|
throw new Exception( |
85
|
|
|
'the filename can not be empty', |
86
|
|
|
Exception::INI_FILE_MISSING |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->remoteFilename = $name; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* returns the of the remote location for updating the ini file |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getRemoteIniUrl() |
101
|
|
|
{ |
102
|
|
|
return str_replace('%q', $this->remoteFilename, $this->remoteIniUrl); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* returns the of the remote location for checking the version of the ini file |
107
|
|
|
* |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
6 |
|
public function getRemoteTimeUrl() |
111
|
|
|
{ |
112
|
6 |
|
return $this->remoteTimeUrl; |
113
|
|
|
} |
114
|
6 |
|
|
115
|
|
|
/** |
116
|
|
|
* returns the of the remote location for checking the version of the ini file |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getRemoteVersionUrl() |
121
|
|
|
{ |
122
|
|
|
return $this->remoteVersionUrl; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|