@@ -221,20 +221,20 @@ class QueryBus
221
221
222
222
public function dispatch(object $query): mixed
223
223
{
224
- return $this->handle($query); // Return type will be inferred
224
+ return $this->handle($query); // Return type will be inferred in calling code as query result
225
225
}
226
226
227
227
// Multiple methods per class example
228
228
public function execute(object $message): mixed
229
229
{
230
- return $this->handle($message);
230
+ return $this->handle($message); // Return type will be inferred in calling code as query result
231
231
}
232
232
}
233
233
234
234
// Interface-based configuration example
235
235
interface QueryBusInterface
236
236
{
237
- public function dispatch(object $query): mixed;
237
+ public function dispatch(object $query): mixed; // Return type will be inferred in calling code as query result
238
238
}
239
239
240
240
class QueryBusWithInterface implements QueryBusInterface
@@ -252,12 +252,13 @@ class QueryBusWithInterface implements QueryBusInterface
252
252
}
253
253
}
254
254
255
- // Usage examples with proper type inference
255
+ // Examples of use with proper type inference
256
256
$query = new GetProductQuery($productId);
257
257
$queryBus = new QueryBus($messageBus);
258
258
$queryBusWithInterface = new QueryBusWithInterface($messageBus);
259
259
260
260
$product = $queryBus->dispatch($query); // Returns: Product
261
261
$product2 = $queryBus->execute($query); // Returns: Product
262
262
$product3 = $queryBusWithInterface->dispatch($query); // Returns: Product
263
+ // Without the feature all above query bus results would be default 'mixed'.
263
264
` ` `
0 commit comments