object_class.php
2.2 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
<?php
/**
* Tiny - A PHP Framework For Web Artisans
* @author Tiny <tinylofty@gmail.com>
* @copyright Copyright(c) 2010-2014 http://www.tinyrise.com All rights reserved
* @version 1.0
*/
/**
* 系统的最基类
*
* @author Tiny
* @class Object
*/
class Object
{
protected $properties;
/**
* getter方法
*
* @access public
* @param mixed $name
* @return mixed
*/
public function __get($name)
{
$getter = 'get'.$name;
if(method_exists($this,$getter)) return $this->$getter();
if(isset($this->properties[$name])) return $this->properties[$name];
else null;
}
/**
* steter方法
*
* @access public
* @param mixed $name
* @param mixed $value
* @return mixed
*/
public function __set($name,$value)
{
$setter = 'set'.$name;
if(method_exists($this,$setter)) {
$this->$setter($value);
}else{
$this->properties[$name] = $value;
}
}
/**
* isset判断
*
* @access public
* @param mixed $name
* @return mixed
*/
public function __isset($name)
{
$getter = 'get'.$name;
if(method_exists($this,$getter)){
return $this->$getter()!==null;
}else{
return isset($this->properties[$name]);
}
}
/**
* 销毁
*
* @access public
* @param mixed $name
* @return mixed
*/
public function __unset($name)
{
$setter = 'set'.$name;
if(method_exists($this,$setter)){
$this->$setter(null);
}else{
unset($this->properties[$name]);
}
}
/**
* 调用方法
*
* @access public
* @param mixed $name
* @param mixed $args
* @return mixed
*/
public function __call($name,$args=null)
{
if(method_exists($this,$name))throw new Exception(get_class($this)." method {$name} is private or protected method",E_USER_ERROR);
else throw new Exception(get_class($this)." not exists {$name} method",E_USER_ERROR);
}
/**
* 取得属性
*
* @access public
* @return mixed
*/
public function getPropertys()
{
return $this->properties;
}
}