TenantAtlas/app/Support/Badges/BadgeRenderer.php
ahmido 0b6600b926 059-unified-badges (#71)
## 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
2026-01-22 23:44:51 +00:00

44 lines
1.2 KiB
PHP

<?php
namespace App\Support\Badges;
use Closure;
final class BadgeRenderer
{
public static function label(BadgeDomain $domain): Closure
{
return static function (mixed $state, mixed ...$args) use ($domain): string {
return BadgeCatalog::spec($domain, $state)->label;
};
}
public static function color(BadgeDomain $domain): Closure
{
return static function (mixed $state, mixed ...$args) use ($domain): string {
return BadgeCatalog::spec($domain, $state)->color;
};
}
public static function icon(BadgeDomain $domain): Closure
{
return static function (mixed $state, mixed ...$args) use ($domain): ?string {
return BadgeCatalog::spec($domain, $state)->icon;
};
}
public static function iconColor(BadgeDomain $domain): Closure
{
return static function (mixed $state, mixed ...$args) use ($domain): ?string {
$spec = BadgeCatalog::spec($domain, $state);
return $spec->iconColor ?? $spec->color;
};
}
public static function spec(BadgeDomain $domain, mixed $state): BadgeSpec
{
return BadgeCatalog::spec($domain, $state);
}
}