2023-01-02 16:29:05 +00:00
|
|
|
<?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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-30 20:41:39 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-28 16:43:11 +01:00
|
|
|
|
|
|
|
if (!function_exists('max_results_per_page')) {
|
|
|
|
function max_results_per_page(?int $fallbackLimit = null): int
|
|
|
|
{
|
|
|
|
return app()->make("jikan-config")->maxResultsPerPage($fallbackLimit);
|
|
|
|
}
|
|
|
|
}
|
2023-07-09 10:50:18 +01:00
|
|
|
|
|
|
|
if (!function_exists('text_match_buckets')) {
|
|
|
|
function text_match_buckets(): int
|
|
|
|
{
|
|
|
|
return app()->make("jikan-config")->textMatchBuckets();
|
|
|
|
}
|
|
|
|
}
|