@@ -22,7 +22,7 @@ public function __get ($name) {
2222 $ modelName = $ this ->relations [$ name ][1 ];
2323 switch ($ relationType ) {
2424 case 'hasone ' :
25- return $ modelName ::byId ($ this ->data [$ name ]);
25+ return $ modelName ::ObjectBuilder ()-> byId ($ this ->data [$ name ]);
2626 break ;
2727 case 'hasmany ' :
2828 $ key = $ this ->relations [$ name ][2 ];
@@ -44,7 +44,7 @@ public function __get ($name) {
4444 }
4545
4646 public function __isset ($ name ) {
47- if ($ this ->data [$ name ])
47+ if (isset ( $ this ->data [$ name ]) )
4848 return isset ($ this ->data [$ name ]);
4949
5050 if (property_exists ($ this ->db , $ name ))
@@ -108,22 +108,21 @@ public function remove () {
108108 }
109109
110110
111- public static function byId ($ id , $ fields = null ) {
112- return static :: getOne ($ fields , $ id );
111+ private function byId ($ id , $ fields = null ) {
112+ return $ this -> getOne ($ fields , $ id );
113113 }
114114
115- public static function getOne ($ fields = null , $ primaryKey = null , $ obj = null ) {
116- $ obj = new static ;
115+ private function getOne ($ fields = null , $ primaryKey = null ) {
117116 if ($ primaryKey )
118- $ obj ->db ->where ($ obj ->primaryKey , $ primaryKey );
117+ $ this ->db ->where ($ this ->primaryKey , $ primaryKey );
119118
120- $ results = $ obj ->db ->getOne ($ obj ->dbTable , $ fields );
121- if (isset ($ obj ->jsonFields ) && is_array ($ obj ->jsonFields )) {
122- foreach ($ obj ->jsonFields as $ key )
119+ $ results = $ this ->db ->getOne ($ this ->dbTable , $ fields );
120+ if (isset ($ this ->jsonFields ) && is_array ($ this ->jsonFields )) {
121+ foreach ($ this ->jsonFields as $ key )
123122 $ results [$ key ] = json_decode ($ results [$ key ]);
124123 }
125- if (isset ($ obj ->arrayFields ) && is_array ($ obj ->arrayFields )) {
126- foreach ($ obj ->arrayFields as $ key )
124+ if (isset ($ this ->arrayFields ) && is_array ($ this ->arrayFields )) {
125+ foreach ($ this ->arrayFields as $ key )
127126 $ results [$ key ] = explode ("| " , $ results [$ key ]);
128127 }
129128 if (static ::$ returnType == 'Array ' )
@@ -135,17 +134,16 @@ public static function getOne ($fields = null, $primaryKey = null, $obj = null)
135134 return $ item ;
136135 }
137136
138- public static function get ($ limit = null , $ fields = null ) {
139- $ obj = new static ;
137+ private function get ($ limit = null , $ fields = null ) {
140138 $ objects = Array ();
141- $ results = $ obj ->db ->get ( $ obj ->dbTable , $ limit , $ fields );
139+ $ results = $ this ->db ->get ( $ this ->dbTable , $ limit , $ fields );
142140 foreach ($ results as &$ r ) {
143- if (isset ($ obj ->jsonFields ) && is_array ($ obj ->jsonFields )) {
144- foreach ($ obj ->jsonFields as $ key )
141+ if (isset ($ this ->jsonFields ) && is_array ($ this ->jsonFields )) {
142+ foreach ($ this ->jsonFields as $ key )
145143 $ r [$ key ] = json_decode ($ r [$ key ]);
146144 }
147- if (isset ($ obj ->arrayFields ) && is_array ($ obj ->arrayFields )) {
148- foreach ($ obj ->arrayFields as $ key )
145+ if (isset ($ this ->arrayFields ) && is_array ($ this ->arrayFields )) {
146+ foreach ($ this ->arrayFields as $ key )
149147 $ r [$ key ] = explode ("| " , $ r [$ key ]);
150148 }
151149 if (static ::$ returnType == 'Object ' ) {
@@ -173,19 +171,22 @@ public function count () {
173171 return $ res ['cnt ' ];
174172 }
175173
176-
177174 public function __call ($ method , $ arg ) {
175+ if (method_exists ($ this , $ method ))
176+ return call_user_func_array (array ($ this , $ method ), $ arg );
177+
178178 call_user_func_array (array ($ this ->db , $ method ), $ arg );
179179 return $ this ;
180180 }
181181
182182 public static function __callStatic ($ method , $ arg ) {
183183 $ obj = new static ;
184- call_user_func_array (array ($ obj , $ method ), $ arg );
184+ $ result = call_user_func_array (array ($ obj , $ method ), $ arg );
185+ if (method_exists ($ obj , $ method ))
186+ return $ result ;
185187 return $ obj ;
186188 }
187189
188-
189190 public function toJson () {
190191 return json_encode ($ this ->data );
191192 }
0 commit comments