The MethodSignatureAnalyzer was rejecting command methods with void return type, causing the schedule:run command to fail validation.
73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Application\Admin\ValueObjects;
|
|
|
|
use App\Framework\Icon\Icon;
|
|
|
|
final readonly class NavigationItem
|
|
{
|
|
public function __construct(
|
|
public string $name,
|
|
public string $url,
|
|
public Icon|string|null $icon = null,
|
|
public bool $isActive = false
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Get icon as Icon object
|
|
*/
|
|
public function getIcon(): ?Icon
|
|
{
|
|
if ($this->icon === null) {
|
|
return null;
|
|
}
|
|
|
|
if ($this->icon instanceof Icon) {
|
|
return $this->icon;
|
|
}
|
|
|
|
return Icon::fromString($this->icon);
|
|
}
|
|
|
|
public static function fromArray(array $data): self
|
|
{
|
|
return new self(
|
|
name: $data['name'] ?? '',
|
|
url: $data['url'] ?? '',
|
|
icon: $data['icon'] ?? null, // Can be string or Icon
|
|
isActive: $data['is_active'] ?? false
|
|
);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
$icon = $this->getIcon();
|
|
|
|
return [
|
|
'name' => $this->name,
|
|
'url' => $this->url,
|
|
'icon' => $this->icon instanceof Icon ? $this->icon->toString() : $this->icon,
|
|
'icon_html' => $icon?->toHtml('admin-nav__icon') ?? '',
|
|
'is_active' => $this->isActive,
|
|
];
|
|
}
|
|
|
|
public function withActiveState(bool $isActive): self
|
|
{
|
|
return new self(
|
|
name: $this->name,
|
|
url: $this->url,
|
|
icon: $this->icon,
|
|
isActive: $isActive
|
|
);
|
|
}
|
|
|
|
public function isActive(string $currentPath): bool
|
|
{
|
|
return $this->url === $currentPath || str_starts_with($currentPath, $this->url);
|
|
}
|
|
}
|