forked from shetabit/visitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenssegersAgent.php
executable file
·90 lines (78 loc) · 1.55 KB
/
JenssegersAgent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Shetabit\Visitor\Drivers;
use Illuminate\Http\Request;
use Jenssegers\Agent\Agent;
use Shetabit\Visitor\Contracts\UserAgentParser;
class JenssegersAgent implements UserAgentParser
{
/**
* Request container.
*
* @var Request
*/
protected $request;
/**
* Agent parser.
*
* @var Agent
*/
protected $parser;
/**
* Parser constructor.
*
* @param Request $request
*/
public function __construct(Request $request)
{
$this->request = $request;
$this->parser = $this->initParser();
}
/**
* Retrieve device's name.
*
* @return string
*/
public function device() : string
{
return $this->parser->device();
}
/**
* Retrieve platform's name.
*
* @return string
*/
public function platform() : string
{
return $this->parser->platform();
}
/**
* Retrieve browser's name.
*
* @return string
*/
public function browser() : string
{
return $this->parser->browser();
}
/**
* Retrieve languages.
*
* @return array
*/
public function languages() : array
{
return $this->parser->languages();
}
/**
* Initialize userAgent parser.
*
* @return Agent
*/
protected function initParser()
{
$parser = new Agent();
$parser->setUserAgent($this->request->userAgent());
$parser->setHttpHeaders($this->request->headers);
return $parser;
}
}