Extract Config to a class property for some classes
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
ff5c4d2ae5
commit
fa68771d07
@ -60,8 +60,6 @@
|
||||
<file src="src/Bookmarks/BookmarkRepository.php">
|
||||
<DeprecatedMethod>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
</DeprecatedMethod>
|
||||
<InvalidArgument>
|
||||
<code>$result</code>
|
||||
@ -847,7 +845,6 @@
|
||||
<file src="src/Console.php">
|
||||
<DeprecatedMethod>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
</DeprecatedMethod>
|
||||
</file>
|
||||
<file src="src/Controllers/AbstractController.php">
|
||||
@ -4951,14 +4948,6 @@
|
||||
<file src="src/DatabaseInterface.php">
|
||||
<DeprecatedMethod>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
</DeprecatedMethod>
|
||||
<DeprecatedProperty>
|
||||
<code>Routing::$route</code>
|
||||
@ -5769,8 +5758,6 @@
|
||||
<file src="src/File.php">
|
||||
<DeprecatedMethod>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
</DeprecatedMethod>
|
||||
<FalsableReturnStatement>
|
||||
<code><![CDATA[$this->detectCompression()]]></code>
|
||||
@ -6783,20 +6770,19 @@
|
||||
<file src="src/LanguageManager.php">
|
||||
<DeprecatedMethod>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
</DeprecatedMethod>
|
||||
<MixedArgument>
|
||||
<code><![CDATA[$config->get('Lang')]]></code>
|
||||
<code><![CDATA[$config->getCookie('pma_lang')]]></code>
|
||||
<code><![CDATA[$this->config->get('Lang')]]></code>
|
||||
<code><![CDATA[$this->config->getCookie('pma_lang')]]></code>
|
||||
</MixedArgument>
|
||||
<MixedArrayOffset>
|
||||
<code><![CDATA[$langs[$config->get('DefaultLang')]]]></code>
|
||||
<code><![CDATA[$langs[$this->config->get('DefaultLang')]]]></code>
|
||||
</MixedArrayOffset>
|
||||
<MixedArrayTypeCoercion>
|
||||
<code><![CDATA[$langs[$config->get('DefaultLang')]]]></code>
|
||||
<code><![CDATA[$langs[$this->config->get('DefaultLang')]]]></code>
|
||||
</MixedArrayTypeCoercion>
|
||||
<MixedOperand>
|
||||
<code><![CDATA[$config->get('FilterLanguages')]]></code>
|
||||
<code><![CDATA[$this->config->get('FilterLanguages')]]></code>
|
||||
</MixedOperand>
|
||||
<PossiblyInvalidArgument>
|
||||
<code><![CDATA[$_GET['lang']]]></code>
|
||||
@ -6807,8 +6793,8 @@
|
||||
<code><![CDATA[$_POST['lang']]]></code>
|
||||
</PossiblyInvalidCast>
|
||||
<PossiblyNullArgument>
|
||||
<code><![CDATA[$config->get('Lang')]]></code>
|
||||
<code><![CDATA[$config->getCookie('pma_lang')]]></code>
|
||||
<code><![CDATA[$this->config->get('Lang')]]></code>
|
||||
<code><![CDATA[$this->config->getCookie('pma_lang')]]></code>
|
||||
</PossiblyNullArgument>
|
||||
<PossiblyNullArrayOffset>
|
||||
<code>$langs</code>
|
||||
@ -6816,9 +6802,9 @@
|
||||
<RiskyTruthyFalsyComparison>
|
||||
<code><![CDATA[empty($_GET['lang'])]]></code>
|
||||
<code><![CDATA[empty($_POST['lang'])]]></code>
|
||||
<code><![CDATA[empty($config->get('FilterLanguages'))]]></code>
|
||||
<code><![CDATA[empty($config->get('Lang'))]]></code>
|
||||
<code><![CDATA[empty($config->getCookie('pma_lang'))]]></code>
|
||||
<code><![CDATA[empty($this->config->get('FilterLanguages'))]]></code>
|
||||
<code><![CDATA[empty($this->config->get('Lang'))]]></code>
|
||||
<code><![CDATA[empty($this->config->getCookie('pma_lang'))]]></code>
|
||||
</RiskyTruthyFalsyComparison>
|
||||
</file>
|
||||
<file src="src/Linter.php">
|
||||
@ -10329,8 +10315,6 @@
|
||||
</file>
|
||||
<file src="src/ResponseRenderer.php">
|
||||
<DeprecatedMethod>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>DatabaseInterface::getInstance()</code>
|
||||
<code>DatabaseInterface::getInstance()</code>
|
||||
@ -11023,7 +11007,6 @@
|
||||
<file src="src/SqlQueryForm.php">
|
||||
<DeprecatedMethod>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
</DeprecatedMethod>
|
||||
<MixedArgument>
|
||||
<code>$table</code>
|
||||
@ -11039,8 +11022,8 @@
|
||||
<code>$query</code>
|
||||
</PossiblyInvalidArgument>
|
||||
<PossiblyInvalidArrayOffset>
|
||||
<code><![CDATA[$config->settings['Servers'][Current::$server]]]></code>
|
||||
<code><![CDATA[$config->settings['Servers'][Current::$server]]]></code>
|
||||
<code><![CDATA[$this->config->settings['Servers'][Current::$server]]]></code>
|
||||
<code><![CDATA[$this->config->settings['Servers'][Current::$server]]]></code>
|
||||
</PossiblyInvalidArrayOffset>
|
||||
<PossiblyInvalidCast>
|
||||
<code>$query</code>
|
||||
@ -11875,8 +11858,6 @@
|
||||
<file src="src/UserPreferences.php">
|
||||
<DeprecatedMethod>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
<code>Config::getInstance()</code>
|
||||
</DeprecatedMethod>
|
||||
<DocblockTypeContradiction>
|
||||
<code>[]</code>
|
||||
|
||||
@ -21,10 +21,12 @@ use PhpMyAdmin\Util;
|
||||
final class BookmarkRepository
|
||||
{
|
||||
private BookmarkFeature|null $bookmarkFeature;
|
||||
private readonly Config $config;
|
||||
|
||||
public function __construct(private DatabaseInterface $dbi, Relation $relation)
|
||||
{
|
||||
$this->bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature;
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +49,7 @@ final class BookmarkRepository
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! Config::getInstance()->settings['AllowSharedBookmarks']) {
|
||||
if (! $this->config->settings['AllowSharedBookmarks']) {
|
||||
$shared = false;
|
||||
}
|
||||
|
||||
@ -76,7 +78,7 @@ final class BookmarkRepository
|
||||
return [];
|
||||
}
|
||||
|
||||
$exactUserMatch = ! Config::getInstance()->settings['AllowSharedBookmarks'];
|
||||
$exactUserMatch = ! $this->config->settings['AllowSharedBookmarks'];
|
||||
|
||||
$query = 'SELECT * FROM ' . Util::backquote($this->bookmarkFeature->database)
|
||||
. '.' . Util::backquote($this->bookmarkFeature->bookmark)
|
||||
@ -121,7 +123,7 @@ final class BookmarkRepository
|
||||
if ($user !== null) {
|
||||
$query .= ' AND (user = ' . $this->dbi->quoteString($user);
|
||||
|
||||
$exactUserMatch = ! Config::getInstance()->settings['AllowSharedBookmarks'];
|
||||
$exactUserMatch = ! $this->config->settings['AllowSharedBookmarks'];
|
||||
if (! $exactUserMatch) {
|
||||
$query .= " OR user = ''";
|
||||
}
|
||||
|
||||
@ -29,12 +29,14 @@ class Console
|
||||
* Whether we are servicing an ajax request.
|
||||
*/
|
||||
private bool $isAjax = false;
|
||||
private readonly Config $config;
|
||||
|
||||
public function __construct(
|
||||
private readonly Relation $relation,
|
||||
private readonly Template $template,
|
||||
private readonly BookmarkRepository $bookmarkRepository,
|
||||
) {
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +68,7 @@ class Console
|
||||
return '';
|
||||
}
|
||||
|
||||
$bookmarks = $this->bookmarkRepository->getList(Config::getInstance()->selectedServer['user']);
|
||||
$bookmarks = $this->bookmarkRepository->getList($this->config->selectedServer['user']);
|
||||
$countBookmarks = count($bookmarks);
|
||||
if ($countBookmarks > 0) {
|
||||
$welcomeMessage = sprintf(
|
||||
@ -107,7 +109,7 @@ class Console
|
||||
}
|
||||
|
||||
$bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature;
|
||||
$sqlHistory = $this->relation->getHistory(Config::getInstance()->selectedServer['user']);
|
||||
$sqlHistory = $this->relation->getHistory($this->config->selectedServer['user']);
|
||||
$bookmarkContent = $this->getBookmarkContent();
|
||||
|
||||
return $this->template->render('console/display', [
|
||||
|
||||
@ -135,6 +135,7 @@ class DatabaseInterface implements DbalInterface
|
||||
public float $lastQueryExecutionTime = 0;
|
||||
|
||||
private ListDatabase|null $databaseList = null;
|
||||
private readonly Config $config;
|
||||
|
||||
/** @param DbiExtension $extension Object to be used for database queries */
|
||||
public function __construct(private DbiExtension $extension)
|
||||
@ -146,6 +147,7 @@ class DatabaseInterface implements DbalInterface
|
||||
|
||||
$this->cache = new Cache();
|
||||
$this->types = new Types($this);
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/** @deprecated Use dependency injection instead. */
|
||||
@ -203,8 +205,7 @@ class DatabaseInterface implements DbalInterface
|
||||
int $options = self::QUERY_BUFFERED,
|
||||
bool $cacheAffectedRows = true,
|
||||
): ResultInterface|false {
|
||||
$config = Config::getInstance();
|
||||
$debug = isset($config->settings['DBG']) && $config->settings['DBG']['sql'];
|
||||
$debug = isset($this->config->settings['DBG']) && $this->config->settings['DBG']['sql'];
|
||||
if (! isset($this->connections[$connectionType->value])) {
|
||||
return false;
|
||||
}
|
||||
@ -229,7 +230,7 @@ class DatabaseInterface implements DbalInterface
|
||||
$result,
|
||||
$this->lastQueryExecutionTime,
|
||||
);
|
||||
if ($config->settings['DBG']['sqllog']) {
|
||||
if ($this->config->settings['DBG']['sqllog']) {
|
||||
openlog('phpMyAdmin', LOG_NDELAY | LOG_PID, LOG_USER);
|
||||
|
||||
syslog(
|
||||
@ -326,7 +327,7 @@ class DatabaseInterface implements DbalInterface
|
||||
0,
|
||||
$connectionType,
|
||||
);
|
||||
if (Config::getInstance()->settings['NaturalOrder']) {
|
||||
if ($this->config->settings['NaturalOrder']) {
|
||||
usort($tables, strnatcasecmp(...));
|
||||
}
|
||||
|
||||
@ -371,9 +372,8 @@ class DatabaseInterface implements DbalInterface
|
||||
string|null $tableType = null,
|
||||
ConnectionType $connectionType = ConnectionType::User,
|
||||
): array {
|
||||
$config = Config::getInstance();
|
||||
if ($limitCount === true) {
|
||||
$limitCount = $config->settings['MaxTableList'];
|
||||
$limitCount = $this->config->settings['MaxTableList'];
|
||||
}
|
||||
|
||||
$tables = [];
|
||||
@ -388,7 +388,7 @@ class DatabaseInterface implements DbalInterface
|
||||
$pagingApplied = true;
|
||||
}
|
||||
|
||||
if (! $config->selectedServer['DisableIS']) {
|
||||
if (! $this->config->selectedServer['DisableIS']) {
|
||||
$sqlWhereTable = '';
|
||||
if ($table !== [] && $table !== '') {
|
||||
if (is_array($table)) {
|
||||
@ -449,7 +449,7 @@ class DatabaseInterface implements DbalInterface
|
||||
}
|
||||
}
|
||||
|
||||
if ($sortBy === 'Name' && $config->settings['NaturalOrder']) {
|
||||
if ($sortBy === 'Name' && $this->config->settings['NaturalOrder']) {
|
||||
// here, the array's first key is by schema name
|
||||
foreach ($tables as $oneDatabaseName => $oneDatabaseTables) {
|
||||
uksort($oneDatabaseTables, strnatcasecmp(...));
|
||||
@ -552,7 +552,7 @@ class DatabaseInterface implements DbalInterface
|
||||
|
||||
// Sort naturally if the config allows it and we're sorting
|
||||
// the Name column.
|
||||
if ($sortBy === 'Name' && $config->settings['NaturalOrder']) {
|
||||
if ($sortBy === 'Name' && $this->config->settings['NaturalOrder']) {
|
||||
uksort($eachTables, strnatcasecmp(...));
|
||||
|
||||
if ($sortOrder === 'DESC') {
|
||||
@ -633,21 +633,20 @@ class DatabaseInterface implements DbalInterface
|
||||
): array {
|
||||
$sortOrder = strtoupper($sortOrder);
|
||||
|
||||
$config = Config::getInstance();
|
||||
if ($limitCount === true) {
|
||||
$limitCount = $config->settings['MaxDbList'];
|
||||
$limitCount = $this->config->settings['MaxDbList'];
|
||||
}
|
||||
|
||||
$applyLimitAndOrderManual = true;
|
||||
|
||||
if (! $config->selectedServer['DisableIS']) {
|
||||
if (! $this->config->selectedServer['DisableIS']) {
|
||||
/**
|
||||
* if \PhpMyAdmin\Config::getInstance()->settings['NaturalOrder'] is enabled, we cannot use LIMIT
|
||||
* if NaturalOrder config is enabled, we cannot use LIMIT
|
||||
* cause MySQL does not support natural ordering,
|
||||
* we have to do it afterward
|
||||
*/
|
||||
$limit = '';
|
||||
if (! $config->settings['NaturalOrder']) {
|
||||
if (! $this->config->settings['NaturalOrder']) {
|
||||
if ($limitCount) {
|
||||
$limit = ' LIMIT ' . $limitCount . ' OFFSET ' . $limitOffset;
|
||||
}
|
||||
@ -733,7 +732,7 @@ class DatabaseInterface implements DbalInterface
|
||||
|
||||
/**
|
||||
* apply limit and order manually now
|
||||
* (caused by older MySQL < 5 or \PhpMyAdmin\Config::getInstance()->settings['NaturalOrder'])
|
||||
* (caused by older MySQL < 5 or NaturalOrder config)
|
||||
*/
|
||||
if ($applyLimitAndOrderManual) {
|
||||
usort(
|
||||
@ -768,7 +767,7 @@ class DatabaseInterface implements DbalInterface
|
||||
string|null $column = null,
|
||||
ConnectionType $connectionType = ConnectionType::User,
|
||||
): array {
|
||||
if (! Config::getInstance()->selectedServer['DisableIS']) {
|
||||
if (! $this->config->selectedServer['DisableIS']) {
|
||||
$sql = QueryGenerator::getInformationSchemaColumnsFullRequest(
|
||||
$database !== null ? $this->quoteString($database, $connectionType) : null,
|
||||
$table !== null ? $this->quoteString($table, $connectionType) : null,
|
||||
@ -1460,7 +1459,7 @@ class DatabaseInterface implements DbalInterface
|
||||
|
||||
$hasGrantPrivilege = false;
|
||||
|
||||
if (Config::getInstance()->selectedServer['DisableIS']) {
|
||||
if ($this->config->selectedServer['DisableIS']) {
|
||||
$grants = $this->getCurrentUserGrants();
|
||||
|
||||
foreach ($grants as $grant) {
|
||||
@ -1496,7 +1495,7 @@ class DatabaseInterface implements DbalInterface
|
||||
|
||||
$hasCreatePrivilege = false;
|
||||
|
||||
if (Config::getInstance()->selectedServer['DisableIS']) {
|
||||
if ($this->config->selectedServer['DisableIS']) {
|
||||
$grants = $this->getCurrentUserGrants();
|
||||
|
||||
foreach ($grants as $grant) {
|
||||
@ -1875,7 +1874,7 @@ class DatabaseInterface implements DbalInterface
|
||||
*/
|
||||
public function getDbCollation(string $db): string
|
||||
{
|
||||
if (! Config::getInstance()->selectedServer['DisableIS']) {
|
||||
if (! $this->config->selectedServer['DisableIS']) {
|
||||
// this is slow with thousands of databases
|
||||
$sql = 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA'
|
||||
. ' WHERE SCHEMA_NAME = ' . $this->quoteString($db)
|
||||
@ -1972,7 +1971,7 @@ class DatabaseInterface implements DbalInterface
|
||||
public function getDatabaseList(): ListDatabase
|
||||
{
|
||||
if ($this->databaseList === null) {
|
||||
$this->databaseList = new ListDatabase($this, Config::getInstance(), new UserPrivilegesFactory($this));
|
||||
$this->databaseList = new ListDatabase($this, $this->config, new UserPrivilegesFactory($this));
|
||||
}
|
||||
|
||||
return $this->databaseList;
|
||||
|
||||
16
src/File.php
16
src/File.php
@ -79,10 +79,12 @@ class File
|
||||
protected string $charset = '';
|
||||
|
||||
private ZipExtension $zipExtension;
|
||||
private readonly Config $config;
|
||||
|
||||
/** @param bool|string $name file name or false */
|
||||
public function __construct(bool|string $name = false)
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
if ($name && is_string($name)) {
|
||||
$this->setName($name);
|
||||
}
|
||||
@ -399,13 +401,12 @@ class File
|
||||
*/
|
||||
public function setLocalSelectedFile(string $name): bool
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
if ($config->settings['UploadDir'] === '') {
|
||||
if ($this->config->settings['UploadDir'] === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setName(
|
||||
Util::userDir($config->settings['UploadDir']) . Core::securePath($name),
|
||||
Util::userDir($this->config->settings['UploadDir']) . Core::securePath($name),
|
||||
);
|
||||
if (@is_link((string) $this->getName())) {
|
||||
$this->errorMessage = Message::error(__('File is a symbolic link'));
|
||||
@ -447,7 +448,7 @@ class File
|
||||
return true;
|
||||
}
|
||||
|
||||
$tmpSubdir = Config::getInstance()->getUploadTempDir();
|
||||
$tmpSubdir = $this->config->getUploadTempDir();
|
||||
if ($tmpSubdir === null) {
|
||||
// cannot create directory or access, point user to FAQ 1.11
|
||||
$this->errorMessage = Message::error(__(
|
||||
@ -574,13 +575,12 @@ class File
|
||||
$this->handle = @fopen((string) $this->getName(), 'r');
|
||||
}
|
||||
|
||||
$config = Config::getInstance();
|
||||
switch ($this->getCompression()) {
|
||||
case false:
|
||||
return false;
|
||||
|
||||
case 'application/bzip2':
|
||||
if (! $config->settings['BZipDump'] || ! function_exists('bzopen')) {
|
||||
if (! $this->config->settings['BZipDump'] || ! function_exists('bzopen')) {
|
||||
$this->errorUnsupported();
|
||||
|
||||
return false;
|
||||
@ -589,7 +589,7 @@ class File
|
||||
$this->handle = @bzopen($this->getName(), 'r');
|
||||
break;
|
||||
case 'application/gzip':
|
||||
if (! $config->settings['GZipDump'] || ! function_exists('gzopen')) {
|
||||
if (! $this->config->settings['GZipDump'] || ! function_exists('gzopen')) {
|
||||
$this->errorUnsupported();
|
||||
|
||||
return false;
|
||||
@ -598,7 +598,7 @@ class File
|
||||
$this->handle = @gzopen((string) $this->getName(), 'r');
|
||||
break;
|
||||
case 'application/zip':
|
||||
if ($config->settings['ZipDump'] && function_exists('zip_open')) {
|
||||
if ($this->config->settings['ZipDump'] && function_exists('zip_open')) {
|
||||
return $this->openZip();
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,13 @@ use function str_ends_with;
|
||||
*/
|
||||
class FileListing
|
||||
{
|
||||
private readonly Config $config;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of filtered file names
|
||||
*
|
||||
@ -96,12 +103,11 @@ class FileListing
|
||||
{
|
||||
$compressions = '';
|
||||
|
||||
$config = Config::getInstance();
|
||||
if ($config->settings['GZipDump'] && function_exists('gzopen')) {
|
||||
if ($this->config->settings['GZipDump'] && function_exists('gzopen')) {
|
||||
$compressions = 'gz';
|
||||
}
|
||||
|
||||
if ($config->settings['BZipDump'] && function_exists('bzopen')) {
|
||||
if ($this->config->settings['BZipDump'] && function_exists('bzopen')) {
|
||||
if ($compressions !== '') {
|
||||
$compressions .= '|';
|
||||
}
|
||||
@ -109,7 +115,7 @@ class FileListing
|
||||
$compressions .= 'bz2';
|
||||
}
|
||||
|
||||
if ($config->settings['ZipDump'] && function_exists('gzinflate')) {
|
||||
if ($this->config->settings['ZipDump'] && function_exists('gzinflate')) {
|
||||
if ($compressions !== '') {
|
||||
$compressions .= '|';
|
||||
}
|
||||
|
||||
@ -28,6 +28,13 @@ use function substr_replace;
|
||||
*/
|
||||
class IpAllowDeny
|
||||
{
|
||||
private readonly Config $config;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches for IPv4 or IPv6 addresses
|
||||
*
|
||||
@ -241,12 +248,11 @@ class IpAllowDeny
|
||||
return false;
|
||||
}
|
||||
|
||||
$config = Config::getInstance();
|
||||
// copy username
|
||||
$username = $config->selectedServer['user'];
|
||||
$username = $this->config->selectedServer['user'];
|
||||
|
||||
// copy rule database
|
||||
$rules = $config->selectedServer['AllowDeny']['rules'];
|
||||
$rules = $this->config->selectedServer['AllowDeny']['rules'];
|
||||
|
||||
// lookup table for some name shortcuts
|
||||
$shortcuts = ['all' => '0.0.0.0/0', 'localhost' => '127.0.0.1/8'];
|
||||
|
||||
@ -724,6 +724,12 @@ class LanguageManager
|
||||
|
||||
/** @psalm-var 'ltr'|'rtl' */
|
||||
public static string $textDir = 'ltr';
|
||||
private readonly Config $config;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns LanguageManager singleton
|
||||
@ -785,12 +791,11 @@ class LanguageManager
|
||||
public function availableLocales(): array
|
||||
{
|
||||
if ($this->availableLocales === []) {
|
||||
$config = Config::getInstance();
|
||||
if (empty($config->get('FilterLanguages'))) {
|
||||
if (empty($this->config->get('FilterLanguages'))) {
|
||||
$this->availableLocales = $this->listLocaleDir();
|
||||
} else {
|
||||
$this->availableLocales = preg_grep(
|
||||
'@' . $config->get('FilterLanguages') . '@',
|
||||
'@' . $this->config->get('FilterLanguages') . '@',
|
||||
$this->listLocaleDir(),
|
||||
);
|
||||
}
|
||||
@ -873,9 +878,8 @@ class LanguageManager
|
||||
public function selectLanguage(): Language
|
||||
{
|
||||
// check forced language
|
||||
$config = Config::getInstance();
|
||||
if (! empty($config->get('Lang'))) {
|
||||
$lang = $this->getLanguage($config->get('Lang'));
|
||||
if (! empty($this->config->get('Lang'))) {
|
||||
$lang = $this->getLanguage($this->config->get('Lang'));
|
||||
if ($lang !== false) {
|
||||
return $lang;
|
||||
}
|
||||
@ -905,8 +909,8 @@ class LanguageManager
|
||||
}
|
||||
|
||||
// check previous set language
|
||||
if (! empty($config->getCookie('pma_lang'))) {
|
||||
$lang = $this->getLanguage($config->getCookie('pma_lang'));
|
||||
if (! empty($this->config->getCookie('pma_lang'))) {
|
||||
$lang = $this->getLanguage($this->config->getCookie('pma_lang'));
|
||||
if ($lang !== false) {
|
||||
return $lang;
|
||||
}
|
||||
@ -939,7 +943,7 @@ class LanguageManager
|
||||
}
|
||||
|
||||
// Fallback to English
|
||||
return $langs[$config->get('DefaultLang')] ?? $langs['en'];
|
||||
return $langs[$this->config->get('DefaultLang')] ?? $langs['en'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -32,12 +32,15 @@ use function trim;
|
||||
*/
|
||||
class Normalization
|
||||
{
|
||||
private readonly Config $config;
|
||||
|
||||
public function __construct(
|
||||
private DatabaseInterface $dbi,
|
||||
private Relation $relation,
|
||||
private Transformations $transformations,
|
||||
public Template $template,
|
||||
) {
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,8 +122,7 @@ class Normalization
|
||||
$contentCells = [];
|
||||
$availableMime = [];
|
||||
$mimeMap = [];
|
||||
$config = Config::getInstance();
|
||||
if ($relationParameters->browserTransformationFeature !== null && $config->settings['BrowseMIME']) {
|
||||
if ($relationParameters->browserTransformationFeature !== null && $this->config->settings['BrowseMIME']) {
|
||||
$mimeMap = $this->transformations->getMime($db, $table);
|
||||
$availableMime = $this->transformations->getAvailableMimeTypes();
|
||||
}
|
||||
@ -145,8 +147,8 @@ class Normalization
|
||||
];
|
||||
}
|
||||
|
||||
$charsets = Charsets::getCharsets($this->dbi, $config->selectedServer['DisableIS']);
|
||||
$collations = Charsets::getCollations($this->dbi, $config->selectedServer['DisableIS']);
|
||||
$charsets = Charsets::getCharsets($this->dbi, $this->config->selectedServer['DisableIS']);
|
||||
$collations = Charsets::getCollations($this->dbi, $this->config->selectedServer['DisableIS']);
|
||||
$charsetsList = [];
|
||||
foreach ($charsets as $charset) {
|
||||
$collationsList = [];
|
||||
@ -168,13 +170,13 @@ class Normalization
|
||||
'content_cells' => $contentCells,
|
||||
'change_column' => $_POST['change_column'] ?? $_GET['change_column'] ?? null,
|
||||
'is_virtual_columns_supported' => Compatibility::isVirtualColumnsSupported($this->dbi->getVersion()),
|
||||
'browse_mime' => $config->settings['BrowseMIME'],
|
||||
'browse_mime' => $this->config->settings['BrowseMIME'],
|
||||
'supports_stored_keyword' => Compatibility::supportsStoredKeywordForVirtualColumns(
|
||||
$this->dbi->getVersion(),
|
||||
),
|
||||
'server_version' => $this->dbi->getVersion(),
|
||||
'max_rows' => intval($config->settings['MaxRows']),
|
||||
'char_editing' => $config->settings['CharEditing'],
|
||||
'max_rows' => intval($this->config->settings['MaxRows']),
|
||||
'char_editing' => $this->config->settings['CharEditing'],
|
||||
'attribute_types' => $this->dbi->types->getAttributes(),
|
||||
'privs_available' => $userPrivileges->column && $userPrivileges->isReload,
|
||||
'max_length' => $this->dbi->getVersion() >= 50503 ? 1024 : 255,
|
||||
|
||||
@ -143,19 +143,20 @@ class ResponseRenderer
|
||||
protected Response $response;
|
||||
|
||||
protected Template $template;
|
||||
protected Config $config;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->template = new Template();
|
||||
$dbi = DatabaseInterface::getInstance();
|
||||
$relation = new Relation($dbi);
|
||||
$config = Config::getInstance();
|
||||
$this->header = new Header(
|
||||
$this->template,
|
||||
new Console($relation, $this->template, new BookmarkRepository($dbi, $relation)),
|
||||
$config,
|
||||
$this->config,
|
||||
);
|
||||
$this->footer = new Footer($this->template, $config);
|
||||
$this->footer = new Footer($this->template, $this->config);
|
||||
$this->response = ResponseFactory::create()->createResponse();
|
||||
|
||||
$this->setAjax(! empty($_REQUEST['ajax_request']));
|
||||
@ -323,7 +324,7 @@ class ResponseRenderer
|
||||
// set current db, table and sql query in the querywindow
|
||||
// (this is for the bottom console)
|
||||
$query = '';
|
||||
$maxChars = Config::getInstance()->settings['MaxCharactersInDisplayedSQL'];
|
||||
$maxChars = $this->config->settings['MaxCharactersInDisplayedSQL'];
|
||||
if (isset($GLOBALS['sql_query']) && mb_strlen($GLOBALS['sql_query']) < $maxChars) {
|
||||
$query = $GLOBALS['sql_query'];
|
||||
}
|
||||
@ -440,7 +441,7 @@ class ResponseRenderer
|
||||
* like /phpmyadmin/index.php/ which some web servers happily accept.
|
||||
*/
|
||||
if (str_starts_with($url, '.')) {
|
||||
$url = Config::getInstance()->getRootPath() . substr($url, 2);
|
||||
$url = $this->config->getRootPath() . substr($url, 2);
|
||||
}
|
||||
|
||||
$this->addHeader('Location', $url);
|
||||
|
||||
@ -28,11 +28,14 @@ use function str_contains;
|
||||
*/
|
||||
class SqlQueryForm
|
||||
{
|
||||
private readonly Config $config;
|
||||
|
||||
public function __construct(
|
||||
private Template $template,
|
||||
private DatabaseInterface $dbi,
|
||||
private readonly BookmarkRepository $bookmarkRepository,
|
||||
) {
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,9 +91,8 @@ class SqlQueryForm
|
||||
$bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature;
|
||||
|
||||
$bookmarks = [];
|
||||
$config = Config::getInstance();
|
||||
if ($displayTab === 'full' && $bookmarkFeature !== null) {
|
||||
$bookmarkList = $this->bookmarkRepository->getList($config->selectedServer['user'], $db);
|
||||
$bookmarkList = $this->bookmarkRepository->getList($this->config->selectedServer['user'], $db);
|
||||
|
||||
foreach ($bookmarkList as $bookmarkItem) {
|
||||
$bookmarks[] = [
|
||||
@ -104,15 +106,15 @@ class SqlQueryForm
|
||||
|
||||
return $this->template->render('sql/query', [
|
||||
'legend' => $legend ?? '',
|
||||
'textarea_cols' => $config->settings['TextareaCols'],
|
||||
'textarea_rows' => $config->settings['TextareaRows'],
|
||||
'textarea_auto_select' => $config->settings['TextareaAutoSelect'],
|
||||
'textarea_cols' => $this->config->settings['TextareaCols'],
|
||||
'textarea_rows' => $this->config->settings['TextareaRows'],
|
||||
'textarea_auto_select' => $this->config->settings['TextareaAutoSelect'],
|
||||
'columns_list' => $columnsList ?? [],
|
||||
'codemirror_enable' => $config->settings['CodemirrorEnable'],
|
||||
'codemirror_enable' => $this->config->settings['CodemirrorEnable'],
|
||||
'has_bookmark' => $bookmarkFeature !== null,
|
||||
'delimiter' => $delimiter,
|
||||
'retain_query_box' => $config->settings['RetainQueryBox'] !== false,
|
||||
'is_upload' => $config->get('enable_upload'),
|
||||
'retain_query_box' => $this->config->settings['RetainQueryBox'] !== false,
|
||||
'is_upload' => $this->config->get('enable_upload'),
|
||||
'db' => $db,
|
||||
'table' => $table,
|
||||
'goto' => $goto,
|
||||
@ -121,7 +123,7 @@ class SqlQueryForm
|
||||
'bookmarks' => $bookmarks,
|
||||
'can_convert_kanji' => Encoding::canConvertKanji(),
|
||||
'is_foreign_key_check' => ForeignKey::isCheckEnabled(),
|
||||
'allow_shared_bookmarks' => $config->settings['AllowSharedBookmarks'],
|
||||
'allow_shared_bookmarks' => $this->config->settings['AllowSharedBookmarks'],
|
||||
]);
|
||||
}
|
||||
|
||||
@ -135,29 +137,28 @@ class SqlQueryForm
|
||||
public function init(string $query): array
|
||||
{
|
||||
$columnsList = [];
|
||||
$config = Config::getInstance();
|
||||
if (Current::$database === '') {
|
||||
// prepare for server related
|
||||
$legend = sprintf(
|
||||
__('Run SQL query/queries on server “%s”'),
|
||||
htmlspecialchars(
|
||||
! empty($config->settings['Servers'][Current::$server]['verbose'])
|
||||
? $config->settings['Servers'][Current::$server]['verbose']
|
||||
: $config->settings['Servers'][Current::$server]['host'],
|
||||
! empty($this->config->settings['Servers'][Current::$server]['verbose'])
|
||||
? $this->config->settings['Servers'][Current::$server]['verbose']
|
||||
: $this->config->settings['Servers'][Current::$server]['host'],
|
||||
),
|
||||
);
|
||||
} elseif (Current::$table === '') {
|
||||
// prepare for db related
|
||||
$db = Current::$database;
|
||||
// if you want navigation:
|
||||
$scriptName = Util::getScriptNameForOption($config->settings['DefaultTabDatabase'], 'database');
|
||||
$scriptName = Util::getScriptNameForOption($this->config->settings['DefaultTabDatabase'], 'database');
|
||||
$tmpDbLink = '<a href="' . $scriptName
|
||||
. Url::getCommon(['db' => $db], ! str_contains($scriptName, '?') ? '?' : '&')
|
||||
. '">';
|
||||
$tmpDbLink .= htmlspecialchars($db) . '</a>';
|
||||
$legend = sprintf(__('Run SQL query/queries on database %s'), $tmpDbLink);
|
||||
if ($query === '') {
|
||||
$query = Util::expandUserString($config->settings['DefaultQueryDatabase'], Util::backquote(...));
|
||||
$query = Util::expandUserString($this->config->settings['DefaultQueryDatabase'], Util::backquote(...));
|
||||
}
|
||||
} else {
|
||||
$db = Current::$database;
|
||||
@ -167,12 +168,12 @@ class SqlQueryForm
|
||||
// trying to synchronize and the table has not yet been created
|
||||
$columnsList = $this->dbi->getColumns($db, Current::$table, true);
|
||||
|
||||
$scriptName = Util::getScriptNameForOption($config->settings['DefaultTabTable'], 'table');
|
||||
$scriptName = Util::getScriptNameForOption($this->config->settings['DefaultTabTable'], 'table');
|
||||
$tmpTblLink = '<a href="' . $scriptName . Url::getCommon(['db' => $db, 'table' => $table], '&') . '">';
|
||||
$tmpTblLink .= htmlspecialchars($db) . '.' . htmlspecialchars($table) . '</a>';
|
||||
$legend = sprintf(__('Run SQL query/queries on table %s'), $tmpTblLink);
|
||||
if ($query === '') {
|
||||
$query = Util::expandUserString($config->settings['DefaultQueryTable'], Util::backquote(...));
|
||||
$query = Util::expandUserString($this->config->settings['DefaultQueryTable'], Util::backquote(...));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,11 +30,14 @@ use function urlencode;
|
||||
*/
|
||||
class UserPreferences
|
||||
{
|
||||
private readonly Config $config;
|
||||
|
||||
public function __construct(
|
||||
private readonly DatabaseInterface $dbi,
|
||||
private readonly Relation $relation,
|
||||
private readonly Template $template,
|
||||
) {
|
||||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +53,7 @@ class UserPreferences
|
||||
$cf->setCfgUpdateReadMapping(
|
||||
['Server/hide_db' => 'Servers/1/hide_db', 'Server/only_db' => 'Servers/1/only_db'],
|
||||
);
|
||||
$cf->updateWithGlobalConfig(Config::getInstance()->settings);
|
||||
$cf->updateWithGlobalConfig($this->config->settings);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +184,7 @@ class UserPreferences
|
||||
{
|
||||
$query = 'SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '
|
||||
. $this->dbi->quoteString($database->getName());
|
||||
if (Config::getInstance()->selectedServer['DisableIS']) {
|
||||
if ($this->config->selectedServer['DisableIS']) {
|
||||
$query = 'SHOW DATABASES LIKE '
|
||||
. $this->dbi->quoteString(
|
||||
$this->dbi->escapeMysqlWildcards($database->getName()),
|
||||
@ -202,7 +205,7 @@ class UserPreferences
|
||||
public function apply(array $configData): array
|
||||
{
|
||||
$cfg = [];
|
||||
$excludeList = array_flip(Config::getInstance()->settings['UserprefsDisallow']);
|
||||
$excludeList = array_flip($this->config->settings['UserprefsDisallow']);
|
||||
$allowList = array_flip(UserFormList::getFields());
|
||||
// allow some additional fields which are custom handled
|
||||
$allowList['ThemeDefault'] = true;
|
||||
|
||||
@ -52,8 +52,8 @@ class ResponseRenderer extends \PhpMyAdmin\ResponseRenderer
|
||||
|
||||
$GLOBALS['lang'] = 'en';
|
||||
$this->template = new Template();
|
||||
$config = Config::getInstance();
|
||||
$config->selectedServer['pmadb'] = 'phpmyadmin';
|
||||
$this->config = Config::getInstance();
|
||||
$this->config->selectedServer['pmadb'] = 'phpmyadmin';
|
||||
$dummyDbi = new DbiDummy();
|
||||
$dummyDbi->addSelectDb('phpmyadmin');
|
||||
$dbi = new DatabaseInterface($dummyDbi);
|
||||
@ -61,9 +61,9 @@ class ResponseRenderer extends \PhpMyAdmin\ResponseRenderer
|
||||
$this->header = new Header(
|
||||
$this->template,
|
||||
new Console($relation, $this->template, new BookmarkRepository($dbi, $relation)),
|
||||
$config,
|
||||
$this->config,
|
||||
);
|
||||
$this->footer = new Footer($this->template, $config);
|
||||
$this->footer = new Footer($this->template, $this->config);
|
||||
$this->response = ResponseFactory::create()->createResponse();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user