-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
From @oqq on September 19, 2016 9:5
Hi!
Currently i see no clean way to provide some context metadata to response strategy.
As example it would be handy to use the request or the query that was dispatched to the query bus, to get the provided metadata.
final class HtmlResponseStrategy implements ResponseStrategy
{
/** @var TemplateRendererInterface */
private $templateRenderer;
/**
* @param TemplateRendererInterface $templateRenderer
*/
public function __construct(TemplateRendererInterface $templateRenderer)
{
$this->templateRenderer = $templateRenderer;
}
/**
* @inheritDoc
*/
public function fromPromise(Promise $promise, array $context)
{
/** @var ServerRequestInterface $request */
$request = $context['request'];
$template = $request->getAttribute('template');
$data = null;
$promise->done(function($result) use (&$data) {
$data = $result;
});
return new HtmlResponse(
$this->templateRenderer->render($template),
['data' => $data]
);
}
}Without $context i have create a abstract factory to inject the template name in the strategy, which would ends in a config nighmare.
Or am i missing a already existing solution for that issue?
Some hints would to be welcome.
Thanks!
Copied from original issue: prooph/psr7-middleware#14
Metadata
Metadata
Assignees
Labels
No labels