Skip to content

Commit 93a4d90

Browse files
Merge pull request #20436 from kamil-tekiela/PmaGlobalVariable
Remove PmaGlobalVariable class
2 parents 9e50819 + bacbb04 commit 93a4d90

4 files changed

Lines changed: 10 additions & 61 deletions

File tree

‎psalm-baseline.xml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8129,11 +8129,6 @@
81298129
<code><![CDATA[empty($_POST['item_timing'])]]></code>
81308130
</RiskyTruthyFalsyComparison>
81318131
</file>
8132-
<file src="src/Twig/PmaGlobalVariable.php">
8133-
<UnusedParam>
8134-
<code><![CDATA[$arguments]]></code>
8135-
</UnusedParam>
8136-
</file>
81378132
<file src="src/TwoFactor.php">
81388133
<DeprecatedMethod>
81398134
<code><![CDATA[Config::getInstance()]]></code>

‎src/Template.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use PhpMyAdmin\Container\ContainerBuilder;
88
use PhpMyAdmin\Html\Generator;
99
use PhpMyAdmin\Html\MySQLDocumentation;
10+
use PhpMyAdmin\I18n\LanguageManager;
1011
use PhpMyAdmin\Theme\ThemeManager;
1112
use PhpMyAdmin\Twig\I18nExtension;
1213
use PhpMyAdmin\Twig\MessageExtension;
13-
use PhpMyAdmin\Twig\PmaGlobalVariable;
1414
use PhpMyAdmin\Utils\Gis;
1515
use RuntimeException;
1616
use Throwable;
@@ -61,7 +61,10 @@ public static function getTwigEnvironment(string|null $cacheDir, bool $isDevEnv)
6161
$twig->disableStrictVariables();
6262
}
6363

64-
$twig->addGlobal('pma', new PmaGlobalVariable());
64+
$twig->addGlobal('pma', [
65+
'version' => Version::VERSION,
66+
'text_dir' => LanguageManager::$textDirection->value,
67+
]);
6568
$twig->addExtension(new AttributeExtension(Core::class));
6669
$twig->addExtension(new AttributeExtension(FlashMessenger::class));
6770
$twig->addExtension(new AttributeExtension(Generator::class));

‎src/Twig/PmaGlobalVariable.php‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎tests/unit/Twig/PmaGlobalVariableTest.php‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
use PhpMyAdmin\I18n\TextDirection;
1010
use PhpMyAdmin\Template;
1111
use PhpMyAdmin\Tests\AbstractTestCase;
12-
use PhpMyAdmin\Twig\PmaGlobalVariable;
1312
use PhpMyAdmin\Version;
1413
use PHPUnit\Framework\Attributes\CoversClass;
1514
use ReflectionProperty;
16-
use RuntimeException;
1715
use Twig\Error\RuntimeError;
1816
use Twig\Loader\FilesystemLoader;
1917

20-
#[CoversClass(PmaGlobalVariable::class)]
18+
#[CoversClass(Template::class)]
2119
final class PmaGlobalVariableTest extends AbstractTestCase
2220
{
2321
protected function setUp(): void
@@ -36,32 +34,13 @@ protected function tearDown(): void
3634
(new ReflectionProperty(Template::class, 'twig'))->setValue(null, null);
3735
}
3836

39-
public function testUndefinedVariable(): void
40-
{
41-
self::expectException(RuntimeException::class);
42-
self::expectExceptionMessage('The "pma.undefined_variable" variable is not available.');
43-
/**
44-
* @psalm-suppress UndefinedMagicMethod
45-
* @phpstan-ignore-next-line
46-
*/
47-
(new PmaGlobalVariable())->undefined_variable();
48-
}
49-
50-
public function testVersion(): void
51-
{
52-
self::assertSame(Version::VERSION, (new PmaGlobalVariable())->version());
53-
}
54-
55-
public function testTextDir(): void
56-
{
57-
LanguageManager::$textDirection = TextDirection::LeftToRight;
58-
self::assertSame('ltr', (new PmaGlobalVariable())->text_dir());
59-
}
60-
6137
public function testUndefinedVariableFromTwig(): void
6238
{
6339
self::expectException(RuntimeError::class);
64-
self::expectExceptionMessage('The "pma.undefined_variable" variable is not available.');
40+
self::expectExceptionMessage(
41+
'Key "undefined_variable" for sequence/mapping with keys "version, text_dir" does not exist'
42+
. ' in "pma_global_variable/undefined_variable.twig" at line 1.',
43+
);
6544
(new Template(new Config()))->render('pma_global_variable/undefined_variable', []);
6645
}
6746

0 commit comments

Comments
 (0)