-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeviceDetect.php
54 lines (47 loc) · 1.05 KB
/
DeviceDetect.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
<?php
namespace i4erkasov\devicedetect;
use yii\base\Component;
require_once(\Yii::getAlias('@vendor/mobiledetect/mobiledetectlib/Mobile_Detect.php'));
/**
* Uses the Mobile_Detect library.
* Extends functionality, added isDesktop method
* Requires "mobiledetect/mobiledetectlib": "^2.8"
*
* @method (bool)isMobile()
* @method (bool)isTablet()
* @method (bool)isDesktop()
*
* Class DeviceDetect
*/
class DeviceDetect extends Component
{
/**
* @var \Mobile_Detect
*/
private $_mobileDetect;
/**
* @inheritdoc
*/
public function init(): void
{
parent::init();
$this->_mobileDetect = new \Mobile_Detect();
}
/**
* @param $method
* @param $arguments
*
* @return mixed
*/
public function __call($method, $arguments)
{
return call_user_func_array([$this->_mobileDetect, $method], $arguments);
}
/**
* @return bool
*/
public function isDesktop(): bool
{
return ($this->isMobile() || $this->isTablet()) ? false : true;
}
}