1: <?php
2:
3: namespace LaravelUi5\Core\Ui5\Contracts;
4:
5: use LaravelUi5\Core\Contracts\ParameterResolverInterface;
6: use LaravelUi5\Core\Enums\HttpMethod;
7: use LaravelUi5\Core\Ui5\Capabilities\ActionHandlerInterface;
8:
9: /**
10: * Contract for UI5 Actions.
11: *
12: * A UI5 Action represents a state-changing operation that can be invoked
13: * from a UI5 client via the generic API dispatcher. Typical examples are:
14: * - "toggle-lock" on a user
15: * - "approve-invoice"
16: * - "discard-draft"
17: *
18: * Characteristics:
19: * - Actions are always *mutating* operations (never pure reads).
20: * - Therefore, they must only be exposed as *mutating endpoints*, e.g. `POST`, `PATCH`, etc.
21: * - Route parameters (IDs, slugs) are declared on the ActionHandler and resolved
22: * via {@see ParameterResolverInterface}.
23: * - Body parameters (form data, payloads) are validated *inside the
24: * ActionHandler*, following Laravel best practices.
25: *
26: * Responsibilities:
27: * - Provide the {@see ActionHandlerInterface} that handles the logic.
28: */
29: interface Ui5ActionInterface extends Ui5ArtifactInterface
30: {
31: /**
32: * Returns the HTTP method for calling this Action.
33: *
34: * Valid values:
35: * - POST, verb create
36: * - PATCH, verb update
37: * - DELETE, verb delete.
38: *
39: * @return HttpMethod
40: */
41: public function getMethod(): HttpMethod;
42:
43: /**
44: * Returns the ActionHandler responsible for executing this Action.
45: *
46: * Handlers encapsulate the runtime logic and must return a structured
47: * result array, e.g.:
48: *
49: * ```php
50: * ['status' => 'success', 'message' => 'Mailbox cleared']
51: * ```
52: *
53: * @return ActionHandlerInterface
54: */
55: public function getHandler(): ActionHandlerInterface;
56: }
57: