Skip to content

Commit 646b4ff

Browse files
Merge pull request #18793 from MauricioFauth/theme-global
Remove theme global variable
2 parents 4c382d3 + 5f092a8 commit 646b4ff

69 files changed

Lines changed: 55 additions & 222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/services.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
],
7979
'browse_foreigners' => [
8080
'class' => BrowseForeigners::class,
81-
'arguments' => ['@template', '@config'],
81+
'arguments' => ['@template', '@config', '@' . ThemeManager::class],
8282
],
8383
'config' => ['class' => Config::class, 'factory' => [Config::class, 'getInstance']],
8484
Config\PageSettings::class => ['class' => Config\PageSettings::class, 'arguments' => ['@user_preferences']],

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21110,11 +21110,6 @@ parameters:
2111021110
count: 1
2111121111
path: test/classes/Theme/ThemeTest.php
2111221112

21113-
-
21114-
message: "#^Property PhpMyAdmin\\\\Tests\\\\Theme\\\\ThemeTest\\:\\:\\$backup \\(PhpMyAdmin\\\\Theme\\\\Theme\\) does not accept mixed\\.$#"
21115-
count: 1
21116-
path: test/classes/Theme/ThemeTest.php
21117-
2111821113
-
2111921114
message: "#^Property PhpMyAdmin\\\\Config\\:\\:\\$selectedServer \\(array\\{host\\: string, port\\: string, socket\\: string, ssl\\: bool, ssl_key\\: string\\|null, ssl_cert\\: string\\|null, ssl_ca\\: string\\|null, ssl_ca_path\\: string\\|null, \\.\\.\\.\\}\\) does not accept array\\{host\\: string, port\\: string, socket\\: string, ssl\\: bool, ssl_key\\: string\\|null, ssl_cert\\: string\\|null, ssl_ca\\: string\\|null, ssl_ca_path\\: string\\|null, \\.\\.\\.\\}\\.$#"
2112021115
count: 4

psalm-baseline.xml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@
7474
</PossiblyNullArgument>
7575
</file>
7676
<file src="src/BrowseForeigners.php">
77-
<InvalidArrayOffset>
78-
<code><![CDATA[$GLOBALS['theme']]]></code>
79-
</InvalidArrayOffset>
8077
<MixedArgument>
8178
<code>$descriptions[$indexByDescription]</code>
8279
<code>$descriptions[$indexByKeyname]</code>
@@ -93,7 +90,6 @@
9390
<code><![CDATA[$relrow[$foreignData['foreign_field']]]]></code>
9491
</MixedArrayOffset>
9592
<MixedAssignment>
96-
<code><![CDATA[$GLOBALS['theme']]]></code>
9793
<code>$descriptions[]</code>
9894
<code>$keys[]</code>
9995
<code>$leftKeyname</code>
@@ -5521,7 +5517,6 @@
55215517
<InvalidArrayOffset>
55225518
<code><![CDATA[$GLOBALS['is_header_sent']]]></code>
55235519
<code><![CDATA[$GLOBALS['row']]]></code>
5524-
<code><![CDATA[$GLOBALS['theme']]]></code>
55255520
<code>$delUrlParams</code>
55265521
</InvalidArrayOffset>
55275522
<InvalidReturnStatement>
@@ -5691,7 +5686,6 @@
56915686
</MixedArrayTypeCoercion>
56925687
<MixedAssignment>
56935688
<code><![CDATA[$GLOBALS['row']]]></code>
5694-
<code><![CDATA[$GLOBALS['theme']]]></code>
56955689
<code><![CDATA[$_SESSION['tmpval']['geoOption']]]></code>
56965690
<code><![CDATA[$_SESSION['tmpval']['max_rows']]]></code>
56975691
<code><![CDATA[$_SESSION['tmpval']['pftext']]]></code>
@@ -6610,11 +6604,9 @@
66106604
</DeprecatedMethod>
66116605
<InvalidArrayOffset>
66126606
<code><![CDATA[$GLOBALS['buffer_message']]]></code>
6613-
<code><![CDATA[$GLOBALS['theme']]]></code>
66146607
</InvalidArrayOffset>
66156608
<MixedAssignment>
66166609
<code><![CDATA[$GLOBALS['buffer_message']]]></code>
6617-
<code><![CDATA[$GLOBALS['theme']]]></code>
66186610
<code>$bufferMessage</code>
66196611
<code>$pftext</code>
66206612
</MixedAssignment>
@@ -7290,12 +7282,6 @@
72907282
<code>Config::getInstance()</code>
72917283
<code>Config::getInstance()</code>
72927284
</DeprecatedMethod>
7293-
<InvalidArrayOffset>
7294-
<code><![CDATA[$GLOBALS['theme']]]></code>
7295-
</InvalidArrayOffset>
7296-
<MixedAssignment>
7297-
<code><![CDATA[$GLOBALS['theme']]]></code>
7298-
</MixedAssignment>
72997285
<PossiblyNullArrayOffset>
73007286
<code>$hidden</code>
73017287
<code>$hidden</code>
@@ -12503,14 +12489,6 @@
1250312489
<code><![CDATA[$GLOBALS['errors']]]></code>
1250412490
</PossiblyUndefinedArrayOffset>
1250512491
</file>
12506-
<file src="src/Twig/AssetExtension.php">
12507-
<InvalidArrayOffset>
12508-
<code><![CDATA[$GLOBALS['theme']]]></code>
12509-
</InvalidArrayOffset>
12510-
<MixedAssignment>
12511-
<code><![CDATA[$GLOBALS['theme']]]></code>
12512-
</MixedAssignment>
12513-
</file>
1251412492
<file src="src/TwoFactor.php">
1251512493
<DeprecatedMethod>
1251612494
<code>Config::getInstance()</code>
@@ -15845,12 +15823,6 @@
1584515823
</RedundantCondition>
1584615824
</file>
1584715825
<file src="test/classes/Theme/ThemeTest.php">
15848-
<InvalidArrayOffset>
15849-
<code><![CDATA[$GLOBALS['theme']]]></code>
15850-
</InvalidArrayOffset>
15851-
<MixedAssignment>
15852-
<code><![CDATA[$this->backup]]></code>
15853-
</MixedAssignment>
1585415826
<PossiblyUnusedMethod>
1585515827
<code>providerForGetImgPath</code>
1585615828
</PossiblyUnusedMethod>

