Extract dependencies from Util::expandUserString()
Uses DI instead. Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
parent
1ef1fb8095
commit
21ae1694a6
@ -377,6 +377,7 @@ return [
|
||||
ResponseFactory::class,
|
||||
Config::class,
|
||||
UserPreferencesHandler::class,
|
||||
DatabaseInterface::class,
|
||||
],
|
||||
],
|
||||
Export\TablesController::class => [
|
||||
|
||||
@ -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
|
||||
|
||||
-
|
||||
|
||||
@ -8527,8 +8527,6 @@
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
@ -10869,7 +10867,6 @@
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
</DeprecatedMethod>
|
||||
<InvalidPropertyAssignmentValue>
|
||||
<code><![CDATA[Config::getInstance()->selectedServer]]></code>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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';
|
||||
}
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -159,7 +159,12 @@ class SqlQueryForm
|
||||
$tmpDbLink .= htmlspecialchars($db) . '</a>';
|
||||
$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) . '</a>';
|
||||
$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(...),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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(...)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user