jikan-rest/app/Support/helpers.php
2023-07-09 10:50:18 +01:00

71 lines
1.7 KiB
PHP

<?php
// note: some of these are required for packages which are not entirely compatible with "lumen".
// exact copy of "config_path" from laravel framework -- we want to make it available in lumen
if (!function_exists("config_path")) {
/**
* Get the configuration path.
*
* @param string $path
* @return string
*/
function config_path(string $path = ""): string
{
return app()->configPath($path);
}
}
// exact copy of "rescue" from laravel framework -- we want to make it available in lumen
if (!function_exists('rescue')) {
/**
* Catch a potential exception and return a default value.
*
* @param callable $callback
* @param mixed $rescue
* @param bool|callable $report
* @return mixed
*/
function rescue(callable $callback, mixed $rescue = null, bool|callable $report = true): mixed
{
try {
return $callback();
} catch (Throwable $e) {
if (value($report, $e)) {
report($e);
}
return value($rescue, $e);
}
}
}
if (!function_exists('to_boolean')) {
/**
* Convert to boolean
*
* @param $booleable
* @return boolean
*/
function to_boolean($booleable): bool
{
return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
}
if (!function_exists('max_results_per_page')) {
function max_results_per_page(?int $fallbackLimit = null): int
{
return app()->make("jikan-config")->maxResultsPerPage($fallbackLimit);
}
}
if (!function_exists('text_match_buckets')) {
function text_match_buckets(): int
{
return app()->make("jikan-config")->textMatchBuckets();
}
}