-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
EmulatedDevice.php
72 lines (60 loc) · 1.47 KB
/
EmulatedDevice.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
<?php
namespace Piwik\Plugins\PerformanceAudit;
require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php';
use Ducks\Component\SplTypes\SplEnum;
use OutOfBoundsException;
class EmulatedDevice extends SplEnum
{
/**
* Default emulated device.
*
* @var string
*/
public const __default = self::Mobile;
/**
* Emulated devices.
*
* @var string
*/
public const Desktop = 'desktop';
/** @var string */
public const Mobile = 'mobile';
/** @var string */
public const Both = 'both';
/**
* Lookup array for devices.
*
* @var array
*/
private const Lookup = [
self::Mobile => 1,
self::Desktop => 2,
self::Both => 3
];
/**
* Get ID of emulated device.
*
* @param string $enum
* @return int
* @throws OutOfBoundsException
*/
public static function getIdFor(string $enum) {
if (!isset(self::Lookup[$enum])) {
throw new OutOfBoundsException($enum . ' is no valid EmulatedDevice enum.');
}
return self::Lookup[$enum];
}
/**
* Get emulated device(s) as array.
*
* @param string $enum
* @return array
*/
public static function getList(string $enum) {
$emulatedDevices = (array) $enum;
if (current($emulatedDevices) === 'both') {
$emulatedDevices = ['desktop', 'mobile'];
}
return $emulatedDevices;
}
}