Tweak ContentInterface so that callables can be used as well

This commit is contained in:
Franz Liedke 2018-10-21 20:41:10 +02:00
parent 52d7cd0461
commit d335ce8eef
9 changed files with 10 additions and 10 deletions

View File

@ -52,7 +52,7 @@ class AdminPayload implements ContentInterface
$this->events = $events;
}
public function populate(HtmlDocument $document, Request $request)
public function __invoke(HtmlDocument $document, Request $request)
{
$settings = $this->settings->all();

View File

@ -20,7 +20,7 @@ class AssertRegistered implements ContentInterface
{
use AssertPermissionTrait;
public function populate(HtmlDocument $document, Request $request)
public function __invoke(HtmlDocument $document, Request $request)
{
$this->assertRegistered($request->getAttribute('actor'));
}

View File

@ -49,7 +49,7 @@ class Discussion implements ContentInterface
$this->view = $view;
}
public function populate(HtmlDocument $document, Request $request)
public function __invoke(HtmlDocument $document, Request $request)
{
$queryParams = $request->getQueryParams();
$page = max(1, array_get($queryParams, 'page'));

View File

@ -44,7 +44,7 @@ class Index implements ContentInterface
/**
* {@inheritdoc}
*/
public function populate(HtmlDocument $document, Request $request)
public function __invoke(HtmlDocument $document, Request $request)
{
$queryParams = $request->getQueryParams();

View File

@ -20,5 +20,5 @@ interface ContentInterface
* @param HtmlDocument $document
* @param Request $request
*/
public function populate(HtmlDocument $document, Request $request);
public function __invoke(HtmlDocument $document, Request $request);
}

View File

@ -41,7 +41,7 @@ class CorePayload implements ContentInterface
$this->api = $api;
}
public function populate(HtmlDocument $document, Request $request)
public function __invoke(HtmlDocument $document, Request $request)
{
$document->payload = array_merge(
$document->payload,

View File

@ -29,7 +29,7 @@ class Layout implements ContentInterface
$this->layoutView = $layoutView;
}
public function populate(HtmlDocument $document, Request $request)
public function __invoke(HtmlDocument $document, Request $request)
{
$document->layoutView = $this->layoutView;
}

View File

@ -16,7 +16,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
class Meta implements ContentInterface
{
public function populate(HtmlDocument $document, Request $request)
public function __invoke(HtmlDocument $document, Request $request)
{
$document->meta = array_merge($document->meta, $this->buildMeta($document));
$document->head = array_merge($document->head, $this->buildHead($document));

View File

@ -61,7 +61,7 @@ class HtmlDocumentFactory
}
/**
* @param ContentInterface $content
* @param ContentInterface|callable $content
*/
public function add($content)
{
@ -116,7 +116,7 @@ class HtmlDocumentFactory
protected function populate(HtmlDocument $view, Request $request)
{
foreach ($this->content as $content) {
$content->populate($view, $request);
$content($view, $request);
}
}