diff options
author | Felipe Figueroa <amenadiel@gmail.com> | 2021-01-07 00:49:45 +0300 |
---|---|---|
committer | Felipe Figueroa <amenadiel@gmail.com> | 2021-01-07 00:49:45 +0300 |
commit | 4cb07815847d9ffd3a363036e469bc791f079ec7 (patch) | |
tree | 9a5227168a274fcccc05b17561630007ace8d077 | |
parent | 79aa14c04217f978fe7bbe88920cde62cb1f994a (diff) |
deprecate iframes renderer
-rw-r--r-- | src/classes/ViewManager.php | 61 | ||||
-rw-r--r-- | src/router.php | 32 |
2 files changed, 45 insertions, 48 deletions
diff --git a/src/classes/ViewManager.php b/src/classes/ViewManager.php index 665a9ab5..a32eb41a 100644 --- a/src/classes/ViewManager.php +++ b/src/classes/ViewManager.php @@ -204,36 +204,7 @@ class ViewManager extends Twig return $this->_reload_browser; } -/** - * Undocumented function - * - * @param Response $response - * @param string $subject - * @param string $query_string - * @param string $template - * @return ResponseInterface - */ - public function maybeRenderIframes(Response $response, string $subject, string $query_string,string $template='intro_view.twig') - { - $c = $this->getContainer(); - - $in_test = $this->offsetGet('in_test'); - $includeJsTree = $this->offsetExists('includeJsTree')?$this->offsetGet('includeJsTree'):true; - - if ('1' === $in_test||$includeJsTree) { - $className = self::getControllerClassName($subject); - $controller = new $className($c); - - return $controller->render(); - } -ddd('DEFAULTING TO '.$template); - $viewVars = [ - 'url' => '/src/views/' . $subject . ($query_string ? '?' . $query_string : ''), - 'headertemplate' => 'header.twig', - ]; - - return $this->render($response, $template, $viewVars); - } + /** * Gets the theme from @@ -511,7 +482,35 @@ ddd('DEFAULTING TO '.$template); $_SESSION['ppaTheme'] = $_theme; } } +/** + * Undocumented function + * @deprecated v6.2.0 we won't use iframes anymore. + * @param Response $response + * @param string $subject + * @param string $query_string + * @param string $template + * @return ResponseInterface + */ +public function maybeRenderIframes(Response $response, string $subject, string $query_string,string $template='intro_view.twig') +{ + $c = $this->getContainer(); + + $in_test = $this->offsetGet('in_test'); + $includeJsTree = $this->offsetExists('includeJsTree')?$this->offsetGet('includeJsTree'):true; + + if ('1' === $in_test||$includeJsTree) { + $className = self::getControllerClassName($subject); + $controller = new $className($c); + return $controller->render(); + } + $viewVars = [ + 'url' => '/src/views/' . $subject . ($query_string ? '?' . $query_string : ''), + 'headertemplate' => 'header.twig', + ]; + + return $this->render($response, $template, $viewVars); +} /** * Undocumented function. * @@ -521,7 +520,7 @@ ddd('DEFAULTING TO '.$template); * * @return class-string */ - private static function getControllerClassName(string $subject): string + public function getControllerClassName(string $subject): string { return '\PHPPgAdmin\Controller\\' . \ucfirst($subject) . 'Controller'; } diff --git a/src/router.php b/src/router.php index 9db39b6f..392ff57f 100644 --- a/src/router.php +++ b/src/router.php @@ -35,6 +35,14 @@ if ($shouldSetSession && \PHP_SAPI !== 'cli') { $app = getAppInstance(); $container = $app->getContainer(); +// If no dump function has been globally declared at this point +// we fill the gap with an empty one to avoid errors +if(!function_exists('dump')) { + function dump(...$args):void { + // do nothing + } +} + // 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)); @@ -145,8 +153,8 @@ $app->map(['GET', 'POST'], '/src/views/{subject}', function ( ) { $subject = $args['subject']; $nextPath=$this->subFolder.'/'. $subject; - -return $response->withStatus(302)->withHeader('Location',$nextPath); + $query_string = $request->getUri()->getQuery(); +return $response->withStatus(302)->withHeader('Location',$nextPath.($query_string? '?'.$query_string:'')); }); $app->get('/{subject:\w+}[/{server_id}]', function ( @@ -156,12 +164,7 @@ $app->get('/{subject:\w+}[/{server_id}]', function ( ) { $subject = $args['subject'] ?? 'intro'; $server_id = $args['server_id'] ?? $request->getQueryParam('server'); - $query_params=$request->getQueryParams(); - $_server_info = $this->misc->getServerInfo(); - - //$this->utils->prtrace($_server_info); - if (!isset($_server_info['username'])) { $subject = 'login'; } @@ -171,8 +174,10 @@ $app->get('/{subject:\w+}[/{server_id}]', function ( } $query_string = $request->getUri()->getQuery(); $this->view->offsetSet('includeJsTree',true); + $className = $this->view->getControllerClassName($subject); + $controller = new $className($this); + return $controller->render(); - return $this->view->maybeRenderIframes($response, $subject, $query_string); }); $app->get('/', function ( @@ -181,8 +186,8 @@ $app->get('/', function ( array $args ) { $subject = 'intro'; - $query_string = $request->getUri()->getQuery(); + return $response->withStatus(302)->withHeader('Location',$nextPath); return $this->view->maybeRenderIframes($response, $subject, $query_string); }); @@ -192,14 +197,7 @@ $app->get('[/{path:.*}]', function ( \Slim\Http\Response $response, array $args ) { - $filepath = \dirname(__DIR__) . '/' . $args['path']; - $query_string = $request->getUri()->getQuery(); - - //d($this->subfolder, $args, $query_string, $filepath); - - $this->prtrace($request->getAttribute('route')); - - return $response->write($args['path'] ? $args['path'] : 'index'); + return $response->write(sprintf("We couldn't find a route matching %s", $args['path'] ? $args['path'] : 'index')); }); // Run app |