@@ -16,22 +16,23 @@ public function __invoke(RegularQuery $query): RegularQueryResult
1616 }
1717}
1818
19+ class BooleanQuery {}
1920class StringQuery {}
2021class IntQuery {}
2122class FloatQuery {}
2223class MultiQueryHandler implements MessageSubscriberInterface
2324{
2425 public static function getHandledMessages (): iterable
2526 {
26- yield StringQuery ::class;
27+ yield BooleanQuery ::class;
2728 yield IntQuery::class => ['method ' => 'handleInt ' ];
2829 yield FloatQuery::class => ['method ' => 'handleFloat ' ];
2930 yield StringQuery::class => ['method ' => 'handleString ' ];
3031 }
3132
32- public function __invoke (StringQuery $ query ): string
33+ public function __invoke (BooleanQuery $ query ): bool
3334 {
34- return ' string result ' ;
35+ return true ;
3536 }
3637
3738 public function handleInt (IntQuery $ query ): int
@@ -52,16 +53,63 @@ public function handleString(StringQuery $query): string
5253 // todo add handle method with union return type?
5354 }
5455
56+ class TaggedQuery {}
57+ class TaggedResult {}
58+ class TaggedHandler
59+ {
60+ public function handle (TaggedQuery $ query ): TaggedResult
61+ {
62+ return new TaggedResult ();
63+ }
64+ }
65+
66+ class MultiHandlesForInTheSameHandlerQuery {}
67+ class MultiHandlesForInTheSameHandler implements MessageSubscriberInterface
68+ {
69+ public static function getHandledMessages (): iterable
70+ {
71+ yield MultiHandlesForInTheSameHandlerQuery::class;
72+ yield MultiHandlesForInTheSameHandlerQuery::class => ['priority ' => '0 ' ];
73+ }
74+
75+ public function __invoke (MultiHandlesForInTheSameHandlerQuery $ query ): bool
76+ {
77+ return true ;
78+ }
79+ }
80+
81+ class MultiHandlersForTheSameMessageQuery {}
82+ class MultiHandlersForTheSameMessageHandler1
83+ {
84+ public function __invoke (MultiHandlersForTheSameMessageQuery $ query ): bool
85+ {
86+ return true ;
87+ }
88+ }
89+ class MultiHandlersForTheSameMessageHandler2
90+ {
91+ public function __invoke (MultiHandlersForTheSameMessageQuery $ query ): bool
92+ {
93+ return false ;
94+ }
95+ }
96+
5597class HandleTraitClass {
5698 use HandleTrait;
5799
58100 public function __invoke ()
59101 {
60102 assertType (RegularQueryResult::class, $ this ->handle (new RegularQuery ()));
103+
104+ assertType ('bool ' , $ this ->handle (new BooleanQuery ()));
61105 assertType ('int ' , $ this ->handle (new IntQuery ()));
62106 assertType ('float ' , $ this ->handle (new FloatQuery ()));
107+ assertType ('string ' , $ this ->handle (new StringQuery ()));
108+
109+ assertType (TaggedResult::class, $ this ->handle (new TaggedQuery ()));
63110
64- // HandleTrait will throw exception in fact due to multiple handlers per single query
65- assertType ('mixed ' , $ this ->handle (new StringQuery ()));
111+ // HandleTrait will throw exception in fact due to multiple handle methods/handlers per single query
112+ assertType ('mixed ' , $ this ->handle (new MultiHandlesForInTheSameHandlerQuery ()));
113+ assertType ('mixed ' , $ this ->handle (new MultiHandlersForTheSameMessageQuery ()));
66114 }
67115}
0 commit comments