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