diff --git a/src/Console/src/Command.php b/src/Console/src/Command.php index fe11cf881..2a6ab2772 100644 --- a/src/Console/src/Command.php +++ b/src/Console/src/Command.php @@ -113,7 +113,7 @@ function () use ($method) { return $core instanceof HandlerInterface ? (int)$core->handle(new CallContext( - Target::fromReflectionMethod(new \ReflectionMethod(static::class, $method)), + Target::fromPair($this, $method), $arguments, )) : (int)$core->callAction(static::class, $method, $arguments); diff --git a/src/Events/src/EventDispatcher.php b/src/Events/src/EventDispatcher.php index 853f1722d..47e5b2231 100644 --- a/src/Events/src/EventDispatcher.php +++ b/src/Events/src/EventDispatcher.php @@ -24,7 +24,7 @@ public function dispatch(object $event): object return $this->isLegacy ? $this->core->callAction($event::class, 'dispatch', ['event' => $event]) : $this->core->handle(new CallContext( - Target::fromReflectionMethod(new \ReflectionMethod($event::class, 'dispatch')), + Target::fromPair($event, 'dispatch'), ['event' => $event], )); } diff --git a/src/Hmvc/tests/Interceptors/Unit/Context/TargetTest.php b/src/Hmvc/tests/Interceptors/Unit/Context/TargetTest.php index 6f9c7f267..d6642193e 100644 --- a/src/Hmvc/tests/Interceptors/Unit/Context/TargetTest.php +++ b/src/Hmvc/tests/Interceptors/Unit/Context/TargetTest.php @@ -143,12 +143,25 @@ public function testCreateFromPair(string $controller, string $action, bool $has self::assertSame([$controller, $action], $target->getPath()); $reflection = $target->getReflection(); self::assertSame($hasReflection, $reflection !== null); + self::assertNull($target->getObject()); if ($hasReflection) { self::assertInstanceOf(\ReflectionMethod::class, $reflection); self::assertSame($action, $reflection->getName()); } } + public function testCreateFromObject(): void + { + $service = new TestService(); + $target = Target::fromPair($service, 'parentMethod'); + + self::assertSame([TestService::class, 'parentMethod'], $target->getPath()); + $reflection = $target->getReflection(); + self::assertInstanceOf(\ReflectionMethod::class, $reflection); + self::assertSame('parentMethod', $reflection->getName()); + self::assertSame($service, $target->getObject()); + } + public function testCreateFromPathStringDefaultSeparator(): void { $str = 'foo.bar.baz';