src/BrowseForeigners.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace PhpMyAdmin;
99

1010
use PhpMyAdmin\Config\Settings;
11-
use PhpMyAdmin\Theme\Theme;
11+
use PhpMyAdmin\Theme\ThemeManager;
1212

1313
use function __;
1414
use function array_keys;
@@ -27,7 +27,7 @@ class BrowseForeigners
2727
{
2828
private Settings $settings;
2929

30-
public function __construct(public Template $template, Config $config)
30+
public function __construct(public Template $template, Config $config, private readonly ThemeManager $themeManager)
3131
{
3232
$this->settings = $config->getSettings();
3333
}
@@ -54,8 +54,6 @@ private function getHtmlForOneKey(
5454
int $indexByDescription,
5555
string $currentValue,
5656
): array {
57-
$GLOBALS['theme'] ??= null;
58-
5957
$horizontalCount++;
6058
$output = '';
6159

@@ -106,7 +104,7 @@ private function getHtmlForOneKey(
106104
]);
107105

108106
$output .= '<td width="20%"><img src="'
109-
. ($GLOBALS['theme'] instanceof Theme ? $GLOBALS['theme']->getImgPath('spacer.png') : '')
107+
. $this->themeManager->theme->getImgPath('spacer.png')
110108
. '" alt="" width="1" height="1"></td>';
111109

112110
$output .= $this->template->render('table/browse_foreigners/column_element', [

src/Display/Results.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use PhpMyAdmin\StatementInfo;
2929
use PhpMyAdmin\Table;
3030
use PhpMyAdmin\Template;
31-
use PhpMyAdmin\Theme\Theme;
31+
use PhpMyAdmin\Theme\ThemeManager;
3232
use PhpMyAdmin\Transformations;
3333
use PhpMyAdmin\UniqueCondition;
3434
use PhpMyAdmin\Url;
@@ -1146,8 +1146,6 @@ private function getOptionsBlock(): array
11461146
*/
11471147
private function getFullOrPartialTextButtonOrLink(): string
11481148
{
1149-
$GLOBALS['theme'] ??= null;
1150-
11511149
$urlParamsFullText = [
11521150
'db' => $this->db,
11531151
'table' => $this->table,
@@ -1167,8 +1165,11 @@ private function getFullOrPartialTextButtonOrLink(): string
11671165
$urlParamsFullText['pftext'] = self::DISPLAY_FULL_TEXT;
11681166
}
11691167

1168+
/** @var ThemeManager $themeManager */
1169+
$themeManager = Core::getContainerBuilder()->get(ThemeManager::class);
1170+
11701171
$tmpImage = '<img class="fulltext" src="'
1171-
. ($GLOBALS['theme'] instanceof Theme ? $GLOBALS['theme']->getImgPath($tmpImageFile) : '')
1172+
. $themeManager->theme->getImgPath($tmpImageFile)
11721173
. '" alt="' . $tmpTxt . '" title="' . $tmpTxt . '">';
11731174

11741175
return Generator::linkOrButton(Url::getFromRoute('/sql'), $urlParamsFullText, $tmpImage);

src/Header.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PhpMyAdmin\ConfigStorage\Relation;
1111
use PhpMyAdmin\Html\Generator;
1212
use PhpMyAdmin\Navigation\Navigation;
13-
use PhpMyAdmin\Theme\Theme;
13+
use PhpMyAdmin\Theme\ThemeManager;
1414

1515
use function array_merge;
1616
use function defined;
@@ -255,8 +255,6 @@ public function disableWarnings(): void
255255
*/
256256
public function getDisplay(): string
257257
{
258-
$GLOBALS['theme'] ??= null;
259-
260258
if ($this->headerIsSent || ! $this->isEnabled) {
261259
return '';
262260
}
@@ -273,10 +271,11 @@ public function getDisplay(): string
273271
$this->sendHttpHeaders();
274272

275273
$baseDir = defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : '';
276-
$themePath = $GLOBALS['theme'] instanceof Theme ? $GLOBALS['theme']->getPath() : '';
277-
$themeColorMode = $GLOBALS['theme'] instanceof Theme ? $GLOBALS['theme']->getColorMode() : 'light';
278-
$themeColorModes = $GLOBALS['theme'] instanceof Theme ? $GLOBALS['theme']->getColorModes() : [];
279-
$themeId = $GLOBALS['theme'] instanceof Theme ? $GLOBALS['theme']->getId() : '';
274+
275+
/** @var ThemeManager $themeManager */
276+
$themeManager = Core::getContainerBuilder()->get(ThemeManager::class);
277+
$theme = $themeManager->theme;
278+
280279
$version = self::getVersionParameter();
281280

282281
// The user preferences have been merged at this point
@@ -349,7 +348,7 @@ public function getDisplay(): string
349348
'lang' => $GLOBALS['lang'],
350349
'allow_third_party_framing' => $config->settings['AllowThirdPartyFraming'],
351350
'base_dir' => $baseDir,
352-
'theme_path' => $themePath,
351+
'theme_path' => $theme->getPath(),
353352
'version' => $version,
354353
'text_dir' => $GLOBALS['text_dir'],
355354
'server' => $GLOBALS['server'] ?? null,
@@ -367,9 +366,9 @@ public function getDisplay(): string
367366
'console' => $console,
368367
'messages' => $messages,
369368
'recent_table' => $recentTable,
370-
'theme_color_mode' => $themeColorMode,
371-
'theme_color_modes' => $themeColorModes,
372-
'theme_id' => $themeId,
369+
'theme_color_mode' => $theme->getColorMode(),
370+
'theme_color_modes' => $theme->getColorModes(),
371+
'theme_id' => $theme->getId(),
373372
]);
374373
}
375374

src/Http/Middleware/ThemeInitialization.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ final class ThemeInitialization implements MiddlewareInterface
1515
{
1616
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
1717
{
18-
$container = Core::getContainerBuilder();
1918
/** @var ThemeManager $themeManager */
20-
$themeManager = $container->get(ThemeManager::class);
21-
$GLOBALS['theme'] = $themeManager->initializeTheme();
19+
$themeManager = Core::getContainerBuilder()->get(ThemeManager::class);
20+
$themeManager->initializeTheme();
2221

2322
return $handler->handle($request);
2423
}

src/Navigation/Navigation.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
use PhpMyAdmin\Config;
1212
use PhpMyAdmin\Config\PageSettings;
1313
use PhpMyAdmin\ConfigStorage\Relation;
14+
use PhpMyAdmin\Core;
1415
use PhpMyAdmin\DatabaseInterface;
1516
use PhpMyAdmin\Dbal\Connection;
1617
use PhpMyAdmin\ResponseRenderer;
1718
use PhpMyAdmin\Sanitize;
1819
use PhpMyAdmin\Server\Select;
1920
use PhpMyAdmin\Template;
20-
use PhpMyAdmin\Theme\Theme;
21+
use PhpMyAdmin\Theme\ThemeManager;
2122
use PhpMyAdmin\Url;
2223
use PhpMyAdmin\UserPreferences;
2324
use PhpMyAdmin\Util;
@@ -254,16 +255,16 @@ private function getHiddenItems(string $database): array
254255
/** @return string Logo source */
255256
private function getLogoSource(): string
256257
{
257-
$GLOBALS['theme'] ??= null;
258+
/** @var ThemeManager $themeManager */
259+
$themeManager = Core::getContainerBuilder()->get(ThemeManager::class);
260+
$theme = $themeManager->theme;
258261

259-
if ($GLOBALS['theme'] instanceof Theme) {
260-
if (@file_exists($GLOBALS['theme']->getFsPath() . 'img/logo_left.png')) {
261-
return $GLOBALS['theme']->getPath() . '/img/logo_left.png';
262-
}
262+
if (@file_exists($theme->getFsPath() . 'img/logo_left.png')) {
263+
return $theme->getPath() . '/img/logo_left.png';
264+
}
263265

264-
if (@file_exists($GLOBALS['theme']->getFsPath() . 'img/pma_logo2.png')) {
265-
return $GLOBALS['theme']->getPath() . '/img/pma_logo2.png';
266-
}
266+
if (@file_exists($theme->getFsPath() . 'img/pma_logo2.png')) {
267+
return $theme->getPath() . '/img/pma_logo2.png';
267268
}
268269

269270
return '';

src/Theme/ThemeManager.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct()
6060
$this->theme = new Theme();
6161
}
6262

63-
public function initializeTheme(): Theme
63+
public function initializeTheme(): void
6464
{
6565
$config = Config::getInstance();
6666
$this->setThemePerServer($config->settings['ThemePerServer']);
@@ -91,12 +91,10 @@ public function initializeTheme(): Theme
9191
$this->theme->setColorMode($colorMode);
9292
}
9393

94-
return $this->theme;
94+
return;
9595
}
9696

9797
$this->setActiveTheme(self::FALLBACK_THEME);
98-
99-
return $this->theme;
10098
}
10199

102100
/**

src/Twig/AssetExtension.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
namespace PhpMyAdmin\Twig;
66

7-
use PhpMyAdmin\Theme\Theme;
7+
use PhpMyAdmin\Core;
8+
use PhpMyAdmin\Theme\ThemeManager;
89
use Twig\Extension\AbstractExtension;
910
use Twig\TwigFunction;
1011

1112
final class AssetExtension extends AbstractExtension
1213
{
14+
private ThemeManager|null $themeManager = null;
15+
1316
/** @return TwigFunction[] */
1417
public function getFunctions(): array
1518
{
@@ -18,12 +21,15 @@ public function getFunctions(): array
1821

1922
public function getImagePath(string|null $filename = null, string|null $fallback = null): string
2023
{
21-
$GLOBALS['theme'] ??= null;
24+
if ($this->themeManager === null) {
25+
$themeManager = Core::getContainerBuilder()->get(ThemeManager::class);
26+
if (! ($themeManager instanceof ThemeManager)) {
27+
return '';
28+
}
2229

23-
if (! $GLOBALS['theme'] instanceof Theme) {
24-
return '';
30+
$this->themeManager = $themeManager;
2531
}
2632

27-
return $GLOBALS['theme']->getImgPath($filename, $fallback);
33+
return $this->themeManager->theme->getImgPath($filename, $fallback);
2834
}
2935
}

0 commit comments

Comments
 (0)