Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmenadiel <amenadiel@gmail.com>2020-01-07 06:36:44 +0300
committerAmenadiel <amenadiel@gmail.com>2020-01-07 06:36:44 +0300
commitb8dfbe45c8588323c73c0ead742c44521b61fdae (patch)
treec531ea297b373f30fd77977bad9f0571f86f8184 /src
parentbf0e617e8a7207db623a31d383e14ca4f45fba5b (diff)
Creating Tag v6.0.0-RC1 at 2020-01-07 - ignoring test folder for packagist distrov6.0.0-RC1
Diffstat (limited to 'src')
-rw-r--r--src/classes/ContainerUtils.php34
-rw-r--r--src/lib.inc.php82
-rw-r--r--src/middleware/Middleware.php23
-rw-r--r--src/middleware/PopulateRequestResponse.php81
4 files changed, 133 insertions, 87 deletions
diff --git a/src/classes/ContainerUtils.php b/src/classes/ContainerUtils.php
index 8afd2f25..06a9c8de 100644
--- a/src/classes/ContainerUtils.php
+++ b/src/classes/ContainerUtils.php
@@ -31,7 +31,7 @@ class ContainerUtils
*/
public function __construct()
{
- $composerinfo = json_decode(file_get_contents(BASE_PATH . '/composer.json'));
+ $composerinfo = json_decode(file_get_contents(BASE_PATH.'/composer.json'));
$appVersion = $composerinfo->version;
$phpMinVer = (str_replace(['<', '>', '='], '', $composerinfo->require->php));
@@ -49,14 +49,14 @@ class ContainerUtils
'base_path' => BASE_PATH,
'debug' => DEBUGMODE,
- 'routerCacheFile' => BASE_PATH . '/temp/route.cache.php',
+ 'routerCacheFile' => BASE_PATH.'/temp/route.cache.php',
// Configuration file version. If this is greater than that in config.inc.php, then
// the app will refuse to run. This and $conf['version'] should be incremented whenever
// backwards incompatible changes are made to config.inc.php-dist.
'base_version' => 60,
// Application version
- 'appVersion' => 'v' . $appVersion,
+ 'appVersion' => 'v'.$appVersion,
// Application name
'appName' => 'phpPgAdmin6',
@@ -73,7 +73,7 @@ class ContainerUtils
// Fetch DI Container
$container = $this->app->getContainer();
$container['utils'] = $this;
- $container['version'] = 'v' . $appVersion;
+ $container['version'] = 'v'.$appVersion;
$container['errors'] = [];
$this->container = $container;
@@ -88,6 +88,26 @@ class ContainerUtils
return [self::$instance->container, self::$instance->app];
}
+ public function maybeRenderIframes($response, $subject, $query_string)
+ {
+ $c = $this->container;
+ $in_test = $c->view->offsetGet('in_test');
+
+ if ($in_test === '1') {
+ $className = '\PHPPgAdmin\Controller\\'.ucfirst($subject).'Controller';
+ $controller = new $className($c);
+
+ return $controller->render();
+ }
+
+ $viewVars = [
+ 'url' => '/src/views/'.$subject.($query_string ? '?'.$query_string : ''),
+ 'headertemplate' => 'header.twig',
+ ];
+
+ return $c->view->render($response, 'iframe_view.twig', $viewVars);
+ }
+
/**
* Gets the theme from
* 1. The $_REQUEST global (when it's chosen from start screen)
@@ -186,10 +206,10 @@ class ContainerUtils
// if server_id isn't set, then you will be redirected to intro
if ($this->container->requestobj->getQueryParam('server') === null) {
- $destinationurl = \SUBFOLDER . '/src/views/intro';
+ $destinationurl = \SUBFOLDER.'/src/views/intro';
} else {
// otherwise, you'll be redirected to the login page for that server;
- $destinationurl = \SUBFOLDER . '/src/views/login' . ($query_string ? '?' . $query_string : '');
+ $destinationurl = \SUBFOLDER.'/src/views/login'.($query_string ? '?'.$query_string : '');
}
return $destinationurl;
@@ -213,7 +233,7 @@ class ContainerUtils
$destinationurl = $this->getRedirectUrl();
} else {
$url = $this->container->misc->getLastTabURL($subject);
- $this->addFlash($url, 'getLastTabURL for ' . $subject);
+ $this->addFlash($url, 'getLastTabURL for '.$subject);
// Load query vars into superglobal arrays
if (isset($url['urlvars'])) {
$urlvars = [];
diff --git a/src/lib.inc.php b/src/lib.inc.php
index 2e12c2f4..8c182bf3 100644
--- a/src/lib.inc.php
+++ b/src/lib.inc.php
@@ -178,15 +178,6 @@ $container['plugin_manager'] = function ($c) {
return $plugin_manager;
};
-$container['serializer'] = function ($c) {
- $serializerbuilder = \JMS\Serializer\SerializerBuilder::create();
- $serializer = $serializerbuilder
- ->setCacheDir(BASE_PATH . '/temp/jms')
- ->setDebug($c->get('settings')['debug'])
- ->build();
- return $serializer;
-};
-
// Create Misc class references
$container['misc'] = function ($c) {
$misc = new \PHPPgAdmin\Misc($c);
@@ -202,17 +193,12 @@ $container['misc'] = function ($c) {
}
$_theme = $c->utils->getTheme($conf, $_server_info);
- // if any of the above conditions had set the $_theme variable
- // then we store it in the session and a cookie
- // and we overwrite $conf['theme'] with its value
if (!is_null($_theme)) {
/* save the selected theme in cookie for a year */
setcookie('ppaTheme', $_theme, time() + 31536000, '/');
$_SESSION['ppaTheme'] = $_theme;
+ $misc->setConf('theme', $_theme);
}
-
- $misc->setConf('theme', $_theme);
-
return $misc;
};
@@ -279,71 +265,7 @@ $container['haltHandler'] = function ($c) {
// Set the requestobj and responseobj properties of the container
// as the value of $request and $response, which already contain the route
-$app->add(
- function ($request, $response, $next) {
-
- $this['requestobj'] = $request;
- $this['responseobj'] = $response;
-
- $this['server'] = $request->getParam('server');
- $this['database'] = $request->getParam('database');
- $this['schema'] = $request->getParam('schema');
- $misc = $this->get('misc');
-
- $misc->setHREF();
- $misc->setForm();
-
- $this->view->offsetSet('METHOD', $request->getMethod());
- if ($request->getAttribute('route')) {
- $this->view->offsetSet('subject', $request->getAttribute('route')->getArgument('subject'));
- }
-
- $query_string = $request->getUri()->getQuery();
- $this->view->offsetSet('query_string', $query_string);
- $path = (SUBFOLDER ? (SUBFOLDER . '/') : '') . $request->getUri()->getPath() . ($query_string ? '?' . $query_string : '');
- $this->view->offsetSet('path', $path);
-
- $params = $request->getParams();
-
- $viewparams = [];
-
- foreach ($params as $key => $value) {
- if (is_scalar($value)) {
- $viewparams[$key] = $value;
- }
- }
-
- if (isset($_COOKIE['IN_TEST'])) {
- $in_test = (string) $_COOKIE['IN_TEST'];
- } else {
- $in_test = '0';
- }
-
- // remove tabs and linebreaks from query
- if (isset($params['query'])) {
- $viewparams['query'] = str_replace(["\r", "\n", "\t"], ' ', $params['query']);
- }
- $this->view->offsetSet('params', $viewparams);
- $this->view->offsetSet('in_test', $in_test);
-
- if (count($this['errors']) > 0) {
- return ($this->haltHandler)($this->requestobj, $this->responseobj, $this['errors'], 412);
- }
-
- $messages = $this->flash->getMessages();
- if (!empty($messages)) {
- foreach ($messages as $key => $message) {
- \PC::debug($message, 'Flash: ' . $key);
- }
- }
-
- // First execute anything else
- $response = $next($request, $response);
-
- // Any other request, pass on current response
- return $response;
- }
-);
+$app->add(new \PHPPgAdmin\Middleware\PopulateRequestResponse($container));
$container['action'] = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
diff --git a/src/middleware/Middleware.php b/src/middleware/Middleware.php
new file mode 100644
index 00000000..c6314fb4
--- /dev/null
+++ b/src/middleware/Middleware.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace PHPPgAdmin\Middleware;
+
+class Middleware
+{
+ use \PHPPgAdmin\Traits\HelperTrait;
+ protected $container;
+ protected $router;
+
+ public function __construct($container)
+ {
+ $this->container = $container;
+ $this->router = $container->get('router');
+ }
+
+ public function __get($property)
+ {
+ if (isset($this->container->{$property})) {
+ return $this->container->{$property};
+ }
+ }
+}
diff --git a/src/middleware/PopulateRequestResponse.php b/src/middleware/PopulateRequestResponse.php
new file mode 100644
index 00000000..97416fa8
--- /dev/null
+++ b/src/middleware/PopulateRequestResponse.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace PHPPgAdmin\Middleware;
+
+/**
+ * Set the requestobj and responseobj properties of the container
+ * as the value of $request and $response, which already contain the route
+ */
+class PopulateRequestResponse extends Middleware
+{
+ use \PHPPgAdmin\Traits\HelperTrait;
+
+ public function __invoke(
+ \Psr\Http\Message\ServerRequestInterface $request,
+ \Psr\Http\Message\ResponseInterface $response,
+ $next
+ ) {
+
+ $container = $this->container;
+ $container['requestobj'] = $request;
+ $container['responseobj'] = $response;
+
+ $container['server'] = $request->getParam('server');
+ $container['database'] = $request->getParam('database');
+ $container['schema'] = $request->getParam('schema');
+ $misc = $container->get('misc');
+
+ $misc->setHREF();
+ $misc->setForm();
+
+ $container->view->offsetSet('METHOD', $request->getMethod());
+ if ($request->getAttribute('route')) {
+ $container->view->offsetSet('subject', $request->getAttribute('route')->getArgument('subject'));
+ }
+
+ $query_string = $request->getUri()->getQuery();
+ $container->view->offsetSet('query_string', $query_string);
+ $path = (SUBFOLDER ? (SUBFOLDER . '/') : '') . $request->getUri()->getPath() . ($query_string ? '?' . $query_string : '');
+ $container->view->offsetSet('path', $path);
+
+ $params = $request->getParams();
+
+ $viewparams = [];
+
+ foreach ($params as $key => $value) {
+ if (is_scalar($value)) {
+ $viewparams[$key] = $value;
+ }
+ }
+
+ if (isset($_COOKIE['IN_TEST'])) {
+ $in_test = (string) $_COOKIE['IN_TEST'];
+ } else {
+ $in_test = '0';
+ }
+
+ // remove tabs and linebreaks from query
+ if (isset($params['query'])) {
+ $viewparams['query'] = str_replace(["\r", "\n", "\t"], ' ', $params['query']);
+ }
+ $container->view->offsetSet('params', $viewparams);
+ $container->view->offsetSet('in_test', $in_test);
+
+ if (count($container['errors']) > 0) {
+ return ($container->haltHandler)($container->requestobj, $container->responseobj, $container['errors'], 412);
+ }
+
+ $messages = $container->flash->getMessages();
+ if (!empty($messages)) {
+ foreach ($messages as $key => $message) {
+ \PC::debug($message, 'Flash: ' . $key);
+ }
+ }
+
+ // First execute anything else
+ $response = $next($request, $response);
+
+ // Any other request, pass on current response
+ return $response;
+ }
+}