1 | <?php namespace Arcanedev\LaravelTracker\Detectors; |
||
12 | class DeviceDetector implements DeviceDetectorContract |
||
13 | { |
||
14 | /* ------------------------------------------------------------------------------------------------ |
||
15 | | Properties |
||
16 | | ------------------------------------------------------------------------------------------------ |
||
17 | */ |
||
18 | /** @var \Jenssegers\Agent\Agent */ |
||
19 | protected $agent; |
||
20 | |||
21 | /* ------------------------------------------------------------------------------------------------ |
||
22 | | Constructor |
||
23 | | ------------------------------------------------------------------------------------------------ |
||
24 | */ |
||
25 | /** |
||
26 | * DeviceDetector constructor. |
||
27 | * |
||
28 | * @param \Jenssegers\Agent\Agent $agent |
||
29 | */ |
||
30 | 18 | public function __construct($agent) |
|
31 | { |
||
32 | 18 | $this->agent = $agent; |
|
33 | 18 | } |
|
34 | |||
35 | /* ------------------------------------------------------------------------------------------------ |
||
36 | | Main Functions |
||
37 | | ------------------------------------------------------------------------------------------------ |
||
38 | */ |
||
39 | /** |
||
40 | * Detect kind, model and mobility. |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | 18 | public function detect() |
|
45 | { |
||
46 | return [ |
||
47 | 18 | 'kind' => $this->getDeviceKind(), |
|
48 | 18 | 'model' => $this->agent->device() ?: '', |
|
49 | 9 | ]; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Get the kind of device. |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | 18 | public function getDeviceKind() |
|
65 | |||
66 | /** |
||
67 | * Is this a tablet? |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 18 | public function isTablet() |
|
75 | |||
76 | /** |
||
77 | * Is this a computer? |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | 18 | public function isComputer() |
|
85 | |||
86 | /** |
||
87 | * Is this a phone? |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | 18 | public function isPhone() |
|
95 | } |
||
96 |