BulkUpdater work.
[order_line_extra.git] / hincludes / lib / Reflect.class.php
1 <?php
2
3 class Reflect {
4         public function __construct(){}
5         static function hasField($o, $field) {
6                 return _hx_has_field($o, $field);
7         }
8         static function field($o, $field) {
9                 return _hx_field($o, $field);
10         }
11         static function setField($o, $field, $value) {
12                 $o->{$field} = $value;
13         }
14         static function getProperty($o, $field) {
15                 if(null === $o) {
16                         return null;
17                 }
18                 $cls = ((Std::is($o, _hx_qtype("Class"))) ? $o->__tname__ : get_class($o));
19                 $cls_vars = get_class_vars($cls);
20                 if(isset($cls_vars['__properties__']) && isset($cls_vars['__properties__']['get_'.$field]) && ($field = $cls_vars['__properties__']['get_'.$field])) {
21                         return $o->$field();
22                 } else {
23                         return $o->$field;
24                 }
25         }
26         static function setProperty($o, $field, $value) {
27                 if(null === $o) {
28                         null;
29                         return;
30                 }
31                 $cls = ((Std::is($o, _hx_qtype("Class"))) ? $o->__tname__ : get_class($o));
32                 $cls_vars = get_class_vars($cls);
33                 if(isset($cls_vars['__properties__']) && isset($cls_vars['__properties__']['set_'.$field]) && ($field = $cls_vars['__properties__']['set_'.$field])) {
34                         $o->$field($value);
35                         return;
36                 } else {
37                         $o->$field = $value;
38                         return;
39                 }
40         }
41         static function callMethod($o, $func, $args) {
42                 if(is_string($o) && !is_array($func)) {
43                         return call_user_func_array(Reflect::field($o, $func), $args->»a);
44                 }
45                 return call_user_func_array(((is_callable($func)) ? $func : array($o, $func)), ((null === $args) ? array() : $args->»a));
46         }
47         static function fields($o) {
48                 if($o === null) {
49                         return new _hx_array(array());
50                 }
51                 return (($o instanceof _hx_array) ? new _hx_array(array('concat','copy','insert','iterator','length','join','pop','push','remove','reverse','shift','slice','sort','splice','toString','unshift')) : ((is_string($o)) ? new _hx_array(array('charAt','charCodeAt','indexOf','lastIndexOf','length','split','substr','toLowerCase','toString','toUpperCase')) : new _hx_array(_hx_get_object_vars($o))));
52         }
53         static function isFunction($f) {
54                 return (is_array($f) && is_callable($f)) || _hx_is_lambda($f) || is_array($f) && _hx_has_field($f[0], $f[1]) && $f[1] !== "length";
55         }
56         static function compare($a, $b) {
57                 return (($a == $b) ? 0 : (($a > $b) ? 1 : -1));
58         }
59         static function compareMethods($f1, $f2) {
60                 if(is_array($f1) && is_array($f1)) {
61                         return $f1[0] === $f2[0] && $f1[1] == $f2[1];
62                 }
63                 if(is_string($f1) && is_string($f2)) {
64                         return _hx_equal($f1, $f2);
65                 }
66                 return false;
67         }
68         static function isObject($v) {
69                 if($v === null) {
70                         return false;
71                 }
72                 if(is_object($v)) {
73                         return $v instanceof _hx_anonymous || Type::getClass($v) !== null;
74                 }
75                 return is_string($v) && !_hx_is_lambda($v);
76         }
77         static function deleteField($o, $f) {
78                 if(!_hx_has_field($o, $f)) {
79                         return false;
80                 }
81                 if(isset($o->»dynamics[$f])) unset($o->»dynamics[$f]); else if($o instanceof _hx_anonymous) unset($o->$f); else $o->$f = null;
82                 return true;
83         }
84         static function copy($o) {
85                 if(is_string($o)) {
86                         return $o;
87                 }
88                 $o2 = _hx_anonymous(array());
89                 {
90                         $_g = 0; $_g1 = Reflect::fields($o);
91                         while($_g < $_g1->length) {
92                                 $f = $_g1[$_g];
93                                 ++$_g;
94                                 $o2->{$f} = Reflect::field($o, $f);
95                                 unset($f);
96                         }
97                 }
98                 return $o2;
99         }
100         static function makeVarArgs($f) {
101                 return array(new _hx_lambda(array(&$f), '_hx_make_var_args'), 'execute');
102         }
103         function __toString() { return 'Reflect'; }
104 }