You've already forked Atomcms-edit
79 lines
2.0 KiB
PHP
Executable File
79 lines
2.0 KiB
PHP
Executable File
<?php
|
|
|
|
use App\Services\HousekeepingPermissionsService;
|
|
use App\Services\PermissionsService;
|
|
use App\Services\SettingsService;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
if (! function_exists('setting')) {
|
|
function setting(string $key, mixed $default = null): mixed
|
|
{
|
|
return app(SettingsService::class)->getOrDefault($key, $default);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('languages')) {
|
|
function languages(): Collection
|
|
{
|
|
return app(SettingsService::class)->getLanguages();
|
|
}
|
|
}
|
|
|
|
if (! function_exists('hasPermission')) {
|
|
function hasPermission(string $permission): bool
|
|
{
|
|
return (bool) app(PermissionsService::class)->getOrDefault($permission);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('hasHousekeepingPermission')) {
|
|
function hasHousekeepingPermission(string $permission): bool
|
|
{
|
|
return (bool) app(HousekeepingPermissionsService::class)->getOrDefault($permission);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('columnExists')) {
|
|
function columnExists(string $table, string $column): bool
|
|
{
|
|
try {
|
|
return Schema::hasColumn($table, $column);
|
|
} catch (Throwable) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (! function_exists('isDarkColor')) {
|
|
function isDarkColor(string $hexColor): bool
|
|
{
|
|
$hex = ltrim($hexColor, '#');
|
|
$r = hexdec(substr($hex, 0, 2));
|
|
$g = hexdec(substr($hex, 2, 2));
|
|
$b = hexdec(substr($hex, 4, 2));
|
|
|
|
$luminance = (0.299 * $r + 0.587 * $g + 0.114 * $b) / 255;
|
|
|
|
return $luminance < 0.5;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('bootstrap_path')) {
|
|
function bootstrap_path(string $path = ''): string
|
|
{
|
|
return base_path('bootstrap' . ($path ? DIRECTORY_SEPARATOR . $path : ''));
|
|
}
|
|
}
|
|
|
|
if (! function_exists('logJson')) {
|
|
function logJson(string $level, string $message, array $context = []): void
|
|
{
|
|
try {
|
|
Log::channel('json')->{$level}($message, $context);
|
|
} catch (Throwable) {
|
|
}
|
|
}
|
|
}
|