15 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
16 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
65 if ($this->response->getSentResponse()) {
71 return headers_sent();
89 if (
$request->getFirstUrlSegment() ==
'action') {
90 if (
$response->getForwardURL() ===
null) {
113 $parameters = $this->matcher->match(
$path);
116 unset($parameters[
'_resource']);
119 unset($parameters[
'_handler']);
122 unset($parameters[
'_controller']);
125 unset($parameters[
'_file']);
127 $deprecated =
elgg_extract(
'_deprecated', $parameters,
'');
128 unset($parameters[
'_deprecated']);
130 $middleware =
elgg_extract(
'_middleware', $parameters, []);
131 unset($parameters[
'_middleware']);
133 unset($parameters[
'_detect_page_owner']);
134 unset($parameters[
'_use_logged_in']);
136 $route = $this->routes->get($parameters[
'_route']);
137 $route->setMatchedParameters($parameters);
141 $parameters[
'request'] = $envelope;
143 if (!empty($deprecated)) {
148 array_unshift($middleware, MaintenanceGatekeeper::class);
150 foreach ($middleware as $callable) {
151 $result = $this->handlers->call($callable, $envelope,
null);
158 return $this->getResponseFromHandler(
$handler, $envelope);
160 $result = $this->handlers->call($controller, $envelope,
null);
165 return $this->getResponseFromFile($file, $envelope);
170 }
catch (ResourceNotFoundException $ex) {
172 $result = $this->handlers->call(MaintenanceGatekeeper::class, $envelope,
null);
178 }
catch (MethodNotAllowedException $ex) {
198 $identifier = array_shift(
$segments) ?:
'';
203 }
catch (\Exception $ex) {
229 if (!is_file($file)) {
237 }
catch (\Exception $ex) {
268 'identifier' => $identifier,
271 $new = $this->events->triggerResults(
'route:rewrite', $identifier, $old, $old);
276 if (!isset($new[
'identifier']) ||
277 !isset($new[
'segments']) ||
278 !is_string($new[
'identifier']) ||
279 !is_array($new[
'segments'])
281 throw new RuntimeException(
'rewrite_path handler returned invalid route data.');
286 array_unshift(
$segments, $new[
'identifier']);
catch(AuthenticationException|LoginException $e) if(elgg_is_xhr()) $output
Thrown when request is malformatted.
Thrown when page is not accessible.
Exception thrown if an error which can only be found on runtime occurs.
Helpers for providing callable-based APIs.
Protects a route if site is in maintenance mode.
Delegates requests to controllers based on the registered configuration.
prepareResponse(HttpRequest $request)
Prepare response.
getResponseFromHandler($handler, \Elgg\Request $request)
Get response from handler function.
getResponseFromFile(string $file, \Elgg\Request $request)
Get response from file.
route(HttpRequest $request)
Routes the request to a registered page handler.
getResponse(HttpRequest $request)
Build a response.
__construct(protected EventsService $events, protected RouteCollection $routes, protected UrlMatcher $matcher, protected HandlersService $handlers, protected ResponseFactory $response)
Constructor.
allowRewrite(HttpRequest $request)
Filter a request through the 'route:rewrite' event.
const ELGG_HTTP_NOT_IMPLEMENTED
const REFERRER
Used in calls to forward() to specify the browser should be redirected to the referring page.
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
elgg()
Bootstrapping and helper procedural code available for use in Elgg core and plugins.
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
HTTP response builder interface.
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
elgg_view_resource(string $name, array $vars=[])
Render a resource view.
trait Profilable
Make an object accept a timer.
beginTimer(array $keys)
Start the timer (when enabled)
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.