From 8adb302a68e6ca021c242b273d0bc61c3cb29303 Mon Sep 17 00:00:00 2001 From: pushrbx Date: Fri, 19 Jan 2024 21:48:19 +0000 Subject: [PATCH] added extra helpers --- app/Support/helpers.php | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/app/Support/helpers.php b/app/Support/helpers.php index a25471e..dc9094d 100644 --- a/app/Support/helpers.php +++ b/app/Support/helpers.php @@ -68,3 +68,49 @@ if (!function_exists('text_match_buckets')) { 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); + } +}