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
diff options
context:
space:
mode:
authorffflabs <amenadiel@gmail.com>2020-08-31 10:38:01 +0300
committerffflabs <amenadiel@gmail.com>2020-08-31 10:38:01 +0300
commit6acec792e066cfac909650d26246c7c6dd46a0df (patch)
tree47f295e4a6d454f4354f4bedfc4f4fd0a9d28814
parent221d5cb3d6338e1da859a2c80e6a518917d04c9e (diff)
adds more type declarations to main classes (ContainerUtils, Misc, ViewManager)
-rw-r--r--.gitignore9
-rw-r--r--Makefile42
-rw-r--r--phpstan.neon2
-rw-r--r--psalm.xml3
-rw-r--r--src/classes/ContainerUtils.php193
-rw-r--r--src/classes/Misc.php115
-rw-r--r--src/classes/Translations.php10
-rw-r--r--src/classes/ViewManager.php62
-rw-r--r--src/database/Connection.php29
-rw-r--r--src/database/Postgres.php2
-rw-r--r--src/database/databasetraits/TableTrait.php2
-rw-r--r--src/lib.inc.php32
12 files changed, 239 insertions, 262 deletions
diff --git a/.gitignore b/.gitignore
index f9a6fcc7..bc9be95c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
selenium/tests/config.inc.php
tests/selenium/config.test.php
-*sublime*
+
@@ -16,13 +16,18 @@ phppga
/.idea/*
sublime-*
.php.tools.ini
-
+.vscode/*
+*.code-workspace
+*sublime*
###> temp and generated files
temp/sessions/*
+temp/route.cache.php
playground
*.log
tests/_output
+temp/*.output.txt
+*baseline.*
###> Vendor files
node_modules
diff --git a/Makefile b/Makefile
index 68f6d23f..48185763 100644
--- a/Makefile
+++ b/Makefile
@@ -126,23 +126,20 @@ var_dumper:
fi;
@echo ""
-folder ?= src
-psalm: FOLDER_BASENAME:=`basename $(folder)|sed 's/src//'`
+
+
psalm:
- @if [ -f "vendor/bin/psalm" ]; then \
- mkdir -p .build/psalm ;\
- ${MAKE} disable_xdebug --no-print-directory ;\
- vendor/bin/psalm --show-info=true \
- --config=psalm.xml \
- --set-baseline=.build/psalm/psalm-baseline$(FOLDER_BASENAME).xml \
- --shepherd $(folder) ;\
- ${MAKE} enable_xdebug new_status=$(XDSWI_STATUS) --no-print-directory;\
- else \
- echo -e "$(GREEN)vimeo/psalm$(WHITE) is $(RED)NOT$(WHITE) installed. " ;\
+ @${MAKE} disable_xdebug --no-print-directory
+ @if [ ! -f "vendor/bin/psalm" ]; then \
+ echo -e "$(GREEN)psalm$(WHITE) is $(RED)NOT$(WHITE) installed. " ;\
echo -e "Install it with $(GREEN)composer require --dev vimeo/psalm$(WHITE)" ;\
+ exit 0 ;\
fi
- @echo ""
-
+
+ @mkdir -p .build/psalm ;\
+ vendor/bin/psalm --show-info=false --long-progress --threads=2 --config=psalm.xml | tee temp/psalm.output.txt
+ @${MAKE} enable_xdebug new_status=$(XDSWI_STATUS) --no-print-directory ;\
+ echo ""
phpstan:
@${MAKE} disable_xdebug --no-print-directory
@@ -153,27 +150,30 @@ phpstan:
fi
@mkdir -p .build/phpstan ;\
- ./vendor/bin/phpstan analyse --memory-limit=2G ${error_format}
+ ./vendor/bin/phpstan analyse --memory-limit=2G --configuration phpstan.neon | tee temp/phpstan.output.txt
@${MAKE} enable_xdebug new_status=$(XDSWI_STATUS) --no-print-directory ;\
echo ""
-
lint:
@if [ -f "vendor/bin/parallel-lint" ]; then \
mkdir -p .build/parallel ;\
${MAKE} disable_xdebug --no-print-directory ;\
- vendor/bin/parallel-lint \
- --ignore-fails \
- --exclude vendor \
- $(folder) ;\
+ vendor/bin/parallel-lint --ignore-fails --exclude vendor src ;\
${MAKE} enable_xdebug new_status=$(XDSWI_STATUS) --no-print-directory;\
else \
echo -e "$(GREEN)parallel-lint$(WHITE) is $(RED)NOT$(WHITE) installed. " ;\
- echo -e "Install it with $(GREEN)composer require --dev jakub-onderka/php-parallel-lint$(WHITE)" ;\
+ echo -e "Install it with $(GREEN)composer require --dev php-parallel-lint/php-parallel-lint$(WHITE)" ;\
fi
@find ./src -name \*.php -print0 | xargs -0 -n 1 php -l
@echo ""
+update_baselines:
+ @${MAKE} disable_xdebug --no-print-directory ;\
+ find .build/phpstan -mtime +5 -type f -name "*.php" -exec rm -rf {} \;
+ @vendor/bin/phpstan analyze --configuration phpstan.neon --generate-baseline ;\
+ find .build/psalm -mtime +5 -type f -exec rm -rf {} \;
+ @vendor/bin/psalm --config=psalm.xml --update-baseline --ignore-baseline --set-baseline=psalm-baseline.xml ;\
+ ${MAKE} enable_xdebug new_status=$(XDSWI_STATUS) --no-print-directory
fixers: phpmd psalm phpstan
diff --git a/phpstan.neon b/phpstan.neon
index 7ea93f06..8f96d6e8 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,5 +1,3 @@
-#includes:
-# - .build/phpstan/phpstan.baseline.neon
parameters:
diff --git a/psalm.xml b/psalm.xml
index bbc56be6..03fcae93 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -7,8 +7,7 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
- errorBaseline=".build/psalm/psalm-baseline.xml"
->
+ errorBaseline="psalm-baseline.xml">
<projectFiles>
<directory name="src" />
<ignoreFiles>
diff --git a/src/classes/ContainerUtils.php b/src/classes/ContainerUtils.php
index 36e4b2a6..d9477472 100644
--- a/src/classes/ContainerUtils.php
+++ b/src/classes/ContainerUtils.php
@@ -6,7 +6,7 @@
namespace PHPPgAdmin;
-use Psr\Container\ContainerInterface;
+use Slim\Container;
use Slim\App;
\defined('BASE_PATH') || \define('BASE_PATH', \dirname(__DIR__, 2));
@@ -40,7 +40,7 @@ class ContainerUtils
const THEME_PATH = THEME_PATH;
/**
- * @var ContainerInterface
+ * @var\Slim\Container
*/
protected $container;
@@ -124,7 +124,7 @@ class ContainerUtils
*
* @throws \Exception (description)
*
- * @return ContainerInterface the container instance
+ * @return\Slim\Container the container instance
*/
public static function getContainerInstance()
{
@@ -156,90 +156,22 @@ class ContainerUtils
*
* @param array $conf The conf
*
- * @return [ContainerInterface,App] ( description_of_the_return_value )
+ * @return \Slim\App ( description_of_the_return_value )
*/
- public static function createContainer($conf)
+ public static function createApp($conf)
{
$_instance = self::getInstance();
-
+
$_instance
- ->setConf($conf)
+ ->withConf($conf)
->setExtra()
->setMisc()
->setViews();
//ddd($container->subfolder);
- return [$_instance->container, self::$_instance->_app];
- }
-
- public function maybeRenderIframes($response, $subject, $query_string)
- {
- $c = self::getContainerInstance();
-
- $in_test = $c->view->offsetGet('in_test');
-
- if ('1' === $in_test) {
- $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)
- * 2. Server specific config theme 3.- $_SESSION global (subsequent requests after 1.) 4.- $_COOKIE global (mostly
- * fallback for $_SESSION after 1.- and 3.-) 5.- theme as set in config 6.- 'default' theme.
- *
- * @param array $conf The conf
- * @param null|mixed $_server_info
- *
- * @return string the theme
- */
- public function getTheme(array $conf, $_server_info = null)
- {
- $_theme = null;
- // List of themes
- $themefolders = $this->getThemeFolders();
- // Check if theme is in $_REQUEST, $_SESSION or $_COOKIE
- // 1.- First priority: $_REQUEST, this happens when you use the selector
- if (\array_key_exists('theme', $_REQUEST) &&
- \array_key_exists($_REQUEST['theme'], $themefolders)) {
- $_theme = $_REQUEST['theme'];
- } elseif ( // otherwise, see if there's a theme associated with this particular server
- null !== $_server_info &&
- \array_key_exists('theme', $_server_info) &&
- \is_string($_server_info['theme']) &&
- \array_key_exists($_COOKIE['ppaTheme'], $themefolders)) {
- $_theme = $_server_info['theme'];
- } elseif (\array_key_exists('ppaTheme', $_SESSION) &&
- \array_key_exists($_SESSION['ppaTheme'], $themefolders)) {
- // otherwise check $_SESSION
- $_theme = $_SESSION['ppaTheme'];
- } elseif (\array_key_exists('ppaTheme', $_SESSION) &&
- \array_key_exists($_COOKIE['ppaTheme'], $themefolders)) {
- // oterwise check $_COOKIE
- $_theme = $_COOKIE['ppaTheme'];
- } elseif ( // see if there's a valid theme set in config file
- \array_key_exists('theme', $conf) &&
- \is_string($conf['theme']) &&
- \array_key_exists($conf['theme'], $themefolders)) {
- $_theme = $conf['theme'];
- } else {
- // okay then, use default theme
- $_theme = 'default';
- }
-
- return $_theme;
+ return $_instance->_app;
}
+
/**
* Determines the redirection url according to query string.
@@ -293,29 +225,31 @@ class ContainerUtils
$this->addFlash($subject, 'getDestinationWithLastTab');
//$this->prtrace('$_server_info', $_server_info);
// If username isn't set in server_info, you should login
+ $url = $this->container->misc->getLastTabURL($subject)??['url'=>'alldb','urlvars'=>[ 'subject'=>'server']];
+ $destinationurl = $this->getRedirectUrl();
+
if (!isset($_server_info['username'])) {
- $destinationurl = $this->getRedirectUrl();
- } else {
- $url = $this->container->misc->getLastTabURL($subject);
- $this->addFlash($url, 'getLastTabURL for ' . $subject);
- // Load query vars into superglobal arrays
- if (isset($url['urlvars'])) {
- $urlvars = [];
-
- foreach ($url['urlvars'] as $key => $urlvar) {
- //$this->prtrace($key, $urlvar);
- $urlvars[$key] = \PHPPgAdmin\Decorators\Decorator::get_sanitized_value($urlvar, $_REQUEST);
- }
- $_REQUEST = \array_merge($_REQUEST, $urlvars);
- $_GET = \array_merge($_GET, $urlvars);
+ return $destinationurl;
+ }
+ if (!is_array($url)) {
+ return $this->getRedirectUrl($subject);
+ }
+ $this->addFlash($url, 'getLastTabURL for ' . $subject);
+ // Load query vars into superglobal arrays
+ if (isset($url['urlvars'])) {
+ $urlvars = [];
+
+ foreach ($url['urlvars'] as $key => $urlvar) {
+ //$this->prtrace($key, $urlvar);
+ $urlvars[$key] = \PHPPgAdmin\Decorators\Decorator::get_sanitized_value($urlvar, $_REQUEST);
}
-
- $actionurl = \PHPPgAdmin\Decorators\Decorator::actionurl($url['url'], $_GET);
- $destinationurl = $actionurl->value($_GET);
+ $_REQUEST = \array_merge($_REQUEST, $urlvars);
+ $_GET = \array_merge($_GET, $urlvars);
}
- $destinationurl = \str_replace('views/?', "views/{$subject}?", $destinationurl);
- // $this->prtrace('destinationurl for ' . $subject, $destinationurl);
- return $destinationurl;
+ $actionurl = \PHPPgAdmin\Decorators\Decorator::actionurl($url['url'], $_GET);
+ $destinationurl = $actionurl->value($_GET);
+
+ return \str_replace('views/?', "views/{$subject}?", $destinationurl);
}
/**
@@ -323,9 +257,9 @@ class ContainerUtils
*
* @param string $errormsg The error msg
*
- * @return ContainerInterface The app container
+ * @return\Slim\Container The app container
*/
- public function addError(string $errormsg): ContainerInterface
+ public function addError(string $errormsg):\Slim\Container
{
//dump($errormsg);
$errors = $this->container->get('errors');
@@ -334,13 +268,15 @@ class ContainerUtils
return $this->container;
}
-
- private function setConf($conf)
+ /**
+ * @param array $conf
+ */
+ private function withConf($conf):self
{
$container = self::getContainerInstance();
$conf['plugins'] = [];
- $container['conf'] = static function ($c) use ($conf) {
+ $container['conf'] = static function (\Slim\Container $c) use ($conf):array {
$display_sizes = $conf['display_sizes'];
if (\is_array($display_sizes)) {
@@ -374,8 +310,7 @@ class ContainerUtils
$container->subfolder = self::SUBFOLDER;
return $this;
- }
-
+ }
/**
* Sets the views.
*
@@ -386,9 +321,9 @@ class ContainerUtils
$container = self::getContainerInstance();
/**
- * return ViewManager.
+ * @return \PHPPgAdmin\ViewManager
*/
- $container['view'] = static function ($c) {
+ $container['view'] = static function (\Slim\Container $c):\PHPPgAdmin\ViewManager {
$misc = $c->misc;
$view = new ViewManager(BASE_PATH . '/assets/templates', [
'cache' => BASE_PATH . '/temp/twigcache',
@@ -412,7 +347,10 @@ class ContainerUtils
private function setMisc()
{
$container = self::getContainerInstance();
- $container['misc'] = static function ($c) {
+ /**
+ * @return \PHPPgAdmin\Misc
+ */
+ $container['misc'] = static function (\Slim\Container $c):\PHPPgAdmin\Misc {
$misc = new \PHPPgAdmin\Misc($c);
$conf = $c->get('conf');
@@ -434,11 +372,11 @@ class ContainerUtils
private function setExtra()
{
$container = self::getContainerInstance();
- $container['flash'] = static function () {
+ $container['flash'] = static function ():\Slim\Flash\Messages {
return new \Slim\Flash\Messages();
};
- $container['lang'] = static function ($c) {
+ $container['lang'] = static function (\Slim\Container $c):array {
$translations = new \PHPPgAdmin\Translations($c);
return $translations->lang;
@@ -446,40 +384,5 @@ class ContainerUtils
return $this;
}
-
- /**
- * Traverse THEME_PATH, consider as theme folders those which
- * contain a `global.css` stylesheet.
- *
- * @return array the theme folders
- */
- private function getThemeFolders()
- {
- // no THEME_PATH (how?) then return empty array
- if (!$gestor = \opendir(self::THEME_PATH)) {
- \closedir($gestor);
-
- return [];
- }
- $themefolders = [];
-
- /* This is the right way to iterate on a folder */
- while (false !== ($foldername = \readdir($gestor))) {
- if ('.' === $foldername || '..' === $foldername) {
- continue;
- }
-
- $folderpath = \sprintf('%s%s%s', self::THEME_PATH, \DIRECTORY_SEPARATOR, $foldername);
- $stylesheet = \sprintf('%s%s%s', $folderpath, \DIRECTORY_SEPARATOR, 'global.css');
- // if $folderpath if indeed a folder and contains a global.css file, then it's a theme
- if (\is_dir($folderpath) &&
- \is_file($stylesheet)) {
- $themefolders[$foldername] = $folderpath;
- }
- }
-
- \closedir($gestor);
-
- return $themefolders;
- }
+
}
diff --git a/src/classes/Misc.php b/src/classes/Misc.php
index ad4302aa..702a8b58 100644
--- a/src/classes/Misc.php
+++ b/src/classes/Misc.php
@@ -38,45 +38,64 @@ class Misc
*/
const DEBUGMODE = ContainerUtils::DEBUGMODE;
+
+ /** @var array */
public $appLangFiles = [];
-
+
+ /** @var string */
public $appName = '';
-
+
+ /** @var string */
public $appVersion = '';
- public $form = '';
+ public $form = '';
+
+ /** @var string */
public $href = '';
-
+
+ /** @var array */
public $lang = [];
-
+
+ /** @var array */
public $conf;
-
+
+ /** @var string */
public $phpMinVer;
-
+
+ /** @var string */
public $postgresqlMinVer;
-
+
+ /** @var \Slim\Views\Twig */
public $view;
+ /** @var \Slim\Container */
protected $container;
-
+
+ /** @var \PHPPgAdmin\Database\Connection|null */
private $_connection;
-
+
+ /** @var bool */
private $_no_db_connection = false;
-
+
+ /** @var bool */
private $_reload_browser = false;
/**
- * @var Postgres
+ * @var Postgres|null
*/
private $_data;
-
+
+ /** @var string|null */
private $_database;
-
+
+ /** @var string|null */
private $_server_id;
-
+
+ /** @var array|null */
private $_server_info;
-
+
+ /** @var string */
private $_error_msg = '';
/**
@@ -125,6 +144,7 @@ class Misc
* @param null|string $key value of the key to be retrieved. If null, the full array is returnes
*
* @return null|array|string the whole $conf array, the value of $conf[key] or null if said key does not exist
+
*/
public function getConf($key = null)
{
@@ -146,6 +166,7 @@ class Misc
* @param mixed $value value of the key to set
*
* @return \PHPPgAdmin\Misc this class instance
+
*/
public function setConf($key, $value)
{
@@ -153,7 +174,10 @@ class Misc
return $this;
}
-
+ /**
+ * @return string|null
+
+ */
public function serverToSha()
{
$request_server = $this->container->requestobj->getParam('server');
@@ -169,7 +193,10 @@ class Misc
return $request_server;
}
-
+ /**
+ * @return string
+
+ */
public function getServerId()
{
if ($this->_server_id) {
@@ -196,6 +223,7 @@ class Misc
* @param \Slim\Views\Twig $view view instance
*
* @return \PHPPgAdmin\Misc this class instance
+
*/
public function setView(\Slim\Views\Twig $view)
{
@@ -210,6 +238,7 @@ class Misc
* @param bool $flag sets internal $_reload_browser var which will be passed to the footer methods
*
* @return \PHPPgAdmin\Misc this class instance
+
*/
public function setReloadBrowser($flag)
{
@@ -217,12 +246,16 @@ class Misc
return $this;
}
+/**
+ * @return bool
+ */
public function getReloadBrowser()
{
return $this->_reload_browser;
}
+
public function getContainer()
{
return $this->container;
@@ -234,6 +267,7 @@ class Misc
* @param bool $flag true or false to allow unconnected clients to access the view
*
* @return \PHPPgAdmin\Misc this class instance
+
*/
public function setNoDBConnection($flag)
{
@@ -246,6 +280,7 @@ class Misc
* Gets member variable $_no_db_connection.
*
* @return bool value of member variable $_no_db_connection
+
*/
public function getNoDBConnection()
{
@@ -258,6 +293,7 @@ class Misc
* @param string $msg error message string
*
* @return \PHPPgAdmin\Misc this class instance
+
*/
public function setErrorMsg($msg)
{
@@ -270,6 +306,7 @@ class Misc
* Returns the error messages stored in member variable $_error_msg.
*
* @return string the error message
+
*/
public function getErrorMsg()
{
@@ -284,7 +321,8 @@ class Misc
*
* @internal mixed $plaform placeholder that will receive the value of the platform
*
- * @return null|\PHPPgAdmin\Database\Postgres the database accessor instance
+ * @return \PHPPgAdmin\Database\Postgres|null the database accessor instance
+
*/
public function getDatabaseAccessor($database = '', $server_id = null): ?\PHPPgAdmin\Database\Postgres
{
@@ -350,7 +388,8 @@ class Misc
}
}
- if (false === $this->_no_db_connection &&
+ if (
+ false === $this->_no_db_connection &&
null !== $this->getDatabase() &&
isset($_REQUEST['schema'])
) {
@@ -367,7 +406,14 @@ class Misc
return $this->_data;
}
- public function getConnection(string $database = '', $server_id = null)
+/**
+ * Undocumented function
+ *
+ * @param string $database
+ * @param string $server_id
+ * @return \PHPPgAdmin\Database\Connection
+ */
+ public function getConnection(string $database = '', $server_id = null):\PHPPgAdmin\Database\Connection
{
$lang = $this->lang;
@@ -389,7 +435,8 @@ class Misc
'administrator' => 'administrator',
];
- if (isset($server_info['username']) &&
+ if (
+ isset($server_info['username']) &&
\array_key_exists(\mb_strtolower($server_info['username']), $bad_usernames)
) {
$msg = $lang['strlogindisallowed'];
@@ -397,7 +444,8 @@ class Misc
throw new \Exception($msg);
}
- if (!isset($server_info['password']) ||
+ if (
+ !isset($server_info['password']) ||
'' === $server_info['password']
) {
$msg = $lang['strlogindisallowed'];
@@ -428,6 +476,7 @@ class Misc
* @param string $server_id A server identifier (host:port)
*
* @return null|array An associative array of server properties
+
*/
public function getServerInfo($server_id = null)
{
@@ -449,7 +498,8 @@ class Misc
$server_string = $info['host'] . ':' . $info['port'] . ':' . $info['sslmode'];
$server_sha = \sha1($server_string);
- if ($this->_server_id === $server_string ||
+ if (
+ $this->_server_id === $server_string ||
$this->_server_id === $server_sha
) {
if (isset($info['username'])) {
@@ -472,7 +522,7 @@ class Misc
return $this->_server_info;
}
-// //$this->prtrace('Invalid server param');
+ // //$this->prtrace('Invalid server param');
$this->_server_info = null;
// Unable to find a matching server, are we being hacked?
$this->halt($this->lang['strinvalidserverparam']);
@@ -487,6 +537,7 @@ class Misc
* params with the assoc-array in $value
* @param mixed $value the new value, or null to unset the parameter
* @param null|string $server_id the server identifier, or null for current server
+
*/
public function setServerInfo($key, $value, $server_id = null): void
{
@@ -509,6 +560,7 @@ class Misc
}
}
+
public function getDatabase(string $database = '')
{
if (null === $this->_server_id && !isset($_REQUEST['database'])) {
@@ -517,7 +569,8 @@ class Misc
$server_info = $this->getServerInfo($this->_server_id);
- if (null !== $this->_server_id &&
+ if (
+ null !== $this->_server_id &&
isset($server_info['useonlydefaultdb']) &&
true === $server_info['useonlydefaultdb'] &&
isset($server_info['defaultdb'])
@@ -544,6 +597,7 @@ class Misc
* @param string $schema The schema name
*
* @return int 0 on success
+
*/
public function setCurrentSchema($schema)
{
@@ -568,6 +622,7 @@ class Misc
* @param bool $all (optional) True to check pg_dumpall, false to just check pg_dump
*
* @return bool True, dumps are set up, false otherwise
+
*/
public function isDumpEnabled($all = false)
{
@@ -580,6 +635,7 @@ class Misc
* Sets the href tracking variable.
*
* @return \PHPPgAdmin\Misc this class instance
+
*/
public function setHREF()
{
@@ -594,6 +650,7 @@ class Misc
* @param null|string $exclude_from
*
* @return string
+
*/
public function getHREF($exclude_from = null)
{
@@ -625,6 +682,7 @@ class Misc
* enforce magic_quotes_gpc being off.
*
* @param mixed $var The variable to strip (passed by reference)
+
*/
public function stripVar(&$var): void
{
@@ -654,6 +712,7 @@ class Misc
* @param mixed $strIniSize The PHP.INI variable
*
* @return bool|float|int size in bytes, false on failure
+
*/
public function inisizeToBytes($strIniSize)
{
@@ -684,6 +743,7 @@ class Misc
}
}
+
public function getRequestVars($subject = '')
{
$v = [];
@@ -713,6 +773,7 @@ class Misc
* @param string $str The string to escape
*
* @return null|string The escaped string
+
*/
public function escapeShellArg($str): ?string
{
@@ -739,6 +800,7 @@ class Misc
* @param string $str The string to escape
*
* @return string The escaped string
+
*/
public function escapeShellCmd($str)
{
@@ -758,6 +820,7 @@ class Misc
* of the database and server.
*
* @param string $script the SQL script to save
+
*/
public function saveScriptHistory($script): void
{
diff --git a/src/classes/Translations.php b/src/classes/Translations.php
index 31f85441..80fda78a 100644
--- a/src/classes/Translations.php
+++ b/src/classes/Translations.php
@@ -11,10 +11,11 @@ namespace PHPPgAdmin;
*/
class Translations
{
+ /** @var array */
public $lang;
// List of language files, and encoded language name.
-
+/** @var array */
public $appLangFiles = [
'afrikaans' => 'Afrikaans',
'arabic' => '&#1593;&#1585;&#1576;&#1610;',
@@ -49,7 +50,7 @@ class Translations
'turkish' => 'T&uuml;rk&ccedil;e',
'ukrainian' => '&#1059;&#1082;&#1088;&#1072;&#9558;&#1085;&#1089;&#1100;&#1082;&#1072;',
];
-
+/** @var array */
public $appClasses = [
'afrikaans' => 'Afrikaans',
'arabic' => 'Arabic',
@@ -91,7 +92,8 @@ class Translations
* If it's available 'language-country', but not general
* 'language' translation (eg. 'portuguese-br', but not 'portuguese')
* specify both 'la' => 'language-country' and 'la-co' => 'language-country'.
- */
+ *
+ * @var array */
public $availableLanguages = [
'af' => 'afrikaans',
'ar' => 'arabic',
@@ -125,7 +127,7 @@ class Translations
'tr' => 'turkish',
'uk' => 'ukrainian',
];
-
+/** @var array */
public $languages_iso_code = [
'afrikaans' => 'af',
'arabic' => 'ar',
diff --git a/src/classes/ViewManager.php b/src/classes/ViewManager.php
index 785096a3..940de6d0 100644
--- a/src/classes/ViewManager.php
+++ b/src/classes/ViewManager.php
@@ -5,7 +5,7 @@
*/
namespace PHPPgAdmin;
-
+use PHPPgAdmin\ContainerUtils;
/**
* @file
* Class to hold various commonly used functions
@@ -39,27 +39,26 @@ class ViewManager extends \Slim\Views\Twig
* @var string
*/
const DEBUGMODE = ContainerUtils::DEBUGMODE;
-
+/** @var array */
public $appLangFiles = [];
-
+/** @var string */
public $appName = '';
-
+/** @var string */
public $appVersion = '';
-
+/** @var string */
public $form = '';
-
+/** @var string */
public $href = '';
-
+/** @var array */
public $lang = [];
-
+/** @var array */
public $conf;
-
+/** @var string */
public $phpMinVer;
-
+/** @var string */
public $postgresqlMinVer;
- public $view;
-
+
/**
* @var \PHPPgAdmin\Misc
*/
@@ -118,13 +117,22 @@ class ViewManager extends \Slim\Views\Twig
$_theme = $this->getTheme($this->conf, $this->misc->getServerInfo());
- if (null !== $_theme && isset($_SESSION)) {
+ if (isset($_SESSION) && !isset($_SESSION['ppaTheme'])) {
/* save the selected theme in cookie for a year */
\setcookie('ppaTheme', $_theme, \time() + 31536000, '/');
$_SESSION['ppaTheme'] = $_theme;
$this->misc->setConf('theme', $_theme);
}
}
+ /**
+ * Undocumented function
+ *
+ * @param string $subject
+ * @return class-string
+ */
+ private static function getControllerClassName(string $subject) {
+ return '\PHPPgAdmin\Controller\\' . \ucfirst($subject) . 'Controller';
+ }
public function maybeRenderIframes($response, $subject, $query_string)
{
@@ -133,7 +141,7 @@ class ViewManager extends \Slim\Views\Twig
$in_test = $this->offsetGet('in_test');
if ('1' === $in_test) {
- $className = '\PHPPgAdmin\Controller\\' . \ucfirst($subject) . 'Controller';
+ $className =self::getControllerClassName($subject);
$controller = new $className($c);
return $controller->render();
@@ -160,7 +168,7 @@ class ViewManager extends \Slim\Views\Twig
*/
public function getTheme(array $conf, $_server_info = null)
{
- $_theme = null;
+ $_theme = 'default';
// List of themes
$themefolders = $this->getThemeFolders();
// Check if theme is in $_REQUEST, $_SESSION or $_COOKIE
@@ -187,10 +195,7 @@ class ViewManager extends \Slim\Views\Twig
\is_string($conf['theme']) &&
\array_key_exists($conf['theme'], $themefolders)) {
$_theme = $conf['theme'];
- } else {
- // okay then, use default theme
- $_theme = 'default';
- }
+ }
return $_theme;
}
@@ -198,7 +203,7 @@ class ViewManager extends \Slim\Views\Twig
/**
* Sets the form tracking variable.
*/
- public function setForm()
+ public function setForm():string
{
$form = [];
@@ -236,6 +241,7 @@ class ViewManager extends \Slim\Views\Twig
* @param string $str the string that the context help is related to (already escaped)
* @param string $help help section identifier
* @param bool $do_print true to echo, false to return
+ * @return string|void
*/
public function printHelp($str, $help = null, $do_print = true)
{
@@ -268,12 +274,14 @@ class ViewManager extends \Slim\Views\Twig
\urlencode($this->misc->getServerId())
);
}
-
- public function icon($icon)
+ /**
+ * @param string $icon
+ * @return string
+ */
+ public function icon( $icon=''):string
{
- if (!\is_string($icon)) {
- return '';
- }
+
+ $icon=strval($icon??'');
$theme = $this->conf['theme'];
$path = 'assets/images/themes';
@@ -306,7 +314,7 @@ class ViewManager extends \Slim\Views\Twig
return $default_icon;
}
- private function getContainer()
+ private function getContainer():\Slim\Container
{
return $this->container;
}
@@ -317,7 +325,7 @@ class ViewManager extends \Slim\Views\Twig
*
* @return array the theme folders
*/
- private function getThemeFolders()
+ private function getThemeFolders():array
{
// no THEME_PATH (how?) then return empty array
if (!$gestor = \opendir(self::THEME_PATH)) {
diff --git a/src/database/Connection.php b/src/database/Connection.php
index 4f50cd49..bd6b982b 100644
--- a/src/database/Connection.php
+++ b/src/database/Connection.php
@@ -36,14 +36,7 @@ class Connection
'9.3' => 'Postgres93',
'9.2' => 'Postgres92',
'9.1' => 'Postgres91',
- '9.0' => 'Postgres90',
- '8.4' => 'Postgres84',
- '8.3' => 'Postgres83',
- '8.2' => 'Postgres82',
- '8.1' => 'Postgres81',
- '8.0' => 'Postgres80',
- '7.5' => 'Postgres80',
- '7.4' => 'Postgres74',
+ '9.0' => 'Postgres90'
];
// The backend platform. Set to UNKNOWN by default.
@@ -69,7 +62,7 @@ class Connection
$this->container = $container;
- $this->conn = ADONewConnection('postgres9');
+ $this->conn = \ADONewConnection('postgres9');
//$this->conn->debug = true;
$this->conn->setFetchMode($fetchMode);
@@ -101,6 +94,7 @@ class Connection
$this->conn->connect($pghost, $user, $password, $database);
//$this->prtrace($this->conn);
} catch (\Exception $e) {
+ dump($e);
$this->prtrace($e->getMessage(), $e->getTrace());
}
}
@@ -119,7 +113,11 @@ class Connection
* @return string The driver. e.g. Postgres96
*/
public function getDriver(&$description)
- {
+ {
+ $version=null;
+ if($this->conn->_connectionID) {
+
+
$v = \pg_version($this->conn->_connectionID);
//\PhpConsole\Handler::getInstance()->debug($v, 'pg_version');
@@ -127,7 +125,7 @@ class Connection
if (isset($v['server'])) {
$version = $v['server'];
}
-
+ }
// If we didn't manage to get the version without a query, query...
if (!isset($version)) {
$adodb = new ADOdbBase($this->conn, $this->container, $this->server_info);
@@ -143,7 +141,7 @@ class Connection
$params = \explode(' ', $field);
if (!isset($params[1])) {
- return -3;
+ return null;
}
$version = $params[1]; // eg. 8.4.4
@@ -165,10 +163,9 @@ class Connection
return $this->version_dictionary[$major_version];
}
- /* All <7.4 versions are not supported */
- // if major version is 7 or less and wasn't cought in the
- // switch/case block, we have an unsupported version.
- if (8 > (int) \mb_substr($version, 0, 1)) {
+
+ // if major version is less than 9 return null, we don't support it
+ if (9 > (int) \mb_substr($version, 0, 1)) {
return null;
}
diff --git a/src/database/Postgres.php b/src/database/Postgres.php
index 6e6dd3b5..4f1c979d 100644
--- a/src/database/Postgres.php
+++ b/src/database/Postgres.php
@@ -846,7 +846,7 @@ class Postgres extends ADOdbBase
$sql .= \implode('","', $show) . '" FROM ';
}
-
+$this->prtrace(['id'=>$this->id]);
$this->fieldClean($table);
if (isset($_REQUEST['schema'])) {
diff --git a/src/database/databasetraits/TableTrait.php b/src/database/databasetraits/TableTrait.php
index 084418fd..7cffce4e 100644
--- a/src/database/databasetraits/TableTrait.php
+++ b/src/database/databasetraits/TableTrait.php
@@ -389,7 +389,7 @@ trait TableTrait
$rs = $this->selectSet($sql);
if (1 !== $rs->recordCount()) {
- return null;
+ return false;
}
$rs->fields['relhasoids'] = $this->phpBool($rs->fields['relhasoids']);
diff --git a/src/lib.inc.php b/src/lib.inc.php
index 84adff6b..4ab6c3e5 100644
--- a/src/lib.inc.php
+++ b/src/lib.inc.php
@@ -6,21 +6,23 @@
\defined('BASE_PATH') || \define('BASE_PATH', \dirname(__DIR__));
-\defined('THEME_PATH') || \define('THEME_PATH', BASE_PATH . '/assets/themes');
+\defined('THEME_PATH') || \define('THEME_PATH', \dirname(__DIR__) . '/assets/themes');
// Enforce PHP environment
\ini_set('arg_separator.output', '&amp;');
-if (!\is_writable(BASE_PATH . '/temp')) {
+if (!\is_writable(\dirname(__DIR__) . '/temp')) {
die('Your temp folder must have write permissions (use chmod 777 temp -R on linux)');
}
-require_once BASE_PATH . '/vendor/autoload.php';
+require_once \dirname(__DIR__) . '/vendor/autoload.php';
$subfolder = '';
// Check to see if the configuration file exists, if not, explain
-if (\file_exists(BASE_PATH . '/config.inc.php')) {
+if (!\file_exists(\dirname(__DIR__) . '/config.inc.php')) {
+ die('Configuration error: Copy config.inc.php-dist to config.inc.php and edit appropriately.');
+}
$conf = [];
- include BASE_PATH . '/config.inc.php';
+ include \dirname(__DIR__) . '/config.inc.php';
if (isset($conf['subfolder']) && \is_string($conf['subfolder'])) {
$subfolder = $conf['subfolder'];
@@ -30,12 +32,10 @@ if (\file_exists(BASE_PATH . '/config.inc.php')) {
$subfolder = \str_replace(
$_SERVER['DOCUMENT_ROOT'],
'',
- BASE_PATH
+ \dirname(__DIR__)
);
}
-} else {
- die('Configuration error: Copy config.inc.php-dist to config.inc.php and edit appropriately.');
-}
+
\defined('PHPPGA_SUBFOLDER') || \define('PHPPGA_SUBFOLDER', $subfolder);
$shouldSetSession = (\defined('PHP_SESSION_ACTIVE') ? \PHP_SESSION_ACTIVE !== \session_status() : !\session_id())
&& !\headers_sent()
@@ -57,7 +57,7 @@ if (!\defined('ADODB_ERROR_HANDLER_TYPE')) {
if (!\defined('ADODB_ERROR_HANDLER')) {
\define('ADODB_ERROR_HANDLER', '\PHPPgAdmin\ADOdbException::adodb_throw');
}
-
+
if (DEBUGMODE) {
\ini_set('display_errors', 'On');
@@ -68,13 +68,15 @@ if (DEBUGMODE) {
if (\array_key_exists('register_debuggers', $conf) && \is_callable($conf['register_debuggers'])) {
$conf['register_debuggers']();
}
+
}
// Fetch App and DI Container
-[$container, $app] = \PHPPgAdmin\ContainerUtils::createContainer($conf);
+$app = \PHPPgAdmin\ContainerUtils::createApp($conf);
+$container=$app->getContainer();
-if (!$container instanceof \Psr\Container\ContainerInterface) {
- \trigger_error('App Container must be an instance of \\Psr\\Container\\ContainerInterface', \E_USER_ERROR);
+if (!$container instanceof \Slim\Container) {
+ \trigger_error('App Container must be an instance of \\Slim\\Container', \E_USER_ERROR);
}
// This should be deprecated once we're sure no php scripts are required directly
@@ -82,8 +84,8 @@ $container->offsetSet('server', $_REQUEST['server'] ?? null);
$container->offsetSet('database', $_REQUEST['database'] ?? null);
$container->offsetSet('schema', $_REQUEST['schema'] ?? null);
-$container['haltHandler'] = static function ($c) {
- return static function ($request, $response, $exits, $status = 500) use ($c) {
+$container['haltHandler'] = static function (\Slim\Container $c) {
+ return static function ($request, $response, $exits, $status = 500) use ( $c) {
$title = 'PHPPgAdmin Error';
$html = '<p>The application could not run because of the following error:</p>';