From 39d1ee750467f47eed3596c4634a1becb1edac37 Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Sun, 12 May 2024 11:59:51 +0200 Subject: [PATCH] =?UTF-8?q?REX=5FVAR-Klassen=20k=C3=B6nnen=20explizit=20re?= =?UTF-8?q?gistriert=20werden=20(#6107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- redaxo/src/core/lib/var/var.php | 9 +++++++++ redaxo/src/core/tests/var/var_test.php | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/redaxo/src/core/lib/var/var.php b/redaxo/src/core/lib/var/var.php index 75f1335865..50a9a1693f 100644 --- a/redaxo/src/core/lib/var/var.php +++ b/redaxo/src/core/lib/var/var.php @@ -32,6 +32,15 @@ abstract class rex_var private static int $variableIndex = 0; + /** + * @param string $name Name must start with "REX_" + * @param class-string $class + */ + public static function register(string $name, string $class): void + { + self::$vars[$name] = $class; + } + /** * Parses all REX_VARs in the given content. * diff --git a/redaxo/src/core/tests/var/var_test.php b/redaxo/src/core/tests/var/var_test.php index bbc52c33b9..c096821980 100644 --- a/redaxo/src/core/tests/var/var_test.php +++ b/redaxo/src/core/tests/var/var_test.php @@ -161,6 +161,13 @@ public function testParseGlobalArgs(string $content, string $expectedOutput): vo $this->assertParseOutputEquals($expectedOutput, $content); } + public function testRegister(): void + { + rex_var::register('REX_3RD_TEST_VAR', rex_var_2nd_test_var::class); + + $this->assertParseOutputEquals('2', 'REX_3RD_TEST_VAR[]'); + } + public function testToArray(): void { $content = '