60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Lucent\Svelte;
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
use Illuminate\Contracts\View\View;
|
|
use Lucent\Account\AccountService;
|
|
use Lucent\Account\AuthService;
|
|
use Lucent\Channel\ChannelService;
|
|
|
|
class Svelte
|
|
{
|
|
public function __construct(
|
|
public ChannelService $channelService,
|
|
public AccountService $accountService,
|
|
public AuthService $authService,
|
|
) {}
|
|
|
|
function render(
|
|
string $layout,
|
|
string $view,
|
|
string $title = "",
|
|
mixed $data = [],
|
|
): View|Factory {
|
|
$context = [];
|
|
$context["user"] = $this->authService->isLoggedIn()
|
|
? $this->authService->getCurrentUser()
|
|
: null;
|
|
$context["view"] = $view;
|
|
$context["layout"] = $layout;
|
|
$context["title"] = $title;
|
|
$context["data"] = $data;
|
|
$context["channel"] = $this->channelService->channel;
|
|
$context[
|
|
"readableSchemas"
|
|
] = $this->accountService->currentReadableSchemas();
|
|
$json = json_encode($context);
|
|
|
|
$divTag = sprintf(
|
|
'<div class="lucent-component" data-layout="%s"></div>',
|
|
$layout,
|
|
);
|
|
$jsonTag = sprintf(
|
|
'<script type="application/json" id="json-%s">%s</script>',
|
|
$layout,
|
|
$json,
|
|
);
|
|
|
|
$svelte = $divTag . $jsonTag;
|
|
|
|
return view("lucent::svelte", [
|
|
"svelte" => $svelte,
|
|
"view" => $view,
|
|
"data" => $data,
|
|
"title" => $title,
|
|
"channel" => $this->channelService->channel,
|
|
]);
|
|
}
|
|
}
|