Skip to content

Commit

Permalink
REX_VAR-Klassen können explizit registriert werden
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed May 12, 2024
1 parent 93c0bfb commit dde253e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions redaxo/src/core/lib/var/var.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ abstract class rex_var

private static int $variableIndex = 0;

/**
* @param string $name Name must start with "REX_"
* @param class-string<self> $class
*/
public static function register(string $name, string $class): void
{
self::$vars[$name] = $class;
}

/**
* Parses all REX_VARs in the given content.
*
Expand Down
7 changes: 7 additions & 0 deletions redaxo/src/core/tests/var/var_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<?php echo rex_var::toArray("REX_TEST_VAR[content=\'test\']") === null ? "null" : "";';
Expand Down

0 comments on commit dde253e

Please sign in to comment.