29 lines
695 B
PHP
29 lines
695 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Lucent\Schema\Sidebar;
|
||
|
|
|
||
|
|
use Lucent\Primitive\Collection;
|
||
|
|
use Lucent\Schema\Sidebar\Item\Item;
|
||
|
|
use Lucent\Schema\Sidebar\Item\LinkItem;
|
||
|
|
use Lucent\Schema\Sidebar\Item\SchemaItem;
|
||
|
|
|
||
|
|
class Section
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @param Collection<Item> $items
|
||
|
|
*/
|
||
|
|
public function __construct(
|
||
|
|
public string $label,
|
||
|
|
public Collection $items
|
||
|
|
)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function fromArray(array $data): self
|
||
|
|
{
|
||
|
|
return new self(
|
||
|
|
label: $data["label"],
|
||
|
|
items: (new Collection($data["items"]))->map(fn($itemData) => isset($itemData["schema"]) ? SchemaItem::fromArray($itemData) : LinkItem::fromArray($itemData))
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|