-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNUObject.php
88 lines (78 loc) · 2.7 KB
/
NUObject.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
<?php
class NUObject
{
protected static $_classMethods = array();
protected static $_classProperties = array();
protected $_instanceMethods = array();
protected $_instanceProperties = array();
protected $_usePrototype = false;
public static $base;
public function __construct($members = array()) {
foreach ($members as $name => $value) {
$this->prototype->$name = $value;
}
if(isset($members['init']) && $members['init']==true){
self::$base=$this;
}
}
public function __get($property)
{
if ($property === 'prototype') {
$this->_usePrototype = true;
return $this;
} else {
if (array_key_exists($property, $this->_instanceMethods)) {
return $this->_instanceMethods[$property];
}
if (array_key_exists($property, $this->_instanceProperties)) {
return $this->_instanceProperties[$property];
}
if (array_key_exists($property, self::$_classMethods)) {
return self::$_classMethods[$property];
}
if (array_key_exists($property, self::$_classProperties)) {
return self::$_classProperties[$property];
}
return $this->$property;
}
}
public function __set($property, $value)
{
if ($property === 'prototype') {
throw new Exception('Cannot assign to prototype');
}
if ($this->_usePrototype) {
if ($value instanceof Closure) {
self::$_classMethods[$property] = $value;
} else {
self::$_classProperties[$property] = $value;
}
$this->_usePrototype = false;
} else {
if ($value instanceof Closure) {
$this->_instanceMethods[$property] = $value;
} else {
$this->_instanceProperties[$property] = $value;
}
}
}
public function __unset($property)
{
unset($this->_instanceMethods[$property]);
unset($this->_instanceProperties[$property]);
unset(self::$_classMethods[$property]);
unset(self::$_classProperties[$property]);
}
public function __call($method, $args){
$args = array_merge(array($this),$args);
//print_r($args);
if (array_key_exists($method, $this->_instanceMethods)) {
return call_user_func_array($this->_instanceMethods[$method], $args);
}
if (array_key_exists($method, self::$_classMethods)) {
return call_user_func_array(self::$_classMethods[$method], $args);
}
return call_user_func_array(array($this, $method), $args);
}
}
?>