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>
43 lines
1.5 KiB
PHP
43 lines
1.5 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\Company;
|
|
use App\Models\FormBuilder\FormSubmission;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* RFC §3 Q9 — supplier_intake: subject is the Company associated with
|
|
* the production_request that created this submission. Throws if no
|
|
* Company subject is set (route should validate upstream).
|
|
*/
|
|
final readonly class SupplierIntakeSubjectResolver implements PurposeSubjectResolver
|
|
{
|
|
public function resolveOrProvision(FormSubmission $submission): Company
|
|
{
|
|
if ($submission->subject_type === 'company' && $submission->subject_id !== null) {
|
|
$subject = $submission->subject;
|
|
if ($subject instanceof Company) {
|
|
return $subject;
|
|
}
|
|
throw new PurposeSubjectResolutionException(
|
|
'supplier_intake',
|
|
'subject_not_found',
|
|
(string) $submission->id,
|
|
"submission claims company subject {$submission->subject_id} but record is gone",
|
|
);
|
|
}
|
|
|
|
throw new PurposeSubjectResolutionException(
|
|
'supplier_intake',
|
|
'no_production_request',
|
|
(string) $submission->id,
|
|
'supplier_intake submission has no Company subject — production_request link missing',
|
|
);
|
|
}
|
|
}
|