public function route(Request $request)
{
$segments = $request->getUrlSegments();
if ($segments) {
$identifier = array_shift($segments);
} else {
$identifier = '';
}
// return false to stop processing the request (because you handled it)
// return a new $result array if you want to route the request differently
$old = array('identifier' => $identifier, 'handler' => $identifier, 'segments' => $segments);
if ($this->timer) {
$this->timer->begin(['build page']);
}
ob_start();
$result = $this->hooks->trigger('route', $identifier, $old, $old);
if ($result === false) {
$output = ob_get_clean();
$response = elgg_ok_response($output);
} else {
if ($result !== $old) {
_elgg_services()->logger->warn('Use the route:rewrite hook to modify routes.');
}
if ($identifier != $result['identifier']) {
$identifier = $result['identifier'];
} else {
if ($identifier != $result['handler']) {
$identifier = $result['handler'];
}
}
$segments = $result['segments'];
$response = false;
if (isset($this->handlers[$identifier]) && is_callable($this->handlers[$identifier])) {
$function = $this->handlers[$identifier];
$response = call_user_func($function, $segments, $identifier);
}
$output = ob_get_clean();
if ($response === false) {
return headers_sent();
}
if (!$response instanceof ResponseBuilder) {
$response = elgg_ok_response($output);
}
}
if (_elgg_services()->responseFactory->getSentResponse()) {
return true;
}
_elgg_services()->responseFactory->respond($response);
return headers_sent();
}