1 | <?php namespace Arcanedev\LaravelTracker\Detectors; |
||
13 | class DeviceDetector implements DeviceDetectorContract |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Properties |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | /** @var \Arcanedev\Agent\Contracts\Agent */ |
||
21 | protected $agent; |
||
22 | |||
23 | /* ----------------------------------------------------------------- |
||
24 | | Constructor |
||
25 | | ----------------------------------------------------------------- |
||
26 | */ |
||
27 | |||
28 | /** |
||
29 | * DeviceDetector constructor. |
||
30 | * |
||
31 | * @param \Arcanedev\Agent\Contracts\Agent $agent |
||
32 | */ |
||
33 | 9 | public function __construct(Agent $agent) |
|
37 | |||
38 | /* ----------------------------------------------------------------- |
||
39 | | Main Methods |
||
40 | | ----------------------------------------------------------------- |
||
41 | */ |
||
42 | |||
43 | /** |
||
44 | * Detect kind, model and mobility. |
||
45 | * |
||
46 | * @return array |
||
47 | */ |
||
48 | 9 | public function detect() |
|
49 | { |
||
50 | return [ |
||
51 | 9 | 'kind' => $this->getDeviceKind(), |
|
52 | 9 | 'model' => $this->agent->device() ?: '', |
|
53 | ]; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Get the kind of device. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 9 | public function getDeviceKind() |
|
62 | { |
||
63 | 9 | if ($this->isTablet()) |
|
64 | return Device::KIND_TABLET; |
||
65 | |||
66 | 9 | if ($this->isPhone()) |
|
67 | return Device::KIND_PHONE; |
||
68 | |||
69 | 9 | if ($this->isComputer()) |
|
70 | 9 | return Device::KIND_COMPUTER; |
|
71 | |||
72 | return Device::KIND_UNAVAILABLE; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Is this a tablet? |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 9 | public function isTablet() |
|
84 | |||
85 | /** |
||
86 | * Is this a computer? |
||
87 | * |
||
88 | * @return bool |
||
89 | */ |
||
90 | 9 | public function isComputer() |
|
94 | |||
95 | /** |
||
96 | * Is this a phone? |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | 9 | public function isPhone() |
|
104 | } |
||
105 |