From 0b442f70e69e7d9844ff1d666f1c31ba5ef575e1 Mon Sep 17 00:00:00 2001 From: Felipe Figueroa Date: Fri, 16 Oct 2020 07:10:54 -0300 Subject: replacing subfolder constant with facade and method to access the container --- src/traits/AdminTrait.php | 32 ++++++++++++++++---------------- src/traits/ExportTrait.php | 2 +- src/traits/HelperTrait.php | 23 +---------------------- src/traits/InsertEditRowTrait.php | 4 ++-- src/traits/MiscTrait.php | 10 +++++----- src/traits/ViewsMatviewsTrait.php | 14 ++++++++------ 6 files changed, 33 insertions(+), 52 deletions(-) diff --git a/src/traits/AdminTrait.php b/src/traits/AdminTrait.php index 8460eaa3..513f15e7 100644 --- a/src/traits/AdminTrait.php +++ b/src/traits/AdminTrait.php @@ -34,7 +34,7 @@ trait AdminTrait $this->printTrail('schema'); $this->printTitle($this->lang['strclusterindex'], 'pg.index.cluster'); - echo '
" . \PHP_EOL; + echo '" . \PHP_EOL; foreach ($_REQUEST['ma'] as $v) { $a = \unserialize(\htmlspecialchars_decode($v, \ENT_QUOTES)); @@ -45,7 +45,7 @@ trait AdminTrait $this->printTrail($type); $this->printTitle($this->lang['strclusterindex'], 'pg.index.cluster'); - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; if ('table' === $type) { echo '

', \sprintf($this->lang['strconfclustertable'], $this->misc->printVal($_REQUEST['object'])), '

' . \PHP_EOL; @@ -86,7 +86,7 @@ trait AdminTrait $this->printTrail('schema'); $this->printTitle($this->lang['strreindex'], 'pg.reindex'); - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; foreach ($_REQUEST['ma'] as $v) { $a = \unserialize(\htmlspecialchars_decode($v, \ENT_QUOTES)); @@ -97,7 +97,7 @@ trait AdminTrait $this->printTrail($type); $this->printTitle($this->lang['strreindex'], 'pg.reindex'); - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; if ('table' === $type) { echo '

', \sprintf($this->lang['strconfreindextable'], $this->misc->printVal($_REQUEST['object'])), '

' . \PHP_EOL; @@ -141,7 +141,7 @@ trait AdminTrait $this->printTrail('schema'); $this->printTitle($this->lang['stranalyze'], 'pg.analyze'); - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; foreach ($_REQUEST['ma'] as $v) { $a = \unserialize(\htmlspecialchars_decode($v, \ENT_QUOTES)); @@ -153,7 +153,7 @@ trait AdminTrait $this->printTrail($type); $this->printTitle($this->lang['stranalyze'], 'pg.analyze'); - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; if ('table' === $type) { echo '

', \sprintf($this->lang['strconfanalyzetable'], $this->misc->printVal($_REQUEST['object'])), '

' . \PHP_EOL; @@ -190,7 +190,7 @@ trait AdminTrait $this->printTrail('schema'); $this->printTitle($this->lang['strvacuum'], 'pg.vacuum'); - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; foreach ($_REQUEST['ma'] as $v) { $a = \unserialize(\htmlspecialchars_decode($v, \ENT_QUOTES)); @@ -202,7 +202,7 @@ trait AdminTrait $this->printTrail($type); $this->printTitle($this->lang['strvacuum'], 'pg.vacuum'); - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; if ('table' === $type) { echo '

', \sprintf($this->lang['strconfvacuumtable'], $this->misc->printVal($_REQUEST['object'])), '

' . \PHP_EOL; @@ -286,7 +286,7 @@ trait AdminTrait $old_val['autovacuum_vacuum_cost_limit'] = ''; } - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; echo $this->view->form; echo '' . \PHP_EOL; echo \sprintf('%s', \htmlspecialchars($_REQUEST['table']), \PHP_EOL); @@ -661,7 +661,7 @@ trait AdminTrait // Vacuum echo '' . \PHP_EOL; echo '' . \PHP_EOL; - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; echo '

' . \PHP_EOL; echo $this->view->form; @@ -672,7 +672,7 @@ trait AdminTrait // Analyze echo '' . \PHP_EOL; - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; echo '

' . \PHP_EOL; echo $this->view->form; echo $table_hidden_inputs; @@ -685,7 +685,7 @@ trait AdminTrait // Reindex echo '' . \PHP_EOL; - echo '" . \PHP_EOL; + echo '" . \PHP_EOL; echo '

' . \PHP_EOL; echo $this->view->form; echo $table_hidden_inputs; @@ -807,7 +807,7 @@ trait AdminTrait $disabled = ''; $reclusterconf = '' . \PHP_EOL; - $reclusterconf .= '" . \PHP_EOL; + $reclusterconf .= '" . \PHP_EOL; $reclusterconf .= $this->view->form; $reclusterconf .= $table_hidden_inputs; @@ -854,13 +854,13 @@ trait AdminTrait 'namespace' => [ 'title' => $this->lang['strschema'], 'field' => Decorator::field('nspname'), - 'url' => self::SUBFOLDER . "/redirect/schema?{$this->misc->href}&", + 'url' => \containerInstance()->subFolder . "/redirect/schema?{$this->misc->href}&", 'vars' => ['schema' => 'nspname'], ], 'relname' => [ 'title' => $this->lang['strtable'], 'field' => Decorator::field('relname'), - 'url' => self::SUBFOLDER . "/redirect/table?{$this->misc->href}&", + 'url' => \containerInstance()->subFolder . "/redirect/table?{$this->misc->href}&", 'vars' => ['table' => 'relname', 'schema' => 'nspname'], ], 'autovacuum_enabled' => [ @@ -947,7 +947,7 @@ trait AdminTrait if (('table' === $type) && (0 === $autovac->recordCount())) { echo '
'; - echo 'misc->href}&table="; + echo 'misc->href}&table="; echo \htmlspecialchars($_REQUEST['table']); echo "\">{$this->lang['straddvacuumtable']}"; } diff --git a/src/traits/ExportTrait.php b/src/traits/ExportTrait.php index 803bb58b..9098c2df 100644 --- a/src/traits/ExportTrait.php +++ b/src/traits/ExportTrait.php @@ -172,7 +172,7 @@ trait ExportTrait { $content = \sprintf( '%s', - self::SUBFOLDER . '/src/views', + \containerInstance()->subFolder . '/src/views', $endpoint, \PHP_EOL ); diff --git a/src/traits/HelperTrait.php b/src/traits/HelperTrait.php index 0728ede1..a2b1b98f 100644 --- a/src/traits/HelperTrait.php +++ b/src/traits/HelperTrait.php @@ -18,28 +18,7 @@ namespace PHPPgAdmin\Traits; */ trait HelperTrait { - /** - * static reference to subfolder in which the app is running. - * - * @var null|string - */ - public static $subFolder = null; - - /** - * Gets the subfolder. - * - * @param string $path The path - * - * @return string the subfolder - */ - public function getSubfolder(string $path = ''): string - { - if (null === self::$subFolder) { - self::$subFolder = $this->container->subfolder; - } - - return \implode(\DIRECTORY_SEPARATOR, [self::$subFolder, $path]); - } + /** * Halts the execution of the program. It's like calling exit() but using builtin Slim Exceptions. diff --git a/src/traits/InsertEditRowTrait.php b/src/traits/InsertEditRowTrait.php index a6c2ac2a..742d518f 100644 --- a/src/traits/InsertEditRowTrait.php +++ b/src/traits/InsertEditRowTrait.php @@ -119,12 +119,12 @@ trait InsertEditRowTrait $fksprops['code'] .= "var table='" . \addslashes(\htmlentities($table, \ENT_QUOTES, 'UTF-8')) . "';"; $fksprops['code'] .= "var server='" . \htmlentities($_REQUEST['server'], \ENT_QUOTES, 'UTF-8') . "';"; $fksprops['code'] .= "var database='" . \addslashes(\htmlentities($_REQUEST['database'], \ENT_QUOTES, 'UTF-8')) . "';"; - $fksprops['code'] .= "var subfolder='" . self::SUBFOLDER . "';"; + $fksprops['code'] .= "var subfolder='" . \containerInstance()->subFolder . "';"; $fksprops['code'] .= '' . \PHP_EOL; $fksprops['code'] .= '

'; $fksprops['code'] .= '
'; - $fksprops['code'] .= ''; + $fksprops['code'] .= ''; } else { /* we have no foreign keys on this table */ return false; diff --git a/src/traits/MiscTrait.php b/src/traits/MiscTrait.php index 7c5e21b4..ac6632c4 100644 --- a/src/traits/MiscTrait.php +++ b/src/traits/MiscTrait.php @@ -161,11 +161,11 @@ trait MiscTrait } if (!isset($vars['url'])) { - $vars['url'] = self::SUBFOLDER . '/redirect'; + $vars['url'] = \containerInstance()->subFolder . '/redirect'; } - if (self::SUBFOLDER . '/redirect' === $vars['url'] && isset($vars['params']['subject'])) { - $vars['url'] = self::SUBFOLDER . '/redirect/' . $vars['params']['subject']; + if (containerInstance()->subFolder . '/redirect' === $vars['url'] && isset($vars['params']['subject'])) { + $vars['url'] = \containerInstance()->subFolder . '/redirect/' . $vars['params']['subject']; unset($vars['params']['subject']); } @@ -1038,14 +1038,14 @@ trait MiscTrait return [ 'sql' => [ 'title' => $lang['strsql'], - 'url' => self::SUBFOLDER . '/src/views/sqledit', + 'url' => \containerInstance()->subFolder . '/src/views/sqledit', 'urlvars' => ['action' => 'sql', 'subject' => 'schema'], 'help' => 'pg.sql', 'icon' => 'SqlEditor', ], 'find' => [ 'title' => $lang['strfind'], - 'url' => self::SUBFOLDER . '/src/views/sqledit', + 'url' => \containerInstance()->subFolder . '/src/views/sqledit', 'urlvars' => ['action' => 'find', 'subject' => 'schema'], 'icon' => 'Search', ], diff --git a/src/traits/ViewsMatviewsTrait.php b/src/traits/ViewsMatviewsTrait.php index 9a35516d..6bd20a44 100644 --- a/src/traits/ViewsMatviewsTrait.php +++ b/src/traits/ViewsMatviewsTrait.php @@ -64,7 +64,7 @@ trait ViewsMatviewsTrait $attrs = $data->getTableAttributes($_REQUEST[$this->keystring]); - echo ''; + echo ''; echo \PHP_EOL; if (0 < $attrs->recordCount()) { @@ -118,12 +118,13 @@ trait ViewsMatviewsTrait '>', \htmlspecialchars($v), '' . \PHP_EOL; } echo '' . \PHP_EOL; - echo '', $data->printField( + echo ''; + echo $data->printField( "values[{$attrs->fields['attname']}]", $_REQUEST['values'][$attrs->fields['attname']], $attrs->fields['type'] - ), ''; - echo '' . \PHP_EOL; + ); + echo '' . \PHP_EOL; ++$i; $attrs->moveNext(); } @@ -184,7 +185,7 @@ trait ViewsMatviewsTrait $tables = $data->getAllTables(); - echo 'script}\" method=\"post\">" . \PHP_EOL; + echo 'script}\" method=\"post\">" . \PHP_EOL; echo '' . \PHP_EOL; echo ""; echo "\n
{$this->lang['strtables']}
" . \PHP_EOL; @@ -375,7 +376,7 @@ trait ViewsMatviewsTrait } \asort($arrFields); - echo '' . \PHP_EOL; + echo '' . \PHP_EOL; echo '' . \PHP_EOL; echo ""; echo "\n\n
{$this->lang['strviewname']}
" . \PHP_EOL; @@ -409,6 +410,7 @@ trait ViewsMatviewsTrait for ($i = 0; $i < $linkCount; ++$i) { // Initialise variables + $formLink[$i]=$formLink[$i]??[]; $this->coalesceArr($formLink[$i], 'operator', 'INNER JOIN'); echo "
" . \PHP_EOL; -- cgit v1.2.3