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