schneespur/release/schneespur-1.0.2/app/Services/Extension/NavigationRegistry.php
Michael 7288b93500 Release v1.0.2: diagnostic infrastructure core
Add neutral diagnostic framework for future reporting modules:
- DiagnosticReporterInterface, Registry, Manager, PayloadSanitizer
- Laravel exception hook in bootstrap/app.php
- Module permission declarations (requires_permissions in module.json)
- Core diagnostic report points (module boot/install/update failures)
- Module documentation update (moduldoku.md)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 16:54:11 +00:00

78 lines
2.1 KiB
PHP

<?php
namespace App\Services\Extension;
use Illuminate\Support\Facades\Log;
class NavigationRegistry extends ExtensionRegistry
{
protected array $groups = [];
public function addGroup(string $key, string $label, int $order = 100): void
{
$this->groups[$key] = ['key' => $key, 'label' => $label, 'order' => $order];
}
public function getGroups(): array
{
$groups = $this->groups;
usort($groups, fn (array $a, array $b) => $a['order'] <=> $b['order']);
return $groups;
}
public function addItem(
string $group,
string $slug,
string $label,
string $route,
string $icon,
int $order = 100,
?string $permission = null,
?string $routeCheck = null,
?string $activePattern = null,
?string $badge = null,
): void {
if ($this->has($slug)) {
Log::warning("NavigationRegistry: overwriting nav item '{$slug}'");
}
$this->items[$slug] = [
'group' => $group,
'slug' => $slug,
'label' => $label,
'route' => $route,
'icon' => $icon,
'order' => $order,
'permission' => $permission,
'route_check' => $routeCheck,
'active_pattern' => $activePattern ?? $route,
'badge' => $badge,
];
}
/**
* @return array<string, array<int, array{slug: string, label: string, route: string, icon: string, order: int, permission: string|null}>>
*/
public function getItems(?string $userPermission = null): array
{
$items = $this->items;
if ($userPermission !== null) {
$items = array_filter($items, function (array $item) use ($userPermission) {
return $item['permission'] === null || $item['permission'] === $userPermission;
});
}
$grouped = [];
foreach ($items as $item) {
$grouped[$item['group']][] = $item;
}
foreach ($grouped as &$groupItems) {
usort($groupItems, fn (array $a, array $b) => $a['order'] <=> $b['order']);
}
return $grouped;
}
}