44
55namespace WonderNetwork \SlimKernel \Messenger \Kernel ;
66
7+ use ReflectionClass ;
78use ReflectionException ;
89use ReflectionIntersectionType ;
910use ReflectionNamedType ;
10- use ReflectionObject ;
1111use ReflectionUnionType ;
1212use RuntimeException ;
1313
1414final readonly class HandlerToMessageMapping {
1515 /**
1616 * @throws ReflectionException
1717 */
18- public function __invoke (mixed $ handler ): string {
19- if (false === is_object ($ handler )) {
18+ public function __invoke (string $ handler ): string {
19+ if (false === class_exists ($ handler )) {
2020 throw new RuntimeException (
2121 sprintf (
2222 'Handler must be an object, %s given ' ,
@@ -25,13 +25,13 @@ public function __invoke(mixed $handler): string {
2525 );
2626 }
2727
28- $ reflectionObject = new ReflectionObject ($ handler );
28+ $ reflectionObject = new ReflectionClass ($ handler );
2929
3030 if (false === $ reflectionObject ->hasMethod ('__invoke ' )) {
3131 throw new RuntimeException (
3232 sprintf (
3333 'Handler %s does not have an __invoke method ' ,
34- $ handler::class ,
34+ $ handler ,
3535 ),
3636 );
3737 }
@@ -42,7 +42,7 @@ public function __invoke(mixed $handler): string {
4242 throw new RuntimeException (
4343 sprintf (
4444 'Handler %s::__invoke() is expected to have exactly one parameter, actual: %d ' ,
45- $ handler::class ,
45+ $ handler ,
4646 $ reflectionMethod ->getNumberOfParameters (),
4747 ),
4848 );
@@ -52,11 +52,11 @@ public function __invoke(mixed $handler): string {
5252
5353 return match (true ) {
5454 $ type instanceof ReflectionNamedType => $ type ->getName (),
55- $ type instanceof ReflectionUnionType => $ this ->handleUnionTypes ($ handler::class , ...$ type ->getTypes ()),
55+ $ type instanceof ReflectionUnionType => $ this ->handleUnionTypes ($ handler , ...$ type ->getTypes ()),
5656 default => throw new RuntimeException (
5757 sprintf (
5858 'Handler %s::__invoke($message) is not properly typehinted ' ,
59- $ handler::class ,
59+ $ handler ,
6060 ),
6161 ),
6262 };
0 commit comments