@@ -29,6 +29,71 @@ public function toJson()
29
29
return $ json ;
30
30
}
31
31
32
+ public function reflect ($ object = null )
33
+ {
34
+ if ($ object == null ) {
35
+ $ object = $ this ;
36
+ }
37
+
38
+ $ reflection = new \ReflectionObject ($ object );
39
+ $ properties = $ reflection ->getProperties ();
40
+
41
+ $ fields = [];
42
+
43
+ foreach ($ properties as $ property ) {
44
+ $ name = $ property ->getName ();
45
+ if ($ name == 'bot_name ' ) {
46
+ continue ;
47
+ }
48
+
49
+ if (!$ property ->isPrivate ()) {
50
+ $ array_of_obj = false ;
51
+ $ array_of_array_obj = false ;
52
+ if (is_array ($ object ->$ name )) {
53
+ $ array_of_obj = true ;
54
+ $ array_of_array_obj = true ;
55
+ foreach ($ object ->$ name as $ elm ) {
56
+ if (!is_object ($ elm )) {
57
+ //echo $name . " not array of object \n";
58
+ $ array_of_obj = false ;
59
+ //break;
60
+ }
61
+ if (is_array ($ elm )) {
62
+ foreach ($ elm as $ more_net ) {
63
+ if (!is_object ($ more_net )) {
64
+ $ array_of_array_obj = false ;
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ if (is_object ($ object ->$ name )) {
72
+ $ fields [$ name ] = $ this ->reflect ($ object ->$ name );
73
+ } elseif ($ array_of_obj ) {
74
+ foreach ($ object ->$ name as $ elm ) {
75
+ $ fields [$ name ][] = $ this ->reflect ($ elm );
76
+ }
77
+ } elseif ($ array_of_array_obj ) {
78
+ foreach ($ object ->$ name as $ elm ) {
79
+ $ temp = null ;
80
+ foreach ($ elm as $ obj ) {
81
+ $ temp [] = $ this ->reflect ($ obj );
82
+ }
83
+ $ fields [$ name ][] = $ temp ;
84
+ }
85
+ } else {
86
+ $ property ->setAccessible (true );
87
+ $ value = $ property ->getValue ($ object );
88
+ if (is_null ($ value )) {
89
+ continue ;
90
+ }
91
+ $ fields [$ name ] = $ value ;
92
+ }
93
+ }
94
+ }
95
+ return $ fields ;
96
+ }
32
97
33
98
public function reflect ($ object = null )
34
99
{
0 commit comments