-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a7039b
commit d6fb13a
Showing
5 changed files
with
1,138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use Illuminate\Contracts\Container\BindingResolutionException; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
if (! function_exists('formatVND')) { | ||
function formatVND(int $number): string | ||
{ | ||
// Format the number with thousands separator and no decimals | ||
$formattedNumber = number_format($number, 0, '', '.'); | ||
|
||
// Append the Vietnamese currency symbol | ||
return $formattedNumber.' ₫'; | ||
} | ||
} | ||
|
||
if (! function_exists('authUser')) { | ||
function authUser(): User | ||
{ | ||
// @phpstan-ignore-next-line | ||
return Auth::user(); | ||
} | ||
} | ||
|
||
if (! function_exists('typeString')) { | ||
function typeString(mixed $value, string $fallback = ''): string | ||
{ | ||
if (is_string($value)) { | ||
return $value; | ||
} | ||
|
||
try { | ||
// @phpstan-ignore-next-line | ||
return strval($value); | ||
} catch (Throwable) { | ||
return $fallback; | ||
} | ||
} | ||
} | ||
|
||
if (! function_exists('typeArray')) { | ||
/** | ||
* @param array<mixed> $default | ||
* @return array<mixed> | ||
* | ||
* @throws BindingResolutionException | ||
*/ | ||
function typeArray(mixed $value, array $fallback = []): array | ||
{ | ||
if (is_array($value)) { | ||
return $value; | ||
} | ||
|
||
logger('Expect array -> '.gettype($value)); | ||
|
||
return $fallback; | ||
} | ||
} | ||
|
||
if (! function_exists('typeInteger')) { | ||
function typeInteger(mixed $value, int $fallback = 0): int | ||
{ | ||
if (is_int($value)) { | ||
return $value; | ||
} | ||
|
||
try { | ||
// @phpstan-ignore-next-line | ||
return intval($value); | ||
} catch (Throwable) { | ||
return $fallback; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.