cms/app/Support/NavigationManager.php

41 lines
995 B
PHP
Raw Permalink Normal View History

<?php
namespace App\Support;
class NavigationManager
{
protected array $items = [];
/**
* Register a navigation item.
*/
public function register(string $id, string $label, string $url, array $options = [])
{
// If it already exists, merge it.
if (isset($this->items[$id])) {
$this->items[$id] = array_merge($this->items[$id], [
'label' => $label,
'url' => $url,
], $options);
} else {
$this->items[$id] = array_merge([
'id' => $id,
'label' => $label,
'url' => $url,
'icon' => null,
'order' => 0,
'parent' => null,
], $options);
}
}
/**
* Get all registered items, sorted by order.
*/
public function getItems(): array
{
uasort($this->items, fn($a, $b) => $a['order'] <=> $b['order']);
return $this->items;
}
}