Add helpers kvp() and kvp_save() (#966)

This commit is contained in:
Nabeel S
2020-12-21 11:30:44 -05:00
committed by GitHub
parent a5513b6fbb
commit 4bda494c6b

View File

@@ -1,6 +1,7 @@
<?php
use App\Exceptions\SettingNotFound;
use App\Repositories\KvpRepository;
use App\Repositories\SettingRepository;
use Carbon\Carbon;
use Illuminate\Contracts\View\Factory;
@@ -186,6 +187,53 @@ if (!function_exists('setting_save')) {
}
}
/*
* Shortcut for retrieving a KVP
*/
if (!function_exists('kvp')) {
/**
* Read a setting from the KVP repository
*
* @param string $key
* @param string|null $default
*
* @return mixed|null
*/
function kvp(string $key, $default = null)
{
/** @var KvpRepository $kvpRepo */
$kvpRepo = app(KvpRepository::class);
try {
$value = $kvpRepo->get($key, $default);
} catch (Exception $e) {
return $default;
}
return $value;
}
}
/*
* Shortcut for retrieving a KVP
*/
if (!function_exists('kvp_save')) {
/**
* Read a setting from the KVP repository
*
* @param string $key
* @param string $value
*
* @return mixed|null
*/
function kvp_save(string $key, string $value)
{
/** @var KvpRepository $kvpRepo */
$kvpRepo = app(KvpRepository::class);
$kvpRepo->save($key, $value);
}
}
/*
* Wrap the asset URL in the publicBaseUrl that's been
* set