adrema/app/Dashboard/DashboardFactory.php

50 lines
999 B
PHP
Raw Permalink Normal View History

2022-11-17 02:15:29 +01:00
<?php
2023-04-29 21:30:41 +02:00
namespace App\Dashboard;
2022-11-17 02:15:29 +01:00
2023-04-29 21:30:41 +02:00
use App\Dashboard\Blocks\Block;
2022-11-17 02:15:29 +01:00
use App\Efz\EfzPendingBlock;
2023-12-17 01:49:12 +01:00
use App\Invoice\MemberPaymentBlock;
2022-11-17 20:43:51 +01:00
use App\Member\PsPendingBlock;
2022-11-17 02:15:29 +01:00
use App\Membership\AgeGroupCountBlock;
use App\Membership\TestersBlock;
class DashboardFactory
{
/**
* @var array<int, class-string<Block>>
*/
private array $blocks = [
AgeGroupCountBlock::class,
MemberPaymentBlock::class,
TestersBlock::class,
EfzPendingBlock::class,
2022-11-17 20:43:51 +01:00
PsPendingBlock::class,
2022-11-17 02:15:29 +01:00
];
/**
* @return array<array-key, mixed>
*/
public function render(): array
{
return collect($this->blocks)->map(fn ($block): array => app($block)->render())->toArray();
}
/**
* @param class-string<Block> $block
*/
public function register(string $block): self
{
$this->blocks[] = $block;
return $this;
}
public function purge(): self
{
$this->blocks = [];
return $this;
}
}