Minor cleanup

This commit is contained in:
Bob den Otter
2019-04-10 08:31:33 +02:00
parent 03fe08aa79
commit 6d2442004a
2 changed files with 47 additions and 49 deletions
+45 -47
View File
@@ -55,47 +55,6 @@ class Snippets
]);
}
public function getSnippet(string $name): void
{
}
public function getWidget(Environment $twig, string $name): string
{
$widget = $this->queue->where('name', $name)->first();
if ($widget) {
return $this->invoke($twig, $widget['callback']);
}
}
public function getWidgets(Environment $twig, string $target): string
{
$widgets = $this->queue->where('target', $target)->sortBy('priority');
$output = '';
foreach ($widgets as $widget) {
$output .= $this->invoke($twig, $widget['callback']);
}
return $output;
}
/**
* @param BaseWidget|string|callable $callback
*/
public function invoke(Environment $twig, $callback): string
{
if (is_string($callback)) {
return $callback;
} elseif ($callback instanceof BaseWidget) {
$callback->setTwig($twig);
return $callback->invoke();
}
return '<!-- No callback -->';
}
public function registerWidget(BaseWidget $widget): void
{
$widget->setRequest($this->request);
@@ -109,6 +68,51 @@ class Snippets
]);
}
public function getWidget(string $name, ?Environment $twig = null): string
{
$widget = $this->queue->where('name', $name)->first();
if ($widget) {
return $this->invoke($widget['callback'], $twig);
}
}
public function getWidgets(string $target, Environment $twig): string
{
$widgets = $this->queue->where('target', $target)->sortBy('priority');
$output = '';
foreach ($widgets as $widget) {
$output .= $this->invoke($widget['callback'], $twig);
}
return $output;
}
/**
* @param BaseWidget|string|callable $callback
*/
public function invoke($callback, ?Environment $twig = null): string
{
if (is_string($callback)) {
return $callback;
} elseif ($callback instanceof BaseWidget) {
if ($twig !== null) {
$callback->setTwig($twig);
}
return $callback->invoke();
}
return '<!-- No callback -->';
}
public function processQueue(Response $response): void
{
$zone = Zone::get($this->request);
$this->queueProcessor->process($response, $this->queue, $zone);
}
public function registerBoltSnippets(): void
{
$this->registerWidget(new WeatherWidget());
@@ -121,10 +125,4 @@ class Snippets
// @todo Determine if a favicon is something we want in 2019, by default
// $this->registerWidget(new FaviconWidget());
}
public function processQueue(Response $response): void
{
$zone = Zone::get($this->request);
$this->queueProcessor->process($response, $this->queue, $zone);
}
}
+2 -2
View File
@@ -40,12 +40,12 @@ class WidgetExtension extends AbstractExtension
public function getWidget(Environment $twig, string $name): string
{
return $this->snippets->getWidget($twig, $name);
return $this->snippets->getWidget($name, $twig);
}
public function getWidgets(Environment $twig, string $target): string
{
return $this->snippets->getWidgets($twig, $target);
return $this->snippets->getWidgets($target, $twig);
}
public function dummy(Environment $twig, $input = null): string