-
Notifications
You must be signed in to change notification settings - Fork 11
/
api.php
158 lines (138 loc) · 3.92 KB
/
api.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* This class is the api model class.
*
* @Author: Jingrong Tian ([email protected])
* @DateTime: 2015-09-25 22:14:28
* @Description: Description
*/
class Api
{
/**
* The class name.
* @var string
*/
private $__class_name;
/**
* The function name.
* @var string
*/
private $__function_name;
/**
* The description of the function.
* @var string
*/
private $__description;
/**
* The path of the class file.
* @var string
*/
private $__path;
/**
* The url for excuting the function.
* @var string
*/
private $__url;
/**
* The properties of the function
* @var array
*/
private $__properties;
/**
* The constructor of the Api class.
* @param string $class_name The class name.
* @param string $function_name The function name.
* @param string $description The description of the function.
*/
function __construct($class_name, $function_name, $description)
{
$this->__class_name = $class_name;
$this->__function_name = $function_name;
$this->__description = $description;
$this->__properties = array();
}
/**
* Set the path of the class file.
* @param string $path The path of the class file.
* @return boolean The result of setting.
*/
public function set_path ($path) {
$this->__path = $path;
}
/**
* Set the url of executing the function.
* @param string $url The url of executing the function.
* @return boolean The result of setting.
*/
public function set_url ($url) {
$this->__url = $url;
}
/**
* Add a property of the function.
* @param string $property_name The name of property.
* @param string $property_description The description of property.
* @return array The property which has been added in successfully.
*/
public function add_property($property_name, $property_description) {
try {
if (!$property_name) {
throw new Exception('Property can`t null.');
}
if ($this->__property_exist($property_name)) {
throw new Exception('Property has been existed.');
}
$property = array(
'name' => $property_name,
'description' => $property_description
);
$this->__properties[] = $property;
return $property;
} catch (Exception $e) {
echo $e->errorMessage();
}
}
/**
* Check whether the property is exist.
* @param string $property_name The property_name
* @return boolean The result of checking.
*/
private function __property_exist($property_name) {
if ($this->get_property($property_name)) {
return true;
} else {
return false;
}
}
/**
* Get the property.
* @param string $property_name The name of property.
* @return array The property which got.
* Return false if get nothing.
*/
public function get_property($property_name) {
foreach ($this->__properties as $index => $property) {
if ($property['name'] == $property_name) {
return $property;
}
}
return false;
}
public function get_class_name() {
return $this->__class_name;
}
public function get_function_name() {
return $this->__function_name;
}
public function get_description() {
return $this->__description;
}
public function get_path() {
return $this->__path;
}
public function get_url() {
return $this->__url;
}
public function get_properties() {
return $this->__properties;
}
}