This repository was archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathDevice.php
More file actions
83 lines (70 loc) · 1.54 KB
/
Device.php
File metadata and controls
83 lines (70 loc) · 1.54 KB
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
<?php
namespace Sinergi\BrowserDetector;
class Device
{
const UNKNOWN = 'unknown';
const IPAD = 'iPad';
const IPHONE = 'iPhone';
const WINDOWS_PHONE = 'Windows Phone';
const ANDROID_PHONE = 'Android Phone';
/**
* @var string
*/
private $name;
/**
* @var UserAgent
*/
private $userAgent;
/**
* @param null|string|UserAgent $userAgent
*
* @throws \Sinergi\BrowserDetector\InvalidArgumentException
*/
public function __construct($userAgent = null)
{
if ($userAgent instanceof UserAgent) {
$this->setUserAgent($userAgent);
} elseif (null === $userAgent || is_string($userAgent)) {
$this->setUserAgent(new UserAgent($userAgent));
} else {
throw new InvalidArgumentException();
}
}
/**
* @param UserAgent $userAgent
*
* @return $this
*/
public function setUserAgent(UserAgent $userAgent)
{
$this->userAgent = $userAgent;
return $this;
}
/**
* @return UserAgent
*/
public function getUserAgent()
{
return $this->userAgent;
}
/**
* @return string
*/
public function getName()
{
if (!isset($this->name)) {
DeviceDetector::detect($this, $this->getUserAgent());
}
return $this->name;
}
/**
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = (string)$name;
return $this;
}
}