diff --git a/src/functions/values.php b/src/functions/values.php index 0338ea3..3c74928 100644 --- a/src/functions/values.php +++ b/src/functions/values.php @@ -150,7 +150,7 @@ function get_object_changed_values($object) function build_object_ref($classOrCallable = null, array &$values, $context = null, $contextKey = null) { foreach (get_registered_hooks(HooksEnum::BUILD_OBJECT, HooksEnum::GET_OBJECT_CLASS) as $callback) { - if ($dynamicClassOrCallable = call_user_func($callback, $values, $context, $contextKey)) { + if ($dynamicClassOrCallable = call_user_func($callback, $values, $context, $contextKey, $classOrCallable)) { $classOrCallable = $dynamicClassOrCallable; } } diff --git a/tests/Model/ObjectInterface.php b/tests/Model/ObjectInterface.php new file mode 100644 index 0000000..20961f5 --- /dev/null +++ b/tests/Model/ObjectInterface.php @@ -0,0 +1,6 @@ + ['aKey' => ['aSubName' => ['aSubKey' => 'aFooVal']]]], get_values($obj)); self::assertSame(['aSubName' => ['aSubKey' => 'aFooVal']], get_values($subObj)); } + + public function testClassProvidedByHookBasedOnInterface() + { + $values = [ + 'aKey' => [ + 'aSubName' => ['aSubKey' => 'aFooVal'], + ], + ]; + + $obj = new EmptyObject(); + set_values($obj, $values); + + register_hook(HooksEnum::BUILD_OBJECT, HooksEnum::GET_OBJECT_CLASS, function($values, $context, $contextKey, $classOrCallable) { + $this->assertSame(ObjectInterface::class, $classOrCallable); + + return SubObject::class; + }); + + $subObj = get_object($obj, 'aKey', ObjectInterface::class); + + $this->assertInstanceOf(SubObject::class, $subObj); + } } \ No newline at end of file