diff options
Diffstat (limited to 'src/router.php')
-rw-r--r-- | src/router.php | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/src/router.php b/src/router.php index c3d707c1..4d252d6b 100644 --- a/src/router.php +++ b/src/router.php @@ -5,31 +5,35 @@ */ require_once __DIR__ . '/lib.inc.php'; +$app = getAppInstance(); +$container = containerInstance(); + +// Set the requestobj and responseobj properties of the container +// as the value of $request and $response, which already contain the route +$app->add(new \PHPPgAdmin\Middleware\PopulateRequestResponse($container)); + +if (!isset($msg)) { + $msg = ''; +} +$container['msg'] = $msg; +//ddd($container->misc); + $app->get('/status', function ( - /* @scrutinizer ignore-unused */ \Slim\Http\Request $request, - /* @scrutinizer ignore-unused */ \Slim\Http\Response $response, - /* @scrutinizer ignore-unused */ array $args ) { - \phpinfo(); - return; - //dump($this->get('settings')->all()); return $response ->withHeader('Content-type', 'application/json') ->withJson( - DEBUGMODE ? $this->get('settings')->all() : ['version' => $this->version] + $this->get('settings')['debug'] ? $this->get('settings')->all() : ['version' => $this->version] ); }); $app->post('/redirect/server', function ( - /* @scrutinizer ignore-unused */ \Slim\Http\Request $request, - /* @scrutinizer ignore-unused */ \Slim\Http\Response $response, - /* @scrutinizer ignore-unused */ array $args ) { $body = $response->getBody(); @@ -52,6 +56,7 @@ $app->post('/redirect/server', function ( $data = $misc->getDatabaseAccessor(); if (null === $data) { + //ddd($misc->getErrorMsg()); $login_controller = new \PHPPgAdmin\Controller\LoginController($this, true); $body->write($login_controller->doLoginForm($misc->getErrorMsg())); @@ -63,41 +68,36 @@ $app->post('/redirect/server', function ( $_SESSION['sharedPassword'] = $loginPassword; } - $misc->setReloadBrowser(true); + $this->view->setReloadBrowser(true); + $this->addFlash(true, 'reload_browser'); - $destinationurl = $this->utils->getDestinationWithLastTab('alldb'); + $destinationurl = $this->getDestinationWithLastTab('alldb'); return $response->withStatus(302)->withHeader('Location', $destinationurl); } $_server_info = $this->misc->getServerInfo(); if (!isset($_server_info['username'])) { - $destinationurl = $this->utils->getDestinationWithLastTab('server'); + $destinationurl = $this->getDestinationWithLastTab('server'); return $response->withStatus(302)->withHeader('Location', $destinationurl); } }); $app->get('/redirect[/{subject}]', function ( - /* @scrutinizer ignore-unused */ \Slim\Http\Request $request, - /* @scrutinizer ignore-unused */ \Slim\Http\Response $response, - /* @scrutinizer ignore-unused */ array $args ) { $subject = (isset($args['subject'])) ? $args['subject'] : 'root'; - $destinationurl = $this->utils->getDestinationWithLastTab($subject); + $destinationurl = $this->getDestinationWithLastTab($subject); return $response->withStatus(302)->withHeader('Location', $destinationurl); }); $app->map(['GET', 'POST'], '/src/views/{subject}', function ( - /* @scrutinizer ignore-unused */ \Slim\Http\Request $request, - /* @scrutinizer ignore-unused */ \Slim\Http\Response $response, - /* @scrutinizer ignore-unused */ array $args ) { $subject = $args['subject']; @@ -110,11 +110,11 @@ $app->map(['GET', 'POST'], '/src/views/{subject}', function ( $safe_subjects = ('servers' === $subject || 'intro' === $subject || 'browser' === $subject); if (null === $this->misc->getServerId() && !$safe_subjects) { - return $response->withStatus(302)->withHeader('Location', SUBFOLDER . '/src/views/servers'); + return $response->withStatus(302)->withHeader('Location', $this->subFolder . '/src/views/servers'); } if (!isset($_server_info['username']) && 'login' !== $subject && !$safe_subjects) { - $destinationurl = SUBFOLDER . '/src/views/login?server=' . $this->misc->getServerId(); + $destinationurl = $this->subFolder . '/src/views/login?server=' . $this->misc->getServerId(); return $response->withStatus(302)->withHeader('Location', $destinationurl); } @@ -126,11 +126,8 @@ $app->map(['GET', 'POST'], '/src/views/{subject}', function ( }); $app->get('/{subject:\w+}[/{server_id}]', function ( - /* @scrutinizer ignore-unused */ \Slim\Http\Request $request, - /* @scrutinizer ignore-unused */ \Slim\Http\Response $response, - /* @scrutinizer ignore-unused */ array $args ) { $subject = $args['subject'] ?? 'intro'; @@ -153,11 +150,8 @@ $app->get('/{subject:\w+}[/{server_id}]', function ( }); $app->get('/', function ( - /* @scrutinizer ignore-unused */ \Slim\Http\Request $request, - /* @scrutinizer ignore-unused */ \Slim\Http\Response $response, - /* @scrutinizer ignore-unused */ array $args ) { $subject = 'intro'; @@ -168,11 +162,8 @@ $app->get('/', function ( }); $app->get('[/{path:.*}]', function ( - /* @scrutinizer ignore-unused */ \Slim\Http\Request $request, - /* @scrutinizer ignore-unused */ \Slim\Http\Response $response, - /* @scrutinizer ignore-unused */ array $args ) { $filepath = \dirname(__DIR__) . '/' . $args['path']; @@ -180,7 +171,7 @@ $app->get('[/{path:.*}]', function ( //d($this->subfolder, $args, $query_string, $filepath); - $this->utils->prtrace($request->getAttribute('route')); + $this->prtrace($request->getAttribute('route')); return $response->write($args['path'] ? $args['path'] : 'index'); }); |