Add helpers kvp() and kvp_save() (#966)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Exceptions\SettingNotFound;
|
use App\Exceptions\SettingNotFound;
|
||||||
|
use App\Repositories\KvpRepository;
|
||||||
use App\Repositories\SettingRepository;
|
use App\Repositories\SettingRepository;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Contracts\View\Factory;
|
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
|
* Wrap the asset URL in the publicBaseUrl that's been
|
||||||
* set
|
* set
|
||||||
|
|||||||
Reference in New Issue
Block a user