From dcbfb38c104e9b695b89dcfbd2879c999c09d49c Mon Sep 17 00:00:00 2001 From: anoack Date: Fri, 17 Jan 2025 16:24:02 +0100 Subject: re #5155 add registerSlimRoutes and getDispatcher in Plugins --- lib/plugins/core/StudIPPlugin.php | 25 +++++++++++++++++++++++-- public/plugins.php | 7 ++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/plugins/core/StudIPPlugin.php b/lib/plugins/core/StudIPPlugin.php index 8389859..abebfc7 100644 --- a/lib/plugins/core/StudIPPlugin.php +++ b/lib/plugins/core/StudIPPlugin.php @@ -211,7 +211,7 @@ abstract class StudIPPlugin if (!method_exists($this, $action)) { try { - $dispatcher = app(PluginDispatcher::class, ['plugin' => $this]); + $dispatcher = $this->getPluginDispatcher(); return $dispatcher->getRouteCallable($unconsumed_path); } catch (Trails\Exceptions\UnknownAction $exception) { if (count($args) > 0) { @@ -222,7 +222,7 @@ abstract class StudIPPlugin } } else { $that = $this; - return function ($request, $response, array $otherargs) use ($action, $args, $that) { + return function ($request, $response) use ($action, $args, $that) { ob_start(); call_user_func_array([$that, $action], $args); $content = ob_get_clean(); @@ -231,6 +231,27 @@ abstract class StudIPPlugin }; } } + + /** + * @return Trails\Dispatcher + */ + public function getPluginDispatcher() : \Trails\Dispatcher + { + return app(PluginDispatcher::class, ['plugin' => $this]); + } + + /** + * return false to stop route consumption + * + * @param $unconsumed_path string + * @param $app Slim\App + * @return string|false + */ + public function registerSlimRoutes($unconsumed_path, \Slim\App $app) + { + return $unconsumed_path; + } + /** * Callback function called after enabling a plugin. * The plugin's ID is transmitted for convenience. diff --git a/public/plugins.php b/public/plugins.php index 46c1679..c512dbf 100644 --- a/public/plugins.php +++ b/public/plugins.php @@ -51,9 +51,10 @@ $plugin_dispatch = function (ServerRequestInterface $request, RequestHandlerInte // set default page title PageLayout::setTitle($plugin->getPluginName()); - - $route_callable = $plugin->getRouteCallable($unconsumed); - $app->any(Request::pathInfo(), $route_callable); + $still_not_consumed = $plugin->registerSlimRoutes($unconsumed, $app); + if ($still_not_consumed !== false) { + $app->any(Request::pathInfo(), $plugin->getRouteCallable($still_not_consumed)); + } } catch (AccessDeniedException $ade) { $_SESSION['redirect_after_login'] = Request::url(); $response = $responseFactory->createResponse(302); -- cgit v1.0