1: <?php
2:
3: namespace LaravelUi5\Core\Controllers;
4:
5: use Illuminate\Http\JsonResponse;
6: use LaravelUi5\Core\Contracts\Ui5Context;
7: use LaravelUi5\Core\Services\ExecutableHandler;
8: use LaravelUi5\Core\Ui5\Contracts\Ui5ActionInterface;
9:
10: /**
11: * Controller responsible for dispatching UI5 Actions.
12: *
13: * Flow:
14: * - Resolves the Action artifact from the Ui5Context/registry.
15: * - Obtains the ActionHandler behind the Action.
16: * - Injects parameters and settings if supported.
17: * - Executes the handler and returns the result (JSON by default).
18: *
19: * Notes:
20: * - Actions are state-changing operations (POST/PATCH/DELETE).
21: * - Unlike Resources, they may not be idempotent.
22: */
23: class ActionDispatchController
24: {
25: public function __invoke(Ui5Context $context, ExecutableHandler $handler): JsonResponse
26: {
27: /** @var Ui5ActionInterface $action */
28: $action = $context->artifact;
29:
30: $result = $handler->run($action->getHandler());
31:
32: return response()->json($result);
33: }
34: }
35: