@@ -16,22 +16,23 @@ public function __invoke(RegularQuery $query): RegularQueryResult
16
16
}
17
17
}
18
18
19
+ class BooleanQuery {}
19
20
class StringQuery {}
20
21
class IntQuery {}
21
22
class FloatQuery {}
22
23
class MultiQueryHandler implements MessageSubscriberInterface
23
24
{
24
25
public static function getHandledMessages (): iterable
25
26
{
26
- yield StringQuery ::class;
27
+ yield BooleanQuery ::class;
27
28
yield IntQuery::class => ['method ' => 'handleInt ' ];
28
29
yield FloatQuery::class => ['method ' => 'handleFloat ' ];
29
30
yield StringQuery::class => ['method ' => 'handleString ' ];
30
31
}
31
32
32
- public function __invoke (StringQuery $ query ): string
33
+ public function __invoke (BooleanQuery $ query ): bool
33
34
{
34
- return ' string result ' ;
35
+ return true ;
35
36
}
36
37
37
38
public function handleInt (IntQuery $ query ): int
@@ -52,16 +53,63 @@ public function handleString(StringQuery $query): string
52
53
// todo add handle method with union return type?
53
54
}
54
55
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
+
55
97
class HandleTraitClass {
56
98
use HandleTrait;
57
99
58
100
public function __invoke ()
59
101
{
60
102
assertType (RegularQueryResult::class, $ this ->handle (new RegularQuery ()));
103
+
104
+ assertType ('bool ' , $ this ->handle (new BooleanQuery ()));
61
105
assertType ('int ' , $ this ->handle (new IntQuery ()));
62
106
assertType ('float ' , $ this ->handle (new FloatQuery ()));
107
+ assertType ('string ' , $ this ->handle (new StringQuery ()));
108
+
109
+ assertType (TaggedResult::class, $ this ->handle (new TaggedQuery ()));
63
110
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 ()));
66
114
}
67
115
}
0 commit comments