-
Notifications
You must be signed in to change notification settings - Fork 455
Expand file tree
/
Copy pathWiFi.php
More file actions
115 lines (102 loc) · 2.32 KB
/
WiFi.php
File metadata and controls
115 lines (102 loc) · 2.32 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
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
<?php
namespace SimpleSoftwareIO\QrCode\DataTypes;
class WiFi implements DataTypeInterface
{
/**
* The prefix of the QrCode.
*
* @var string
*/
protected $prefix = 'WIFI:';
/**
* The separator between the variables.
*
* @var string
*/
protected $separator = ';';
/**
* The encryption of the network. WEP or WPA.
*
* @var string
*/
protected $encryption;
/**
* The SSID of the WiFi network.
*
* @var string
*/
protected $ssid;
/**
* The password of the network.
*
* @var string
*/
protected $password;
/**
* Whether the network is a hidden SSID or not.
*
* @var bool
*/
protected $hidden;
/**
* Generates the DataType Object and sets all of its properties.
*
* @param $arguments
*/
public function create(array $arguments)
{
$this->setProperties($arguments);
}
/**
* Returns the correct QrCode format.
*
* @return string
*/
public function __toString()
{
return $this->buildWifiString();
}
/**
* Builds the WiFi string.
*
* @return string
*/
protected function buildWifiString()
{
$wifi = $this->prefix;
if (isset($this->encryption)) {
$wifi .= 'T:'.$this->encryption.$this->separator;
}
if (isset($this->ssid)) {
$wifi .= 'S:'.$this->ssid.$this->separator;
}
if (isset($this->password)) {
$wifi .= 'P:'.$this->password.$this->separator;
}
if (isset($this->hidden)) {
$wifi .= 'H:'.$this->hidden.$this->separator;
}
return $wifi;
}
/**
* Sets the WiFi properties.
*
* @param $arguments
*/
protected function setProperties(array $arguments)
{
$arguments = $arguments[0];
if (isset($arguments['encryption'])) {
$this->encryption = $arguments['encryption'];
}
if (isset($arguments['ssid'])) {
$this->ssid = $arguments['ssid'];
}
if (isset($arguments['password'])) {
$this->password = $arguments['password'];
}
if (isset($arguments['hidden'])) {
$this->hidden = $arguments['hidden'];
}
}
}