-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.php
114 lines (90 loc) · 2.58 KB
/
switch.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
<?php
//okay so here, we are going to go ahead and create a switch object
//and then we are going to create a switch database
//for the class, it will be based on the mySwitches.json data
class SwitchItem implements JsonSerializable {
public $weight;
public $brand;
public $name;
public $price;
public $silent;
public $type;
public $img;
public $link;
public function SetWeight($w) {
$this->weight = $w;
}
public function SetBrand($hm) {
$this->brand = $hm;
}
public function SetName($sm) {
$this->name = $sm;
}
public function SetPrice($bm) {
$this->price = $bm;
}
public function SetSilent($b) {
$this->silent = $b;
}
public function SetType($n) {
$this->type = $n;
}
public function SetImg($im) {
$this->img = $im;
}
public function SetLink($l) {
$this->link = $l;
}
public function __construct() {
$this->weight = 0;
$this->brand = generateRandomString();
$this->name = generateRandomString();
$this->price = 0;
$this->silent = false;
$this->type = "clicky";
$this->img = generateRandomString();
$this->link = generateRandomString();
}
//rechecking all. This is fine for now.
public function jsonSerialize() {
return [
'weight' => $this->weight,
'brand' => $this->brand,
'name' => $this->name,
'price' => $this->price,
'silent' => $this->silent,
'type' => $this->type,
'img' => $this->img,
'link' => $this->link
];
}
public function Set($json) {
$this->SetWeight($json['weight']);
$this->SetBrand($json['brand']);
$this->SetName($json['name']);
$this->SetPrice($json['price']);
$this->SetSilent($json['silent']);
$this->SetType($json['type']);
$this->SetImg($json['img']);
$this->SetLink($json['link']);
}
public function Display(){
$v=json_encode($this);
echo $v;
}
public function GetString() {
$v=json_encode($this);
return $v;
}
}
function generateRandomString($length = 10) {
// list of characters that can be present in the string
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>