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>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?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',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user