From 348c44c972e54090f329511e992c7ea5618dd862 Mon Sep 17 00:00:00 2001 From: Art4 Date: Sun, 24 Nov 2024 15:36:37 +0000 Subject: [PATCH] inline slim routes and middlewares into advancedcontentfilter addon --- .../advancedcontentfilter.php | 25 +++++++++++-- advancedcontentfilter/src/middlewares.php | 32 ----------------- advancedcontentfilter/src/routes.php | 36 ------------------- 3 files changed, 23 insertions(+), 70 deletions(-) delete mode 100644 advancedcontentfilter/src/middlewares.php delete mode 100644 advancedcontentfilter/src/routes.php diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index 418b253e..84eb468c 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -192,9 +192,30 @@ function advancedcontentfilter_init() if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'api') { $slim = \Slim\Factory\AppFactory::create(); - require __DIR__ . '/src/middlewares.php'; + /** + * The routing middleware should be added before the ErrorMiddleware + * Otherwise exceptions thrown from it will not be handled + */ + $slim->addRoutingMiddleware(); + + $slim->addErrorMiddleware(true, true, true, DI::logger()); + + // register routes + $slim->group('/advancedcontentfilter/api', function (\Slim\Routing\RouteCollectorProxy $app) { + $app->group('/rules', function (\Slim\Routing\RouteCollectorProxy $app) { + $app->get('', 'advancedcontentfilter_get_rules'); + $app->post('', 'advancedcontentfilter_post_rules'); + + $app->get('/{id}', 'advancedcontentfilter_get_rules_id'); + $app->put('/{id}', 'advancedcontentfilter_put_rules_id'); + $app->delete('/{id}', 'advancedcontentfilter_delete_rules_id'); + }); + + $app->group('/variables', function (\Slim\Routing\RouteCollectorProxy $app) { + $app->get('/{guid}', 'advancedcontentfilter_get_variables_guid'); + }); + }); - require __DIR__ . '/src/routes.php'; $slim->run(); exit; diff --git a/advancedcontentfilter/src/middlewares.php b/advancedcontentfilter/src/middlewares.php deleted file mode 100644 index 2b831473..00000000 --- a/advancedcontentfilter/src/middlewares.php +++ /dev/null @@ -1,32 +0,0 @@ -. - * - */ - -use Friendica\DI; - -/** @var $slim \Slim\App */ - -/** - * The routing middleware should be added before the ErrorMiddleware - * Otherwise exceptions thrown from it will not be handled - */ -$slim->addRoutingMiddleware(); - -$errorMiddleware = $slim->addErrorMiddleware(true, true, true, DI::logger()); diff --git a/advancedcontentfilter/src/routes.php b/advancedcontentfilter/src/routes.php deleted file mode 100644 index a46f1b4b..00000000 --- a/advancedcontentfilter/src/routes.php +++ /dev/null @@ -1,36 +0,0 @@ -. - * - */ - -/* @var $slim Slim\App */ -$slim->group('/advancedcontentfilter/api', function (\Slim\Routing\RouteCollectorProxy $app) { - $app->group('/rules', function (\Slim\Routing\RouteCollectorProxy $app) { - $app->get('', 'advancedcontentfilter_get_rules'); - $app->post('', 'advancedcontentfilter_post_rules'); - - $app->get('/{id}', 'advancedcontentfilter_get_rules_id'); - $app->put('/{id}', 'advancedcontentfilter_put_rules_id'); - $app->delete('/{id}', 'advancedcontentfilter_delete_rules_id'); - }); - - $app->group('/variables', function (\Slim\Routing\RouteCollectorProxy $app) { - $app->get('/{guid}', 'advancedcontentfilter_get_variables_guid'); - }); -});