@@ -49,7 +49,8 @@ public static function all(){
4949
5050 /**
5151 * 数据表字段检索
52- * @param string $field, string $string
52+ * @param string $field
53+ * @param string $string
5354 * @return Collection
5455 */
5556 public static function search ($ field ,$ string ){
@@ -86,7 +87,8 @@ public static function raw($sqlStatement){
8687
8788 /**
8889 * Model 分页
89- * @param int $pageNum, boolean $furtherPageInfo
90+ * @param int $pageNum
91+ * @param boolean $furtherPageInfo
9092 * @return Collection
9193 * @uses Model 集合分页功能
9294 */
@@ -187,16 +189,41 @@ public static function makeCollection($array = []) {
187189
188190 public function __set ($ name , $ value ) {
189191 // $demo->property = "text";
190- return $ this ->objectData [$ name ] = $ value ;
192+
193+ // 通过反射判断是否已经预定义修饰器
194+ try {
195+ $ modelClass = new \ReflectionClass (static ::class);
196+ if ($ modelClass ->hasMethod ("set " .ucfirst ($ name ))){
197+ $ methodName = "set " .ucfirst ($ name );
198+ $ value = $ this ->$ methodName ($ value );
199+ }
200+ } catch (\ReflectionException $ e ) {
201+ // do nothing..
202+ } finally {
203+ return $ this ->objectData [$ name ] = $ value ;
204+ }
191205 }
192206
193207 public function __get ($ name ) {
194208 // echo $demo->property
195- if (isset ($ this ->objectData [$ name ])){
196- return $ this ->objectData [$ name ];
197- } else {
198- return null ;
209+
210+ // 通过反射判断是否已经预定义访问器
211+ try {
212+ $ modelClass = new \ReflectionClass (static ::class);
213+ if ($ modelClass ->hasMethod ("get " .ucfirst ($ name ))){
214+ $ methodName = "get " .ucfirst ($ name );
215+ return $ this ->$ methodName ();
216+ }
217+ } catch (\ReflectionException $ e ) {
218+ // do nothing..
219+ } finally {
220+ if (isset ($ this ->objectData [$ name ])){
221+ return $ this ->objectData [$ name ];
222+ } else {
223+ return null ;
224+ }
199225 }
226+
200227 }
201228
202229 public function __isset ($ name ) {
@@ -228,6 +255,7 @@ public function __toString() {
228255
229256 /**
230257 * 将实例转换为 JSON 字符串
258+ * @param $option
231259 * @return string
232260 */
233261 public function toJson ($ option = 0 ) {
0 commit comments