thrownew\InvalidArgumentException("You need to be administrator in order to register new product");
Our Command Handler method declaration is built from three parameters.
Ecotone does resolve parameters based on given attribute types.
Payload - Does inject payload of the message. In our case it will be the command itself
Headers - Does inject all headers as array.
Reference- Does inject service from Dependency Container. If referenceNamewhich is name of the service in the container is not given, then it will take the class name as default.
Ecotone, if parameter converters are not passed provides default converters.
First parameter is always Payload.
The second parameter, if is array then Headers converter is taken
If class type hint is provided for parameter, then Reference converter is picked
Otherwise, if no default converter can be applied exception will be thrown with information about missing parameter.
Our Command Handler can benefit from default converters, so we don't need to use any additional configuration.
The message may contains of special header contentTypewhich describes content type of Message as media type. Based on this information, if payload of message is not compatible with parameter's type hint, Ecotone do the conversion.
Thanks to conversion on the level of endpoint, Ecotone does not expect running Command Bus with specific class instance. It may receive anything xml, json etc as long as Converter for specific Media Type is registered in the system.
Expression does use of great feature of Symfony, called Expression Language. If you have not came across expression language yet, take few minutes to read about it.
Payload(expression:"payload * 2")
There are three types of variables available within expression.
payload - which is just payload of currently handled Message
headers - contains of all headers available within Message
reference - which allow for retrieving service from Dependency Container and calling a method on it. The result of the expression will be passed to parameter after optional conversion.