fixing syntax error in global functions
This commit is contained in:
parent
a1f677ff9b
commit
58a4701ba3
@ -36,7 +36,7 @@ if (! function_exists('humanBytes')) {
|
|||||||
static $bytePreceision = [0, 0, 1, 2];
|
static $bytePreceision = [0, 0, 1, 2];
|
||||||
$divisor = 1024;
|
$divisor = 1024;
|
||||||
|
|
||||||
for ($i = 0; $number / $divisor > = 0.9 && $i < 4; $i++) {
|
for ($i = 0; $number / $divisor >= 0.9 && $i < 4; $i++) {
|
||||||
$number /= $divisor;
|
$number /= $divisor;
|
||||||
}
|
}
|
||||||
return round($number, is_null($precision) ? $bytePreceision[$i] : $precision) . $units[$i];
|
return round($number, is_null($precision) ? $bytePreceision[$i] : $precision) . $units[$i];
|
||||||
@ -65,6 +65,53 @@ if (! function_exists('carbon')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('translations')) {
|
||||||
|
/**
|
||||||
|
* Loads translations from a JSON file.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @param string $jsonFilePath
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function translations(string $jsonFilePath): array
|
||||||
|
{
|
||||||
|
if (! file_exists($jsonFilePath)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = [];
|
||||||
|
$jsonData = json_decode(file_get_contents($jsonFilePath), true);
|
||||||
|
|
||||||
|
switch (json_last_error()) {
|
||||||
|
case JSON_ERROR_NONE:
|
||||||
|
$payload = $jsonData;
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_DEPTH:
|
||||||
|
throw new \Exception('Maximum stack depth exceeded');
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_STATE_MISMATCH:
|
||||||
|
throw new \Exception('Underflow or the modes mismatch');
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_CTRL_CHAR:
|
||||||
|
throw new \Exception('Unexpected control character found');
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_SYNTAX:
|
||||||
|
throw new \Exception('Syntax error, malformed JSON');
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_UTF8:
|
||||||
|
throw new \Exception('Malformed UTF-8 characters, possibly incorrectly encoded');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new \Exception('Generic or unknown JSON error while decoding');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (! function_exists('is_serialized')) {
|
if (! function_exists('is_serialized')) {
|
||||||
/**
|
/**
|
||||||
* Check a value to find if it was serialized.
|
* Check a value to find if it was serialized.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user