## Summary - centralize all status-like badge semantics via `BadgeCatalog`/`BadgeRenderer` and new per-domain mappings plus coverage for every affected entity - replace ad-hoc badge colors in Filament tables/views with the shared catalog and add a guard test that blocks new inline semantics - stabilize restore views by avoiding `@php(...)` shorthand so Blade compiles cleanly, and document BADGE-001 in the constitution/templates ## Testing - `vendor/bin/sail php vendor/bin/pint --dirty` - `vendor/bin/sail artisan test tests/Unit/Badges tests/Feature/Guards/NoAdHocStatusBadgesTest.php` - `vendor/bin/sail artisan test tests/Feature/Monitoring/OperationsDbOnlyTest.php tests/Feature/Monitoring/OperationsTenantScopeTest.php` - `vendor/bin/sail artisan test tests/Feature/RestoreRunWizardMetadataTest.php tests/Feature/Filament/SettingsCatalogRestoreApplySettingsPatchTest.php` Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #71
62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Badges;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
final class BadgeSpec
|
|
{
|
|
/**
|
|
* @var array<int, string>
|
|
*/
|
|
private const ALLOWED_COLORS = [
|
|
'gray',
|
|
'info',
|
|
'success',
|
|
'warning',
|
|
'danger',
|
|
'primary',
|
|
];
|
|
|
|
public function __construct(
|
|
public readonly string $label,
|
|
public readonly string $color,
|
|
public readonly ?string $icon = null,
|
|
public readonly ?string $iconColor = null,
|
|
) {
|
|
if (trim($this->label) === '') {
|
|
throw new InvalidArgumentException('BadgeSpec label must be a non-empty string.');
|
|
}
|
|
|
|
if (! in_array($this->color, self::ALLOWED_COLORS, true)) {
|
|
throw new InvalidArgumentException('BadgeSpec color must be one of: '.implode(', ', self::ALLOWED_COLORS));
|
|
}
|
|
|
|
if ($this->icon !== null && trim($this->icon) === '') {
|
|
throw new InvalidArgumentException('BadgeSpec icon must be null or a non-empty string.');
|
|
}
|
|
|
|
if ($this->iconColor !== null && ! in_array($this->iconColor, self::ALLOWED_COLORS, true)) {
|
|
throw new InvalidArgumentException('BadgeSpec iconColor must be null or one of: '.implode(', ', self::ALLOWED_COLORS));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function allowedColors(): array
|
|
{
|
|
return self::ALLOWED_COLORS;
|
|
}
|
|
|
|
public static function unknown(): self
|
|
{
|
|
return new self(
|
|
label: 'Unknown',
|
|
color: 'gray',
|
|
icon: 'heroicon-m-question-mark-circle',
|
|
iconColor: 'gray',
|
|
);
|
|
}
|
|
}
|