Handling Queries
Queries PHP

Writing Query Handler

In Ecotone, an object may declare a number of query handler methods, by annotating them with the #[QueryHandler] attribute.

Class Routing

For a query handler method, the first declared parameter defines which query message object it will receive.
1
class OrderSummary
2
{
3
#[QueryHandler]
4
public function getOrders(GetOrdersQuery $query) : array
5
{
6
//return orders
7
}
8
}
Copied!
How to publish queries, you may see in Dispatching Queries section

Name Routing

To route Message to @QueryHandler by name we can use routing. In below example Message will be routed by order.getOrders.
1
use Ecotone\Modelling\Annotation\QueryHandler;
2
3
class OrderSummary
4
{
5
#[QueryHandler("order.getOrders")]
6
public function getOrders(GetOrdersQuery $query) : array
7
{
8
//return orders
9
}
10
}
Copied!
Query can be anything class/scalar/array as long as Ecotone does know how to convert it if there is a need. Read more in Method Invocation and Conversion

Last modified 8mo ago