Skip to content

Commit

Permalink
type rex_var (#5432)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 1, 2022
1 parent f74b19d commit cf8c355
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 0 additions & 5 deletions .tools/phpstan/baseline.neon
Expand Up @@ -4190,11 +4190,6 @@ parameters:
count: 1
path: ../../redaxo/src/core/lib/util/validator.php

-
message: "#^Method rex_var\\:\\:getMatches\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../redaxo/src/core/lib/var/var.php

-
message: "#^Method rex_var\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
14 changes: 9 additions & 5 deletions redaxo/src/core/lib/var/var.php
Expand Up @@ -12,6 +12,10 @@ abstract class rex_var
public const ENV_INPUT = 4;
public const ENV_OUTPUT = 8;

private const PLACEHOLDER_BRACKET_OPEN = '@@@OPEN_BRACKET@@@';
private const PLACEHOLDER_BRACKET_CLOSE = '@@@CLOSE_BRACKET@@@';
private const PLACEHOLDER_INLINE_HTML = '@@@INLINE_HTML_REPLACEMENT_END@@@';

/** @var array<string, class-string<self>> */
private static $vars = [];

Expand Down Expand Up @@ -72,9 +76,9 @@ public static function parse($content, $env = null, $context = null, $contextDat
$add = $token[1];
switch ($token[0]) {
case T_INLINE_HTML:
$format = '<?= %s@@@INLINE_HTML_REPLACEMENT_END@@@';
$format = '<?= %s'.self::PLACEHOLDER_INLINE_HTML;
$add = self::replaceVars($add, $format);
$add = preg_replace_callback('/@@@INLINE_HTML_REPLACEMENT_END@@@(\r?\n?)/', static function (array $match) {
$add = preg_replace_callback('/'. self::PLACEHOLDER_INLINE_HTML .'(\r?\n?)/', static function (array $match) {
return $match[1]
? ', "'.addcslashes($match[1], "\r\n").'" ?>'.$match[1]
: ' ?>';
Expand Down Expand Up @@ -176,7 +180,7 @@ private static function replaceVars($content, $format = '%s', $useVariables = fa
$replaced = false;

if (null !== $var) {
$args = str_replace(['\[', '\]'], ['@@@OPEN_BRACKET@@@', '@@@CLOSE_BRACKET@@@'], $match[2]);
$args = str_replace(['\[', '\]'], [self::PLACEHOLDER_BRACKET_OPEN, self::PLACEHOLDER_BRACKET_CLOSE], $match[2]);
if ($stripslashes) {
$args = str_replace(['\\' . $stripslashes, '\\' . $stripslashes], $stripslashes, $args);
}
Expand Down Expand Up @@ -216,7 +220,7 @@ private static function replaceVars($content, $format = '%s', $useVariables = fa
*
* @param string $content
*
* @return array
* @return list<array<array-key, string>>
*/
private static function getMatches($content)
{
Expand Down Expand Up @@ -296,7 +300,7 @@ protected function getParsedArg($key, $default = null, $defaultArg = false)
$arg = preg_replace_callback("@$begin(.*)$end@Us", static function ($match) {
return addcslashes($match[1], "\'");
}, $arg);
$arg = str_replace(['@@@OPEN_BRACKET@@@', '@@@CLOSE_BRACKET@@@'], ['[', ']'], $arg);
$arg = str_replace([self::PLACEHOLDER_BRACKET_OPEN, self::PLACEHOLDER_BRACKET_CLOSE], ['[', ']'], $arg);
return is_numeric($arg) ? $arg : "'$arg'";
}

Expand Down

0 comments on commit cf8c355

Please sign in to comment.