29 lines
1.1 KiB
PHP
29 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Opportunity;
|
|
use App\Models\User;
|
|
|
|
/** Observe technical failures without changing the approved transition engine. */
|
|
final class OpportunityWorkflowExecution
|
|
{
|
|
public function __construct(private OpportunityProfileWorkflow $workflow, private OpportunityTechnicalExecution $execution) {}
|
|
|
|
/** @param array<string,mixed> $input */
|
|
public function transition(User $actor, int $id, array $input): Opportunity
|
|
{
|
|
$action = $input['action'] ?? null;
|
|
if (! in_array($action, ['submit', 'publish'], true)) {
|
|
return $this->workflow->transition($actor, $id, $input);
|
|
}
|
|
$record = Opportunity::withTrashed()->findOrFail($id);
|
|
app(PortalProfileAccess::class)->authorize($actor, 'view', $record);
|
|
if (! in_array($action, $this->workflow->actions($actor, $record), true)) {
|
|
return $this->workflow->transition($actor, $id, $input);
|
|
}
|
|
|
|
return $this->execution->run($actor, $record, $action, $input, fn () => $this->workflow->transition($actor, $id, $input));
|
|
}
|
|
}
|