Skip to content

Commit

Permalink
Add helpers kvp() and kvp_save() (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio authored Dec 21, 2020
1 parent a5513b6 commit 4bda494
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -186,6 +187,53 @@ function setting_save($key, $value)
}
}

/*
* 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
Expand Down

0 comments on commit 4bda494

Please sign in to comment.