Files
new.rybstock.ru/app/helpers.php
T
2026-06-05 15:52:20 +03:00

60 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
use App\Core\View;
function app_env(string $key, ?string $default = null): ?string
{
$value = $_ENV[$key] ?? getenv($key);
if ($value === false || $value === null) {
return $default;
}
return (string) $value;
}
function base_path(string $path = ''): string
{
$base = dirname(__DIR__);
return $path === '' ? $base : $base . '/' . ltrim($path, '/');
}
function view(string $template, array $data = []): void
{
View::render($template, $data);
}
function e(?string $value): string
{
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}
function unit_label(?string $unit): string
{
return match ((string) $unit) {
'kg' => 'кг',
'g' => 'г',
'l' => 'л',
'ml' => 'мл',
'pcs' => 'шт.',
default => (string) ($unit ?: 'ед.'),
};
}
function money_label(mixed $value): string
{
if ($value === null || $value === '') {
return '';
}
$number = (float) $value;
$formatted = abs($number - round($number)) < 0.005
? number_format($number, 0, ',', ' ')
: number_format($number, 2, ',', ' ');
return $formatted . ' руб.';
}