Elgg  Version 6.2
GenericAction.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Controllers;
4 
7 
13 abstract class GenericAction {
14 
15  protected \Elgg\Request $request;
16 
24  final public function __invoke(\Elgg\Request $request): \Elgg\Http\Response {
25  $this->request = $request;
26 
27  try {
28  $this->sanitize();
29  $this->validate();
30  $this->executeBefore();
31  $this->execute();
32  $this->executeAfter();
33 
34  return $this->success();
35  } catch (\Elgg\Exceptions\HttpException $e) {
36  return $this->error($e->getMessage());
37  }
38  }
39 
45  protected function sanitize(): void {
46  }
47 
53  protected function validate(): void {
54  }
55 
61  protected function executeBefore(): void {
62  }
63 
69  protected function execute(): void {
70  }
71 
77  protected function executeAfter(): void {
78  }
79 
85  protected function success(): OkResponse {
86  return elgg_ok_response();
87  }
88 
96  protected function error(string $message): ErrorResponse {
97  return elgg_error_response($message);
98  }
99 }
executeBefore()
Preparation before executing the action.
Error response builder.
success()
Will be used when an action is successfully finished.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
error(string $message)
Will be used when something wrong happened during the handling of the action.
__invoke(\Elgg\Request $request)
Invoke the action steps.
elgg_ok_response($content= '', string|array $message= '',?string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
execute()
Main part of the action.
executeAfter()
Action part after the main execution.
Generic HTTP exception.
Generic action controller.
Request container.
Definition: Request.php:12
sanitize()
Sanitizes input for the action.
OK response builder.
Definition: OkResponse.php:8
validate()
Validates the action.