I use zend-expressive and i would like to pass data from one middelware to another. e.g. in config/routes.php I've
[
'name' => 'v1.item.list',
'path' => '/item',
'allowed_methods' => ['GET'],
'middleware' => [
Api\V1\Action\ItemListAction::class,
Application\Middleware\JsonRenderMiddleware::class
]
],
in Api\V1\Action\ItemListAction I'm preparin some data from databases and I like to pass $itemsList to another middelware
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
$parameters = new ListParameters($request->getQueryParams());
$itemsList = $this->commandBus->handle(new ItemListCommand($parameters));
return $next($request, $response);
}
and in Application\Middleware\JsonRenderMiddleware I would like get $itemsList and return in json format:
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
return new JsonResponse($itemsList);
}
How is the best way? Only commandBus or is other solution in this framework?