mirror of
https://github.com/jbcr/core.git
synced 2026-04-23 08:38:04 +02:00
Minor cleanup
This commit is contained in:
+45
-47
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user