sidebar
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user