@@ -49,7 +49,10 @@ public function getKnownProps() {
4949 * @return Element $this
5050 */
5151 public function setValue ($ new_value ) {
52- Helpers::checkType ('new_value ' , 'stdClass ' , $ new_value );
52+ if (gettype ($ new_value ) !== 'object ' ) {
53+ return parent ::setValue ($ new_value );
54+ }
55+
5356 $ new_props = $ this ->getSetProps ($ new_value );
5457
5558 foreach ($ new_props as $ new_prop ) {
@@ -66,6 +69,10 @@ public function setValue($new_value) {
6669 */
6770 protected function getSetProps ($ object = null ) {
6871 $ object = $ object ?: $ this ->value ;
72+ if (gettype ($ object ) !== 'object ' ) {
73+ return [];
74+ }
75+
6976 return array_keys ((array ) $ object );
7077 }
7178
@@ -74,6 +81,10 @@ protected function getSetProps($object = null) {
7481 * @return stdClass
7582 */
7683 public function getValue () {
84+ if (gettype ($ this ->value ) !== 'object ' ) {
85+ return parent ::getValue ();
86+ }
87+
7788 $ value = clone ($ this ->value );
7889 $ set_props = $ this ->getSetProps ();
7990
@@ -92,6 +103,12 @@ public function getValue() {
92103 * @return [Error]
93104 */
94105 public function validate () {
106+ $ value_type = gettype ($ this ->value );
107+ if (gettype ($ this ->value ) !== 'object ' ) {
108+ $ encoded_value = json_encode ($ this ->value );
109+ return [new Error ("` $ encoded_value` must be `object` not ` $ value_type` " )];
110+ }
111+
95112 $ errors = [];
96113
97114 // Gets properties.
@@ -132,6 +149,10 @@ public function validate() {
132149 * @return Element $this
133150 */
134151 public function setProp ($ prop_key , $ prop_value ) {
152+ if (gettype ($ this ->value ) !== 'object ' ) {
153+ return $ this ;
154+ }
155+
135156 Helpers::checkType ('prop_key ' , 'string ' , $ prop_key );
136157
137158 if ($ prop_value === null ) {
@@ -158,6 +179,10 @@ public function setProp($prop_key, $prop_value) {
158179 * @return mixed
159180 */
160181 public function getProp ($ prop_key ) {
182+ if (gettype ($ this ->value ) !== 'object ' ) {
183+ return null ;
184+ }
185+
161186 Helpers::checkType ('prop_key ' , 'string ' , $ prop_key );
162187 return isset ($ this ->value ->{$ prop_key }) ? $ this ->value ->{$ prop_key } : null ;
163188 }
@@ -168,6 +193,10 @@ public function getProp($prop_key) {
168193 * @return mixed
169194 */
170195 public function getPropValue ($ prop_key ) {
196+ if (gettype ($ this ->value ) !== 'object ' ) {
197+ return null ;
198+ }
199+
171200 Helpers::checkType ('prop_key ' , 'string ' , $ prop_key );
172201 return $ this ->_getPropValue (explode ('. ' , $ prop_key ));
173202 }
@@ -184,6 +213,10 @@ private function _getPropValue(array $prop_key) {
184213 }
185214
186215 public function unsetProp ($ prop_key ) {
216+ if (gettype ($ this ->value ) !== 'object ' ) {
217+ return $ this ;
218+ }
219+
187220 Helpers::checkType ('prop_key ' , 'string ' , $ prop_key );
188221 unset($ this ->value ->{$ prop_key });
189222 return $ this ;
0 commit comments