/
DeviceInterface.php
143 lines (127 loc) · 3.07 KB
/
DeviceInterface.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace Concrete\Core\Device;
/**
* Class Device
* A representation of a device.
*
* \@package Concrete\Core\Device
*/
interface DeviceInterface
{
/**
* Device type constants, combine them like so:.
*
* $device = new Device('Microsoft Surface', 1366, 768, Device::TABLET | Device::DESKTOP, 1.5);
*
* and you can test against them like this:
*
* $type = $device->getType();
* // Is the type known, and if so is it mobile?
* if ($type != Device::UNKNOWN && $type & Device::MOBILE) {
* // Mobile
* }
*/
const UNKNOWN = 0;
const MOBILE = 1;
const TABLET = 2;
const DESKTOP = 4;
/**
* Get the device handle.
*
* @return string
*/
public function getHandle();
/**
* Get the device name.
*
* @return string
*/
public function getName();
/**
* Get the device brand.
*
* @return string
*/
public function getBrand();
/**
* Get the device user agent.
*
* @return string
*/
public function getUserAgent();
/**
* Get the screen width of the device in pixels
* Be sure to adjust this by the device pixel ratio.
*
* @return int
*/
public function getWidth();
/**
* Get the screen height of the device in pixels
* Be sure to adjust this by the device pixel ratio.
*
* @return int
*/
public function getHeight();
/**
* Get the devices type
* this is an int that maps to a constant on this class, UNKNOWN MOBILE TABLET or DESKTOP
* If testing against a device and not against "UNKNOWN", do not test this directly against a device type, instead
* use bitwise AND to test for the enum you'd like to test:.
*
* // Check if the type is known, if so is it mobile?
* if ($device->getType() == Device::UNKNOWN) {
* $is_mobile = !!($device->getPixelRatio() & Device::MOBILE);
* }
*
* http://php.net/manual/en/language.operators.bitwise.php
*
* @return int
*/
public function getType();
/**
* Get the device pixel ratio.
*
* @return int
*/
public function getPixelRatio();
/**
* Get the HTML for this device's viewport.
*
* @return string
*/
public function getViewportHTML();
/**
* Get the class to be used for this device's icon.
*
* @return string
*/
public function getIconClass();
/**
* @return bool
*/
public function isMobile();
/**
* @return bool
*/
public function isTablet();
/**
* @return bool
*/
public function isDesktop();
/**
* Get the device's default orientation.
*
* @return string ["landscape"|"portrait"]
*/
public function getDefaultOrientation();
/**
* Construct from given configuration.
*
* @param $handle
* @param array $config
*
* @return static
*/
public static function configConstructor($handle, array $config);
}