forked from mirrors/easyappointments
Added the js_config helper method that will assign public JS config values
This commit is contained in:
parent
9c44b8644f
commit
29b22ece3c
1 changed files with 48 additions and 1 deletions
|
@ -55,3 +55,50 @@ function config($key, $default = NULL)
|
|||
|
||||
return $value ?? $default;
|
||||
}
|
||||
|
||||
if ( ! function_exists('js_config'))
|
||||
{
|
||||
/**
|
||||
* Get / set the specified JS config value.
|
||||
*
|
||||
* If an array is passed as the key, we will assume you want to set an array of values.
|
||||
*
|
||||
* Example "Get":
|
||||
*
|
||||
* $version = js_config('version', '1.0.0');
|
||||
*
|
||||
* Example "Set":
|
||||
*
|
||||
* js_config(['version' => '1.0.0']);
|
||||
*
|
||||
* @param array|string $key Configuration key.
|
||||
* @param mixed $default Default value in case the requested config has no value.
|
||||
*
|
||||
* @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
function js_config($key = NULL, $default = NULL)
|
||||
{
|
||||
$js_config = config('js_config', []);
|
||||
|
||||
if (empty($key))
|
||||
{
|
||||
return $js_config;
|
||||
}
|
||||
|
||||
if (is_array($key))
|
||||
{
|
||||
foreach ($key as $item => $value)
|
||||
{
|
||||
$js_config[$item] = $value;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$value = $js_config[$key];
|
||||
|
||||
return $value ?? $default;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue