3
3
namespace spaf \simputils \traits ;
4
4
5
5
use JsonException ;
6
+ use ReflectionException ;
6
7
use spaf \simputils \exceptions \InfiniteLoopPreventionExceptions ;
7
8
use spaf \simputils \exceptions \MetaMagicStrictInheritanceProblem ;
9
+ use spaf \simputils \exceptions \PropertyDoesNotExist ;
8
10
use spaf \simputils \FS ;
9
11
use spaf \simputils \generic \BasicPrism ;
10
12
use spaf \simputils \generic \SimpleObject ;
@@ -181,7 +183,7 @@ protected function _jsonFlags(bool $pretty = null) {
181
183
* @param string $json Json string
182
184
*
183
185
* @return static
184
- * @throws \ ReflectionException Reflection issues
186
+ * @throws ReflectionException Reflection issues
185
187
*/
186
188
public static function fromJson (string $ json ): static {
187
189
$ data = json_decode ($ json , true );
@@ -404,8 +406,8 @@ private function _iterateConvertObjectsAndArrays(
404
406
* By default is true
405
407
*
406
408
* @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
409
411
* Problem
410
412
*/
411
413
public static function expandFrom (
@@ -433,7 +435,7 @@ public static function expandFrom(
433
435
* @param array $data Array data for the class
434
436
*
435
437
* @return static
436
- * @throws \ ReflectionException Reflection issues
438
+ * @throws ReflectionException Reflection issues
437
439
*/
438
440
public static function fromArray (array $ data ): static {
439
441
$ class = static ::class;
@@ -451,7 +453,7 @@ public static function fromArray(array $data): static {
451
453
*
452
454
* @return static
453
455
*
454
- * @throws \ ReflectionException Reflection Exception
456
+ * @throws ReflectionException Reflection Exception
455
457
*/
456
458
public static function createDummy (): static {
457
459
/** @noinspection PhpIncompatibleReturnTypeInspection */
@@ -478,15 +480,25 @@ protected static function ___l10n(array $data) {
478
480
* @param array|Box $data Setup data
479
481
*
480
482
* @return $this
483
+ * @throws ReflectionException
481
484
*/
482
485
protected function ___setup (array |Box $ data ): static {
483
486
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"
488
501
}
489
- $ this ->$ key = $ val ;
490
502
}
491
503
return $ this ;
492
504
}
0 commit comments