@@ -55,32 +55,39 @@ public function api($api)
5555 * @param array $data
5656 * @return $this
5757 */
58- public function hydrate (array $ data = array ())
58+ protected function hydrate (array $ data = array ())
5959 {
6060 if (!empty ($ data )) {
61- foreach ($ data as $ k => $ v ) {
62- if (in_array ($ k , static ::$ properties )) {
63- $ this ->$ k = $ v ;
64- }
61+ foreach ($ data as $ field => $ value ) {
62+ $ this ->setData ($ field , $ value );
6563 }
6664 }
6765
6866 return $ this ;
6967 }
7068
7169 /**
72- * @param string $property
70+ * @param string $field
7371 * @param mixed $value
72+ * @return $this
7473 */
75- public function __set ( $ property , $ value )
74+ protected function setData ( $ field , $ value )
7675 {
77- if (!in_array ($ property , static ::$ properties )) {
78- throw new RuntimeException (sprintf (
79- 'Property "%s" does not exist for %s object ' , $ property , get_called_class ()
80- ));
76+ if (in_array ($ field , static ::$ properties )) {
77+ $ this ->data [$ field ] = $ value ;
8178 }
8279
83- $ this ->data [$ property ] = $ value ;
80+ return $ this ;
81+ }
82+
83+ /**
84+ * @param string $property
85+ * @param mixed $value
86+ * @throws RuntimeException
87+ */
88+ public function __set ($ property , $ value )
89+ {
90+ throw new RuntimeException ('Model properties are immutable ' );
8491 }
8592
8693 /**
@@ -102,4 +109,13 @@ public function __get($property)
102109
103110 return null ;
104111 }
112+
113+ /**
114+ * @param string $property
115+ * @return bool
116+ */
117+ public function __isset ($ property )
118+ {
119+ return isset ($ this ->data [$ property ]);
120+ }
105121}
0 commit comments