Files
alrahma_sunday_school/app/Services/SchoolYearWriteGuard.php
T
root feb1b29a32
Tests / PHPUnit (push) Failing after 1m19s
apply the school year concept
2026-07-14 00:59:00 -04:00

26 lines
652 B
PHP

<?php
namespace App\Services;
use App\Exceptions\SchoolYear\SchoolYearWriteConflictException;
use App\Support\SchoolYear\SchoolYearContext;
final class SchoolYearWriteGuard
{
public function assertWritable(
SchoolYearContext $context,
bool $allowDraftForAdmin = false,
bool $isAdmin = false
): void {
if (strtolower($context->status()) === 'active') {
return;
}
if (strtolower($context->status()) === 'draft' && $allowDraftForAdmin && $isAdmin) {
return;
}
throw new SchoolYearWriteConflictException('The selected school year is read-only.');
}
}