33namespace spaf \simputils \traits ;
44
55use JsonException ;
6+ use ReflectionException ;
67use spaf \simputils \exceptions \InfiniteLoopPreventionExceptions ;
78use spaf \simputils \exceptions \MetaMagicStrictInheritanceProblem ;
9+ use spaf \simputils \exceptions \PropertyDoesNotExist ;
810use spaf \simputils \FS ;
911use spaf \simputils \generic \BasicPrism ;
1012use spaf \simputils \generic \SimpleObject ;
@@ -181,7 +183,7 @@ protected function _jsonFlags(bool $pretty = null) {
181183 * @param string $json Json string
182184 *
183185 * @return static
184- * @throws \ ReflectionException Reflection issues
186+ * @throws ReflectionException Reflection issues
185187 */
186188 public static function fromJson (string $ json ): static {
187189 $ data = json_decode ($ json , true );
@@ -404,8 +406,8 @@ private function _iterateConvertObjectsAndArrays(
404406 * By default is true
405407 *
406408 * @return object Always returns a new object of type provided as a first argument
407- * @throws \ ReflectionException Reflection issue
408- * @throws \spaf\simputils\exceptions\ MetaMagicStrictInheritanceProblem Strict Inheritance
409+ * @throws ReflectionException Reflection issue
410+ * @throws MetaMagicStrictInheritanceProblem Strict Inheritance
409411 * Problem
410412 */
411413 public static function expandFrom (
@@ -433,7 +435,7 @@ public static function expandFrom(
433435 * @param array $data Array data for the class
434436 *
435437 * @return static
436- * @throws \ ReflectionException Reflection issues
438+ * @throws ReflectionException Reflection issues
437439 */
438440 public static function fromArray (array $ data ): static {
439441 $ class = static ::class;
@@ -451,7 +453,7 @@ public static function fromArray(array $data): static {
451453 *
452454 * @return static
453455 *
454- * @throws \ ReflectionException Reflection Exception
456+ * @throws ReflectionException Reflection Exception
455457 */
456458 public static function createDummy (): static {
457459 /** @noinspection PhpIncompatibleReturnTypeInspection */
@@ -478,15 +480,25 @@ protected static function ___l10n(array $data) {
478480 * @param array|Box $data Setup data
479481 *
480482 * @return $this
483+ * @throws ReflectionException
481484 */
482485 protected function ___setup (array |Box $ data ): static {
483486 foreach ($ data as $ key => $ val ) {
484- if (is_array ($ val ) && !empty ($ val [PHP ::$ serialized_class_key_name ])) {
485- $ obj = PHP ::createDummy ($ val [PHP ::$ serialized_class_key_name ]);
486- unset($ val [PHP ::$ serialized_class_key_name ]);
487- $ val = PHP ::metaMagicSpell ($ obj , 'setup ' , $ val );
487+ // MARK Temporary hack to resolve unknown "properties" during setup,
488+ // https://github.com/PandaHugMonster/php-simputils/issues/170
489+
490+ // MARK This hack must be revised and the issue considered during redesign
491+ // of the engine
492+ try {
493+ if (is_array ($ val ) && !empty ($ val [PHP ::$ serialized_class_key_name ])) {
494+ $ obj = PHP ::createDummy ($ val [PHP ::$ serialized_class_key_name ]);
495+ unset($ val [PHP ::$ serialized_class_key_name ]);
496+ $ val = PHP ::metaMagicSpell ($ obj , 'setup ' , $ val );
497+ }
498+ $ this ->$ key = $ val ;
499+ } catch (PropertyDoesNotExist ) {
500+ // MARK Skipping setting up an unknown "property"
488501 }
489- $ this ->$ key = $ val ;
490502 }
491503 return $ this ;
492504 }
0 commit comments