Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Horde\Http\RequestFactory;
use Horde\Http\StreamFactory;
use Horde\Http\Uri;
use Horde\Http\UriFactory;
use Horde\Http\Server\RequestBuilder;
use Horde\Http\Server\ResponseWriterWeb;
Expand All @@ -36,14 +37,19 @@
/*
* Build PSR-7 request and extract the URL path to match against routes.
* Strip the Jonah webroot prefix so the mapper sees paths relative to the app.
*
* Note: the configured webroot may be either a bare path ("/apps/jonah") or a
* fully qualified URL ("https://example.org/apps/jonah"). Parse it through
* Uri::getPath() so str_starts_with() compares path-against-path either way.
*/
$request = (new RequestBuilder(
new RequestFactory(),
new StreamFactory(),
new UriFactory(),
))->withGlobalVariables()->build();

$webroot = rtrim($GLOBALS['registry']->get('webroot', 'jonah'), '/');
$webrootConfig = (string) $GLOBALS['registry']->get('webroot', 'jonah');
$webroot = rtrim((new Uri($webrootConfig))->getPath(), '/');
$path = $request->getUri()->getPath();
if ($webroot !== '' && str_starts_with($path, $webroot)) {
$path = substr($path, strlen($webroot));
Expand Down Expand Up @@ -75,6 +81,13 @@
*/
$controllerClass = $result['controller'];
if (class_exists($controllerClass)) {
/*
* Expose matched route parameters (e.g. channel_id, id) to the
* controller as the 'route' request attribute. Without this, every
* controller would see an empty $request->getAttribute('route', [])
* and redirect to ChannelList with "No channel requested."
*/
$request = $request->withAttribute('route', $result);
$controller = $GLOBALS['injector']->getInstance($controllerClass);
$response = $controller->handle($request);
(new ResponseWriterWeb())->writeResponse($response);
Expand Down
Loading