67 if ($this->response->getSentResponse()) {
73 return headers_sent();
85 $response = $this->prepareResponse($request);
91 if ($request->getFirstUrlSegment() ==
'action') {
92 if (
$response->getForwardURL() === null) {
115 $parameters = $this->matcher->match(
$path);
118 unset($parameters[
'_resource']);
121 unset($parameters[
'_handler']);
124 unset($parameters[
'_controller']);
127 unset($parameters[
'_file']);
129 $deprecated =
elgg_extract(
'_deprecated', $parameters,
'');
130 unset($parameters[
'_deprecated']);
132 $middleware =
elgg_extract(
'_middleware', $parameters, []);
133 unset($parameters[
'_middleware']);
135 $required_plugins = (array)
elgg_extract(
'_required_plugins', $parameters, []);
136 unset($parameters[
'_required_plugins']);
138 unset($parameters[
'_detect_page_owner']);
141 if (!$this->plugins->isActive($plugin_id)) {
146 $route = $this->routes->get($parameters[
'_route']);
147 $route->setMatchedParameters($parameters);
148 $request->setRoute($route);
150 $envelope = new \Elgg\Request(
elgg(), $request);
151 $parameters[
'request'] = $envelope;
153 if (!empty($deprecated)) {
157 foreach ($middleware as $callable) {
158 $result = $this->handlers->call($callable, $envelope, null);
165 return $this->getResponseFromHandler(
$handler, $envelope);
167 $result = $this->handlers->call($controller, $envelope, null);
172 return $this->getResponseFromFile($file, $envelope);
177 }
catch (ResourceNotFoundException $ex) {
179 }
catch (MethodNotAllowedException $ex) {
199 $identifier = array_shift($segments) ?:
'';
204 }
catch (\Exception $ex) {
230 if (!is_file($file)) {
238 }
catch (\Exception $ex) {
269 'identifier' => $identifier,
272 $new = $this->events->triggerResults(
'route:rewrite', $identifier, $old, $old);
277 if (!isset($new[
'identifier']) ||
278 !isset($new[
'segments']) ||
279 !is_string($new[
'identifier']) ||
280 !is_array($new[
'segments'])
282 throw new RuntimeException(
'rewrite_path handler returned invalid route data.');
287 array_unshift(
$segments, $new[
'identifier']);
289 return $request->setUrlSegments(
$segments);
trait Profilable
Make an object accept a timer.
HTTP response builder interface.
route(HttpRequest $request)
Routes the request to a registered page handler.
Exception thrown if an error which can only be found on runtime occurs.
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
const ELGG_HTTP_NOT_IMPLEMENTED
Helpers for providing callable-based APIs.
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.
prepareResponse(HttpRequest $request)
Prepare response.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Delegates requests to controllers based on the registered configuration.
elgg_view_resource(string $name, array $vars=[])
Render a resource view.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
$plugin_id
Remove all user and plugin settings from the give plugin ID.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
getResponseFromHandler($handler,\Elgg\Request $request)
Get response from handler function.
Thrown when page is not accessible.
const REFERRER
Used in calls to forward() to specify the browser should be redirected to the referring page...
allowRewrite(HttpRequest $request)
Filter a request through the 'route:rewrite' event.
Thrown when request is malformatted.
beginTimer(array $keys)
Start the timer (when enabled)
Persistent, installation-wide key-value storage.
getResponse(HttpRequest $request)
Build a response.
__construct(protected EventsService $events, protected RouteCollection $routes, protected UrlMatcher $matcher, protected HandlersService $handlers, protected ResponseFactory $response, protected Plugins $plugins)
Constructor.
getResponseFromFile(string $file,\Elgg\Request $request)
Get response from file.