From a44ddc0b941f7122cc3eb998fed3f424c9d319bc Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 21 Feb 2025 07:34:24 +0100 Subject: [PATCH] remove old code, add error middleware and catch all route --- index.php | 50 ++++++++------------------------------------------ 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/index.php b/index.php index bf780ef9a..5fe1d480c 100644 --- a/index.php +++ b/index.php @@ -44,32 +44,9 @@ if(true) { $containerBuilder = new \DI\ContainerBuilder(); $c = $containerBuilder->build(); - /* - $c['notFoundHandler'] = function ($c) use ($settings, $dms) { - return function ($request, $response) use ($c, $settings, $dms) { - $uri = $request->getUri(); - if($uri->getBasePath()) - $file = $uri->getPath(); - else - $file = substr($uri->getPath(), 1); - if(file_exists($file) && is_file($file)) { - $_SERVER['SCRIPT_FILENAME'] = basename($file); -// include($file); - exit; - } - if($request->isXhr()) { - exit; - } -// print_r($request->getUri()); -// exit; - return $c['response'] - ->withStatus(302) - ->withHeader('Location', isset($settings->_siteDefaultPage) && strlen($settings->_siteDefaultPage)>0 ? $settings->_httpRoot.$settings->_siteDefaultPage : $settings->_httpRoot."out/out.ViewFolder.php"); - }; - }; - */ AppFactory::setContainer($c); $app = AppFactory::create(); + /* put lots of data into the container, because if slim instanciates * a class by itself (with the help from the DI container), it will * pass the container to the constructor of the instanciated class. @@ -91,12 +68,8 @@ if(true) { } } - $app->get('/', function($request, $response) { - return $response - ->withHeader('Location', '/out/out.ViewFolder.php') - ->withStatus(302); + $app->addErrorMiddleware(false, true, true); - }); if(isset($GLOBALS['SEEDDMS_HOOKS']['initDMS'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['initDMS'] as $hookObj) { if (method_exists($hookObj, 'addRoute')) { @@ -107,20 +80,13 @@ if(true) { } } - /* - $app->get('/out/[{path:.*}]', function($request, $response, $path = null) use ($app) { - $uri = $request->getUri(); - if($uri->getBasePath()) - $file = $uri->getPath(); - else - $file = substr($uri->getPath(), 1); - if(file_exists($file) && is_file($file)) { - $_SERVER['SCRIPT_FILENAME'] = basename($file); - include($file); - exit; - } + /* Catch all route */ + $app->get('/{path:.*}', function($request, $response) { + return $response + ->withHeader('Location', '/out/out.ViewFolder.php') + ->withStatus(302); + }); - */ $app->run(); } else {