-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseclass.class.php
executable file
·169 lines (151 loc) · 3.01 KB
/
baseclass.class.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
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* BaseClass
*
* @package default
* @author Ryan Abbott
*/
class BaseClass
{
protected $data = array();
/**
* Magic __set() method
*
* @param string $name
* @param string $value
* @return void
* @author Ryan Abbott
*/
public function __set($name, $value) {
//echo "Setting '$name' to '$value'\n";
$this->data[$name] = $value;
}
/**
* Magic __get() method
*
* @param string $name
* @return void
* @author Ryan Abbott
*/
public function __get($name) {
//echo "Getting '$name'\n";
if (array_key_exists($name, $this->data)) {
if (is_array($this->data[$name])) {
return (array) $this->data[$name];
}
return $this->data[$name];
}
$trace = debug_backtrace();
trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
E_USER_NOTICE);
return null;
}
/**
* Magic __isset() method
*
* @param string $name
* @return void
* @author Ryan Abbott
*/
public function __isset($name) {
//echo "Is '$name' set?\n";
return isset($this->data[$name]);
}
/**
* Magic __unset method
*
* @param string $name
* @return void
* @author Ryan Abbott
*/
public function __unset($name) {
//echo "Unsetting '$name'\n";
unset($this->data[$name]);
}
/**
* __toString
*
* @return void
* @author Ryan Abbott
*/
public function __toString() {
return $this->toString(TOSTRING_MEDIUM);
}
/**
* toString
*
* @return void
* @author Ryan Abbott
*/
public function toString() {
return "The " . get_class($this) ." object does not provide a toString() method.";
}
/**
* getMemberVars
*
* @return array of member variables
* @author Ryan Abbott
*/
public function getMemberVars() {
return $this->data;
}
/**
* getStaticProperty
*
* @package default
* @author Ryan Abbott
*/
public function getStaticProperty($property) {
if(!property_exists(get_class($this), $property)) {
return false;
}
$vars = get_class_vars(get_class($this));
return $vars[$property];
}
/**
* getRemoveUrl
*
* @return void
* @author Ryan Abbott
*/
public function getRemoveUrl() {
if(isset($this->id) && isNotEmpty($this->id)) {
return "/admin/" . strtolower(pluralize(get_class($this))) . "/remove.php?id=" . $this->id;
}
else {
return EMPTY_LINK;
}
}
/**
* getViewUrl
*
* @return void
* @author Ryan Abbott
*/
public function getViewUrl() {
if(isset($this->id) && isNotEmpty($this->id)) {
return "/admin/" . strtolower(pluralize(get_class($this))) . "/view.php?id=" . $this->id;
}
else {
return EMPTY_LINK;
}
}
/**
* getEditUrl
*
* @return void
* @author Ryan Abbott
*/
public function getEditUrl() {
if(isset($this->id) && isNotEmpty($this->id)) {
return "/admin/" . strtolower(pluralize(get_class($this))) . "/edit.php?id=" . $this->id;
}
else {
return EMPTY_LINK;
}
}
}
?>