Files
crewli/api/app/FormBuilder/Purposes/Resolvers/ArtistAdvanceSubjectResolver.php
bert.hausmans 16a9265430 feat(form-builder): add PurposeSubjectResolver per purpose (WS-6)
Parallel interface to PurposeGuardProvider for runtime subject
resolution. Seven concrete resolvers, one per v1.0 purpose. Wired
through purposes.php via subject_resolver_class key.

EventRegistration uses PersonProvisioner (may create). Other purposes
resolve from existing context (portal token, production request, auth).
IncidentReport is the only purpose allowed to return null (anonymous-
allowed configurations); the others return concrete model types
(narrowed via PHP covariance) for caller convenience.

Refs: RFC-WS-6.md §3 (Q9)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 12:57:21 +02:00

47 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\FormBuilder\Purposes\Resolvers;
use App\Exceptions\FormBuilder\PurposeSubjectResolutionException;
use App\FormBuilder\Purposes\PurposeSubjectResolver;
use App\Models\FormBuilder\FormSubmission;
use Illuminate\Database\Eloquent\Model;
/**
* RFC §3 Q9 — artist_advance: subject is the Artist resolved via the
* portal token that opened the submission. Throws if no token.
*
* The Artist model is not yet implemented (BACKLOG: ARCH-09); this
* resolver short-circuits when the submission already carries
* subject_type='artist' (set by the portal route) — the typical path.
* If subject is absent, throw — the route should never have allowed
* the submission through without a portal token.
*/
final readonly class ArtistAdvanceSubjectResolver implements PurposeSubjectResolver
{
public function resolveOrProvision(FormSubmission $submission): Model
{
if ($submission->subject_type === 'artist' && $submission->subject_id !== null) {
$subject = $submission->subject;
if ($subject !== null) {
return $subject;
}
throw new PurposeSubjectResolutionException(
'artist_advance',
'subject_not_found',
(string) $submission->id,
"submission claims artist subject {$submission->subject_id} but record is gone",
);
}
throw new PurposeSubjectResolutionException(
'artist_advance',
'no_portal_token',
(string) $submission->id,
'artist_advance submission has no resolved Artist; portal token missing',
);
}
}