-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
126 lines (114 loc) · 2.08 KB
/
User.php
File metadata and controls
126 lines (114 loc) · 2.08 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
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* 用户接口
*
* @author fdipzone
* @DateTime 2023-03-30 17:01:31
*
*/
interface IUser{
/**
* 新增用户
*
* @author fdipzone
* @DateTime 2023-03-30 17:01:51
*
* @param array $data 用户数据
* @return int
*/
public function add(array $data):int;
/**
* 读取用户数据
*
* @author fdipzone
* @DateTime 2023-03-30 17:01:55
*
* @param int $id 用户id
* @return array
*/
public function get(int $id):array;
}
/**
* 用户类
*
* @author fdipzone
* @DateTime 2023-03-30 17:03:26
*
*/
class User implements IUser{
/**
* 用户数据
*
* @var array
*/
protected $user = array();
/**
* 新增用户
*
* @author fdipzone
* @DateTime 2023-03-30 17:01:51
*
* @param array $data 用户数据
* @return int
*/
public function add(array $data):int{
$this->user[] = $data;
$keys = array_keys($this->user);
return end($keys);
}
/**
* 读取用户数据
*
* @author fdipzone
* @DateTime 2023-03-30 17:01:55
*
* @param int $id 用户id
* @return array
*/
public function get(int $id):array{
if(isset($this->user[$id])){
return $this->user[$id];
}else{
return array();
}
}
}
/**
* VIP用户类
*
* @author fdipzone
* @DateTime 2023-03-30 17:28:13
*
*/
class Vip extends User{
/**
* 读取vip用户数据
*
* @author fdipzone
* @DateTime 2023-03-30 17:04:22
*
* @param int $id 用户id
* @return array
*/
public function getVip(int $id):array{
$data = $this->get($id);
if($data){
return $this->format($data);
}
return $data;
}
/**
* 修饰数据
*
* @author fdipzone
* @DateTime 2023-03-30 17:04:41
*
* @param array $data 用户数据
* @return array
*/
private function format(array $data):array{
$data['is_vip'] = 1;
return $data;
}
}
?>