Handling Queries
Queries PHP
In
Ecotone
, an object may declare a number of query handler methods, by annotating them with the #[QueryHandler]
attribute. For a query handler method, the first declared parameter defines which query message object it will receive.
class OrderSummary
{
#[QueryHandler]
public function getOrders(GetOrdersQuery $query) : array
{
//return orders
}
}
To route
Message
to @QueryHandler
by name we can use routing.
In below example Message will be routed by order.getOrders
. use Ecotone\Modelling\Annotation\QueryHandler;
class OrderSummary
{
#[QueryHandler("order.getOrders")]
public function getOrders(GetOrdersQuery $query) : array
{
//return orders
}
}
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 ConversionLast modified 2yr ago