1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElfSundae\Agent; |
4
|
|
|
|
5
|
|
|
use ArrayAccess; |
6
|
|
|
use JsonSerializable; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
use Jenssegers\Agent\Agent as BaseAgent; |
9
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
10
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
11
|
|
|
|
12
|
|
|
class Agent extends BaseAgent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable |
13
|
|
|
{ |
14
|
|
|
use Concerns\HasAttributes; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
24 |
|
public function __construct(array $headers = null, $userAgent = null) |
20
|
|
|
{ |
21
|
24 |
|
parent::__construct($headers, $userAgent); |
22
|
24 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
12 |
|
public function version($propertyName, $type = self::VERSION_TYPE_STRING) |
28
|
|
|
{ |
29
|
12 |
|
$version = parent::version($propertyName, $type); |
30
|
|
|
|
31
|
12 |
|
if (is_string($version)) { |
|
|
|
|
32
|
8 |
|
$version = str_replace(['_', ' ', '/'], '.', $version); |
33
|
4 |
|
} |
34
|
|
|
|
35
|
12 |
|
return $version; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get the version number of the given property in the User-Agent. |
40
|
|
|
* |
41
|
|
|
* @param string $propertyName |
42
|
|
|
* @return float |
43
|
|
|
*/ |
44
|
4 |
|
public function versionNumber($propertyName) |
45
|
|
|
{ |
46
|
4 |
|
return $this->version($propertyName, self::VERSION_TYPE_FLOAT); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the accept language. |
51
|
|
|
* |
52
|
|
|
* @param string|null $preferLanguage |
53
|
|
|
* @return string|bool |
54
|
|
|
*/ |
55
|
4 |
|
public function language($preferLanguage = null) |
56
|
|
|
{ |
57
|
4 |
|
$languages = $this->languages(); |
58
|
|
|
|
59
|
4 |
|
if (is_null($preferLanguage)) { |
60
|
4 |
|
return reset($languages); |
61
|
|
|
} |
62
|
|
|
|
63
|
4 |
|
$preferLanguage = strtolower($preferLanguage); |
64
|
|
|
|
65
|
4 |
|
foreach ($languages as $lang) { |
66
|
4 |
|
if (Str::startsWith($lang, $preferLanguage)) { |
67
|
4 |
|
return true; |
68
|
|
|
} |
69
|
2 |
|
} |
70
|
|
|
|
71
|
4 |
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the operating system name. |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
8 |
|
public function os() |
80
|
|
|
{ |
81
|
8 |
|
return $this->platform(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the operating system version. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
4 |
|
public function osVersion() |
90
|
|
|
{ |
91
|
4 |
|
return $this->version($this->os()); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|