1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Helpers.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license https://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec <[email protected]> |
8
|
|
|
* @package iPublikuj:MobileDetect! |
9
|
|
|
* @subpackage Templating |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 16.06.14 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\MobileDetect\Templating; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
|
21
|
|
|
use IPub\MobileDetect; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Mobile detect template helpers |
25
|
|
|
* |
26
|
|
|
* @package iPublikuj:MobileDetect! |
27
|
|
|
* @subpackage Templating |
28
|
|
|
* |
29
|
|
|
* @author Adam Kadlec <[email protected]> |
30
|
|
|
*/ |
31
|
1 |
|
final class Helpers |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Implement nette smart magic |
35
|
|
|
*/ |
36
|
1 |
|
use Nette\SmartObject; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var MobileDetect\MobileDetect |
40
|
|
|
*/ |
41
|
|
|
private $mobileDetect; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var MobileDetect\Helpers\DeviceView |
45
|
|
|
*/ |
46
|
|
|
private $deviceView; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param MobileDetect\MobileDetect $mobileDetect |
50
|
|
|
* @param MobileDetect\Helpers\DeviceView $deviceView |
51
|
|
|
*/ |
52
|
|
|
public function __construct( |
53
|
|
|
MobileDetect\MobileDetect $mobileDetect, |
54
|
|
|
MobileDetect\Helpers\DeviceView $deviceView |
55
|
|
|
) { |
56
|
1 |
|
$this->mobileDetect = $mobileDetect; |
57
|
1 |
|
$this->deviceView = $deviceView; |
58
|
1 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return MobileDetect\MobileDetect |
62
|
|
|
*/ |
63
|
|
|
public function getMobileDetectService() : MobileDetect\MobileDetect |
64
|
|
|
{ |
65
|
|
|
return $this->mobileDetect; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return MobileDetect\Helpers\DeviceView |
70
|
|
|
*/ |
71
|
|
|
public function getDeviceViewService() : MobileDetect\Helpers\DeviceView |
72
|
|
|
{ |
73
|
|
|
return $this->deviceView; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
|
|
public function isMobile() : bool |
80
|
|
|
{ |
81
|
1 |
|
return $this->mobileDetect->isMobile(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
|
|
public function isPhone() : bool |
88
|
|
|
{ |
89
|
|
|
return $this->mobileDetect->isPhone(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
|
|
public function isTablet() : bool |
96
|
|
|
{ |
97
|
1 |
|
return $this->mobileDetect->isTablet(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $device |
102
|
|
|
* |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public function isDevice(string $device) : bool |
106
|
|
|
{ |
107
|
1 |
|
return $this->mobileDetect->is($device); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string $os |
112
|
|
|
* |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
|
|
public function isOs(string $os) : bool |
116
|
|
|
{ |
117
|
1 |
|
return $this->mobileDetect->is($os); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
|
|
public function isFullView() : bool |
124
|
|
|
{ |
125
|
|
|
return $this->deviceView->isFullView(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
|
|
public function isMobileView() : bool |
132
|
|
|
{ |
133
|
|
|
return $this->deviceView->isMobileView(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return bool |
138
|
|
|
*/ |
139
|
|
|
public function isPhoneView() : bool |
140
|
|
|
{ |
141
|
|
|
return $this->deviceView->isPhoneView(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return bool |
146
|
|
|
*/ |
147
|
|
|
public function isTabletView() : bool |
148
|
|
|
{ |
149
|
|
|
return $this->deviceView->isTabletView(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return bool |
154
|
|
|
*/ |
155
|
|
|
public function isNotMobileView() : bool |
156
|
|
|
{ |
157
|
|
|
return $this->deviceView->isNotMobileView(); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|