Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 2, 2023
1 parent 49894ef commit 7b340be
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/DI/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static function expand($var, array $params, $recursive = false)
: $params;

} elseif (is_string($var)) {
$recursive = is_array($recursive) ? $recursive : ($recursive ? [] : null);
return self::expandString($var, $params, $recursive);

} else {
Expand All @@ -64,7 +65,7 @@ public static function expand($var, array $params, $recursive = false)
* Expands %placeholders% in string
* @throws Nette\InvalidArgumentException
*/
private static function expandString(string $var, array $params, $recursive, bool $onlyString = false)
private static function expandString(string $var, array $params, ?array $recursive, bool $onlyString = false)
{
$parts = preg_split('#%([\w.-]*)%#i', $var, -1, PREG_SPLIT_DELIM_CAPTURE);
$res = [];
Expand All @@ -85,8 +86,7 @@ private static function expandString(string $var, array $params, $recursive, boo
if (is_array($val) && array_key_exists($key, $val)) {
$val = $val[$key];
$fullExpand = !$onlyString && ($n2 === count($keys) - 1); // last
if ($recursive && ($fullExpand || is_string($val))) {
$recursive = is_array($recursive) ? $recursive : [];
if (is_array($recursive) && ($fullExpand || is_string($val))) {
if (isset($recursive[$path])) {
throw new Nette\InvalidArgumentException('Circular reference detected for parameters: %' . implode('%, %', array_keys($recursive)) . '%');
}
Expand Down

0 comments on commit 7b340be

Please sign in to comment.