Elgg  Version 3.0
ActionMiddleware.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
12 
21  public function __invoke(\Elgg\Request $request) {
22  $route = $request->getRoute();
23  list($prefix, $action) = explode(':', $route, 2);
24 
25  // deprecated action handling
26  $deprecated_msg = "'action', '$action' hook has been deprecated.
27  Please use route middleware or 'action:validate','$action' hook";
28  ob_start();
29  $result = $request->elgg()->hooks->triggerDeprecated('action', $action, null, true, $deprecated_msg, '3.0');
30  $output = ob_get_clean();
31 
32  // this allows you to return a ok or error response in the hook
33  if ($result instanceof ResponseBuilder) {
34  return $result;
35  }
36 
37  // To quietly cancel the file, return a falsey value in the "action" hook.
38  if (!$result) {
39  return elgg_ok_response($output);
40  }
41 
42  $hook_params = ['request' => $request];
43  $result = $request->elgg()->hooks->trigger('action:validate', $action, $hook_params, true);
44  if ($result === false) {
45  throw new ValidationException(elgg_echo('ValidationException'));
46  }
47 
48  // set the maximum execution time for actions
49  $action_timeout = $request->elgg()->config->action_time_limit;
50  if (isset($action_timeout)) {
51  set_time_limit($action_timeout);
52  }
53 
54  return null;
55  }
56 
57 }
HTTP response builder interface.
$action
Definition: full.php:111
__invoke(\Elgg\Request $request)
Pre-action logic.
$request
Page handler for autocomplete endpoint.
Definition: livesearch.php:9
catch(LoginException $e) if($request->isXhr()) $output
Definition: login.php:56
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
Action validation exception.
Some logic implemented before action is executed.
Configuration exception.
elgg_ok_response($content= '', $message= '', $forward_url=null, $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
Request container.
Definition: Request.php:13