added extra helpers

This commit is contained in:
pushrbx 2024-01-19 21:48:19 +00:00 committed by GitHub
parent bb71a7a9eb
commit 8adb302a68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,3 +68,49 @@ if (!function_exists('text_match_buckets')) {
return app()->make("jikan-config")->textMatchBuckets(); return app()->make("jikan-config")->textMatchBuckets();
} }
} }
if (!function_exists('app_path')) {
/**
* Get the path to the application folder.
*
* @param string $path
* @return string
*/
function app_path(?string $path = ""): string {
if ($path == "") {
return base_path('app');
}
return base_path('app/' . $path);
}
}
if (! function_exists('cache')) {
/**
* Get / set the specified cache value.
*
* If an array is passed, we'll assume you want to put to the cache.
*
* @param mixed ...$arguments key|key,default|data,expiration|null
* @return mixed|\Illuminate\Cache\CacheManager
*
* @throws \InvalidArgumentException
*/
function cache(...$arguments)
{
if (empty($arguments)) {
return app('cache');
}
if (is_string($arguments[0])) {
return app('cache')->get(...$arguments);
}
if (! is_array($arguments[0])) {
throw new InvalidArgumentException(
'When setting a value in the cache, you must pass an array of key / value pairs.'
);
}
return app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1] ?? null);
}
}