updateController = $updateController; } public function handle(Request $request): Response { $data = $request->getParams(); $workflow = $this->updateController->updateWorkflow(intval($request->getParam('id')), $data); return new Response($this->buildWorkflow($workflow)); } public static function getRequestSchema(): array { $step = Builder::object([ 'id' => Builder::string()->required(), 'type' => Builder::string()->required(), 'key' => Builder::string()->required(), 'args' => Builder::object(), 'next_step_id' => Builder::string()->nullable(), ]); return [ 'id' => Builder::integer()->required(), 'name' => Builder::string()->minLength(1), 'status' => Builder::string(), 'steps' => Builder::object()->additionalProperties($step), ]; } protected function buildWorkflow(Workflow $workflow): array { return [ 'id' => $workflow->getId(), 'name' => $workflow->getName(), 'status' => $workflow->getStatus(), 'created_at' => $workflow->getCreatedAt()->format(DateTimeImmutable::W3C), 'updated_at' => $workflow->getUpdatedAt()->format(DateTimeImmutable::W3C), 'activated_at' => $workflow->getActivatedAt() ? $workflow->getActivatedAt()->format(DateTimeImmutable::W3C) : null, 'author' => [ 'id' => $workflow->getAuthor()->ID, 'name' => $workflow->getAuthor()->display_name, ], 'steps' => array_map(function (Step $step) { return [ 'id' => $step->getId(), 'type' => $step->getType(), 'key' => $step->getKey(), 'next_step_id' => $step->getNextStepId(), 'args' => $step->getArgs() ?: new stdClass(), ]; }, $workflow->getSteps()), ]; } }