Files
lucent-laravel/src/Schema/Sidebar/SidebarService.php
T

58 lines
1.3 KiB
PHP
Raw Normal View History

2024-03-19 23:05:57 +02:00
<?php
namespace Lucent\Schema\Sidebar;
use Lucent\Channel\Channel;
use PhpOption\Option;
use Symfony\Component\Yaml\Yaml;
class SidebarService
{
public function __construct()
{
}
/**
* @param Channel $channel
* @param array<string> $readableSchemas
* @param string $currentSchema
* @return string
*/
public function render(Channel $channel, array $readableSchemas, string $currentSchema): string
{
$schemas = $channel->schemas->whereIn("name", $readableSchemas);
return view('lucent::sidebar.sidebar', [
'sidebar' => $this->fromConfig(),
'schemas' => $schemas,
'channel' => $channel,
'currentSchema' => $currentSchema,
'lucentUrl' => $channel->lucentUrl,
])->render();
}
/**
* @return Option<Sidebar>
*/
private function fromConfig(): Option
{
$configPath = base_path(config("lucent.sidebar_path")) . "/sidebar.yaml";
if (!file_exists($configPath)) {
return none();
}
$yaml = Yaml::parse(file_get_contents($configPath));
if (empty($yaml)) {
return none();
}
$sidebar = Sidebar::fromArray($yaml);
return some($sidebar);
}
}