Be more permissive about null values passed to lang() and Context::getLang()

This commit is contained in:
Kijin Sung 2023-12-18 21:19:33 +09:00
parent 14449dff9d
commit 6e2bab02cc
2 changed files with 4 additions and 4 deletions

View file

@ -856,7 +856,7 @@ class Context
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common'); $GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
} }
return $GLOBALS['lang']->get($code); return $code ? $GLOBALS['lang']->get((string)$code) : (string)$code;
} }
/** /**

View file

@ -32,7 +32,7 @@ function config(string $key, $value = null)
* @param string $value `$code`s value * @param string $value `$code`s value
* @return string|null|\ArrayObject * @return string|null|\ArrayObject
*/ */
function lang(string $code, $value = null) function lang(?string $code, $value = null)
{ {
if (!isset($GLOBALS['lang']) || !$GLOBALS['lang'] instanceof Rhymix\Framework\Lang) if (!isset($GLOBALS['lang']) || !$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
{ {
@ -42,9 +42,9 @@ function lang(string $code, $value = null)
if ($value === null) if ($value === null)
{ {
return $GLOBALS['lang']->get($code); return $GLOBALS['lang']->get($code ?? '');
} }
else elseif ($code !== null)
{ {
$GLOBALS['lang']->set($code, $value); $GLOBALS['lang']->set($code, $value);
} }