diff --git a/app/services_controllers.php b/app/services_controllers.php
index 9eb12a8e95..e9198a2dd7 100644
--- a/app/services_controllers.php
+++ b/app/services_controllers.php
@@ -377,6 +377,7 @@ return [
ResponseFactory::class,
Config::class,
UserPreferencesHandler::class,
+ DatabaseInterface::class,
],
],
Export\TablesController::class => [
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 38c5d9f2b5..56c63009e2 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -13134,7 +13134,7 @@ parameters:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
- count: 6
+ count: 5
path: src/Util.php
-
@@ -13143,7 +13143,7 @@ parameters:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
- count: 6
+ count: 5
path: src/Util.php
-
@@ -16941,7 +16941,7 @@ parameters:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
- count: 6
+ count: 5
path: tests/unit/UtilTest.php
-
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 0967f53ce8..d822f43b13 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -8527,8 +8527,6 @@
-
-
@@ -10869,7 +10867,6 @@
-
selectedServer]]>
diff --git a/src/Controllers/Export/ExportController.php b/src/Controllers/Export/ExportController.php
index e1e5a65bb3..d949730961 100644
--- a/src/Controllers/Export/ExportController.php
+++ b/src/Controllers/Export/ExportController.php
@@ -11,6 +11,7 @@ use PhpMyAdmin\Controllers\Database\ExportController as DatabaseExportController
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Core;
use PhpMyAdmin\Current;
+use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Exceptions\ExportException;
use PhpMyAdmin\Export\Export;
@@ -50,6 +51,7 @@ final readonly class ExportController implements InvocableController
private ResponseFactory $responseFactory,
private Config $config,
private UserPreferencesHandler $userPreferencesHandler,
+ private DatabaseInterface $dbi,
) {
}
@@ -235,7 +237,7 @@ final readonly class ExportController implements InvocableController
$filename = $this->export->getFinalFilename(
$exportPlugin,
- Sanitize::sanitizeFilename(Util::expandUserString($filenameTemplate), true),
+ Sanitize::sanitizeFilename(Util::expandUserString($this->dbi, $this->config, $filenameTemplate), true),
);
$mimeType = $this->export->getMimeType($exportPlugin);
diff --git a/src/Header.php b/src/Header.php
index 79ed5bca22..931407d78e 100644
--- a/src/Header.php
+++ b/src/Header.php
@@ -421,9 +421,7 @@ class Header
$tempTitle = $this->config->config->TitleDefault;
}
- $this->title = htmlspecialchars(
- Util::expandUserString($tempTitle),
- );
+ $this->title = htmlspecialchars(Util::expandUserString($this->dbi, $this->config, $tempTitle));
} else {
$this->title = 'phpMyAdmin';
}
diff --git a/src/Plugins/Export/ExportLatex.php b/src/Plugins/Export/ExportLatex.php
index f318b23aea..7f42a6a94e 100644
--- a/src/Plugins/Export/ExportLatex.php
+++ b/src/Plugins/Export/ExportLatex.php
@@ -294,12 +294,16 @@ class ExportLatex extends ExportPlugin
if ($this->caption) {
$buffer .= ' \\caption{'
. Util::expandUserString(
+ $this->dbi,
+ $this->config,
$this->dataCaption,
- [static::class, 'texEscape'],
+ static::texEscape(...),
['table' => $tableAlias, 'database' => $dbAlias],
)
. '} \\label{'
. Util::expandUserString(
+ $this->dbi,
+ $this->config,
$this->dataLabel,
null,
['table' => $tableAlias, 'database' => $dbAlias],
@@ -324,8 +328,10 @@ class ExportLatex extends ExportPlugin
$this->outputHandler->addLine(
'\\caption{'
. Util::expandUserString(
+ $this->dbi,
+ $this->config,
$this->dataContinuedCaption,
- [static::class, 'texEscape'],
+ static::texEscape(...),
['table' => $tableAlias, 'database' => $dbAlias],
)
. '} \\\\ ',
@@ -468,12 +474,16 @@ class ExportLatex extends ExportPlugin
if ($this->caption) {
$buffer .= ' \\caption{'
. Util::expandUserString(
+ $this->dbi,
+ $this->config,
$this->structureCaption,
- [static::class, 'texEscape'],
+ static::texEscape(...),
['table' => $tableAlias, 'database' => $dbAlias],
)
. '} \\label{'
. Util::expandUserString(
+ $this->dbi,
+ $this->config,
$this->structureLabel,
null,
['table' => $tableAlias, 'database' => $dbAlias],
@@ -487,8 +497,10 @@ class ExportLatex extends ExportPlugin
if ($this->caption) {
$buffer .= ' \\caption{'
. Util::expandUserString(
+ $this->dbi,
+ $this->config,
$this->structureContinuedCaption,
- [static::class, 'texEscape'],
+ static::texEscape(...),
['table' => $tableAlias, 'database' => $dbAlias],
)
. '} \\\\ ' . "\n";
diff --git a/src/SqlQueryForm.php b/src/SqlQueryForm.php
index 28f5760d31..af0708ffc2 100644
--- a/src/SqlQueryForm.php
+++ b/src/SqlQueryForm.php
@@ -159,7 +159,12 @@ class SqlQueryForm
$tmpDbLink .= htmlspecialchars($db) . '';
$legend = sprintf(__('Run SQL query/queries on database %s'), $tmpDbLink);
if ($query === '') {
- $query = Util::expandUserString($this->config->settings['DefaultQueryDatabase'], Util::backquote(...));
+ $query = Util::expandUserString(
+ $this->dbi,
+ $this->config,
+ $this->config->settings['DefaultQueryDatabase'],
+ Util::backquote(...),
+ );
}
} else {
$db = Current::$database;
@@ -174,7 +179,12 @@ class SqlQueryForm
$tmpTblLink .= htmlspecialchars($db) . '.' . htmlspecialchars($table) . '';
$legend = sprintf(__('Run SQL query/queries on table %s'), $tmpTblLink);
if ($query === '') {
- $query = Util::expandUserString($this->config->settings['DefaultQueryTable'], Util::backquote(...));
+ $query = Util::expandUserString(
+ $this->dbi,
+ $this->config,
+ $this->config->settings['DefaultQueryTable'],
+ Util::backquote(...),
+ );
}
}
diff --git a/src/Util.php b/src/Util.php
index d27191e79e..7ffdffc802 100644
--- a/src/Util.php
+++ b/src/Util.php
@@ -1079,6 +1079,8 @@ class Util
* @psalm-param callable(string):string|null $escape
*/
public static function expandUserString(
+ DatabaseInterface $dbi,
+ Config $config,
string $string,
callable|null $escape = null,
array $updates = [],
@@ -1086,7 +1088,6 @@ class Util
/* Content */
$vars = [];
$vars['http_host'] = Core::getEnv('HTTP_HOST');
- $config = Config::getInstance();
$vars['server_name'] = $config->selectedServer['host'];
$vars['server_verbose'] = $config->selectedServer['verbose'];
@@ -1135,7 +1136,7 @@ class Util
/* Fetch columns list if required */
if (str_contains($string, '@COLUMNS@')) {
- $columnsList = DatabaseInterface::getInstance()->getColumnNames(Current::$database, Current::$table);
+ $columnsList = $dbi->getColumnNames(Current::$database, Current::$table);
$columnNames = [];
if ($escape !== null) {
diff --git a/tests/unit/Controllers/Export/ExportControllerTest.php b/tests/unit/Controllers/Export/ExportControllerTest.php
index bd46432c2e..410585aff2 100644
--- a/tests/unit/Controllers/Export/ExportControllerTest.php
+++ b/tests/unit/Controllers/Export/ExportControllerTest.php
@@ -210,6 +210,7 @@ final class ExportControllerTest extends AbstractTestCase
ResponseFactory::create(),
$config,
$userPreferencesHandler,
+ $dbi,
);
$response = $exportController($request);
$output = $this->getActualOutputForAssertion();
@@ -384,6 +385,7 @@ final class ExportControllerTest extends AbstractTestCase
ResponseFactory::create(),
$config,
$userPreferencesHandler,
+ $dbi,
);
$response = $exportController($request);
$output = $this->getActualOutputForAssertion();
@@ -547,6 +549,7 @@ final class ExportControllerTest extends AbstractTestCase
ResponseFactory::create(),
$config,
$userPreferencesHandler,
+ $dbi,
);
$response = $exportController($request);
@@ -714,6 +717,7 @@ final class ExportControllerTest extends AbstractTestCase
ResponseFactory::create(),
$config,
$userPreferencesHandler,
+ $dbi,
);
$response = $exportController($request);
diff --git a/tests/unit/UtilTest.php b/tests/unit/UtilTest.php
index 7ff8726081..3e283f9d73 100644
--- a/tests/unit/UtilTest.php
+++ b/tests/unit/UtilTest.php
@@ -160,26 +160,15 @@ class UtilTest extends AbstractTestCase
#[DataProvider('providerExpandUserString')]
public function testExpandUserString(string $in, string $out): void
{
- $this->setGlobalConfig();
-
- $config = Config::getInstance();
+ $config = new Config();
$config->selectedServer['host'] = 'host&';
$config->selectedServer['verbose'] = 'verbose';
Current::$database = 'database';
Current::$table = 'table';
+ $dbi = $this->createDatabaseInterface();
- self::assertSame(
- $out,
- Util::expandUserString($in),
- );
-
- self::assertSame(
- htmlspecialchars($out),
- Util::expandUserString(
- $in,
- 'htmlspecialchars',
- ),
- );
+ self::assertSame($out, Util::expandUserString($dbi, $config, $in));
+ self::assertSame(htmlspecialchars($out), Util::expandUserString($dbi, $config, $in, htmlspecialchars(...)));
}
/**