add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks - Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists - Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services - Add Microsoft OIDC SSO, API token management, and user lifecycle features - Add swagger-ui vendor integration and OpenAPI spec - Add production Docker setup and bin/ scripts - Update composer dependencies, config, templates, and frontend assets throughout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* HTML-escape output in templates.
|
||||
*/
|
||||
function e($string): void
|
||||
{
|
||||
echo htmlspecialchars((string) $string, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a web asset URL relative to the app base URL.
|
||||
*/
|
||||
function asset(string $path): string
|
||||
{
|
||||
return \MintyPHP\Router::getBaseUrl() . ltrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an absolute filesystem path inside templates/.
|
||||
*/
|
||||
function templatePath(string $path): string
|
||||
{
|
||||
return dirname(__DIR__, 3) . '/templates/' . ltrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an asset URL with filemtime cache-busting when available.
|
||||
*/
|
||||
function assetVersion(string $path): string
|
||||
{
|
||||
$path = ltrim($path, '/');
|
||||
@@ -27,6 +39,9 @@ function assetVersion(string $path): string
|
||||
return $url . '?v=' . $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base URL including locale segment (e.g. /de/).
|
||||
*/
|
||||
function localeBase(): string
|
||||
{
|
||||
$locale = \MintyPHP\I18n::$locale ?? \MintyPHP\I18n::$defaultLocale;
|
||||
@@ -34,11 +49,17 @@ function localeBase(): string
|
||||
return \MintyPHP\Router::getBaseUrl() . $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locale-aware URL for app routes.
|
||||
*/
|
||||
function lurl(string $path = ''): string
|
||||
{
|
||||
return localeBase() . ltrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* App title from settings with APP_NAME fallback.
|
||||
*/
|
||||
function appTitle(): string
|
||||
{
|
||||
$default = defined('APP_NAME') ? APP_NAME : 'IMVS';
|
||||
@@ -49,11 +70,15 @@ function appTitle(): string
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an absolute URL using APP_URL or request host fallback.
|
||||
*/
|
||||
function appUrl(string $path = ''): string
|
||||
{
|
||||
if ($path !== '' && preg_match('#^https?://#i', $path)) {
|
||||
return $path;
|
||||
}
|
||||
// Prefer configured canonical URL to keep links stable.
|
||||
$base = getenv('APP_URL') ?: '';
|
||||
$base = rtrim((string) $base, '/');
|
||||
if ($base === '') {
|
||||
@@ -75,6 +100,9 @@ function appUrl(string $path = ''): string
|
||||
return $base . '/' . $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human-readable current user name fallback: first+last -> email.
|
||||
*/
|
||||
function currentUserDisplayName(): string
|
||||
{
|
||||
$user = $_SESSION['user'] ?? [];
|
||||
@@ -85,57 +113,43 @@ function currentUserDisplayName(): string
|
||||
return trim((string) ($user['email'] ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute logo URL (used in e-mails and metadata).
|
||||
*/
|
||||
function appLogoUrlAbsolute(int $size = 128): string
|
||||
{
|
||||
$url = appLogoUrl($size);
|
||||
return appUrl($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read one cached app setting from config/settings.php.
|
||||
*/
|
||||
function appSetting(string $key): ?string
|
||||
{
|
||||
$cacheFile = dirname(__DIR__, 3) . '/config/settings.php';
|
||||
if (!is_file($cacheFile)) {
|
||||
if (!class_exists('MintyPHP\\Service\\Settings\\SettingCacheService')) {
|
||||
return null;
|
||||
}
|
||||
$settings = include $cacheFile;
|
||||
if (!is_array($settings)) {
|
||||
return null;
|
||||
}
|
||||
$value = $settings[$key] ?? null;
|
||||
$value = $value !== null ? trim((string) $value) : '';
|
||||
return $value !== '' ? $value : null;
|
||||
return \MintyPHP\Service\Settings\SettingCacheService::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configured themes with a safe fallback list.
|
||||
*/
|
||||
function appThemes(): array
|
||||
{
|
||||
$file = dirname(__DIR__, 3) . '/config/themes.php';
|
||||
if (!is_file($file)) {
|
||||
if (!class_exists('MintyPHP\\Service\\Settings\\ThemeConfigService')) {
|
||||
return [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
];
|
||||
}
|
||||
$themes = include $file;
|
||||
if (!is_array($themes)) {
|
||||
return [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
];
|
||||
}
|
||||
$clean = [];
|
||||
foreach ($themes as $key => $label) {
|
||||
$key = strtolower(trim((string) $key));
|
||||
$label = trim((string) $label);
|
||||
if ($key !== '' && $label !== '') {
|
||||
$clean[$key] = $label;
|
||||
}
|
||||
}
|
||||
return $clean ?: [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
];
|
||||
return \MintyPHP\Service\Settings\ThemeConfigService::all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve default locale only if it exists in APP_LOCALES.
|
||||
*/
|
||||
function appDefaultLocale(): ?string
|
||||
{
|
||||
$locale = appSetting('app_locale');
|
||||
@@ -149,9 +163,16 @@ function appDefaultLocale(): ?string
|
||||
return $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve default theme from settings, then APP_THEME, then light.
|
||||
*/
|
||||
function appDefaultTheme(): string
|
||||
{
|
||||
$themes = appThemes();
|
||||
$tenantTheme = strtolower(trim((string) ($_SESSION['current_tenant']['default_theme'] ?? '')));
|
||||
if ($tenantTheme !== '' && isset($themes[$tenantTheme])) {
|
||||
return $tenantTheme;
|
||||
}
|
||||
$setting = appSetting('app_theme');
|
||||
if ($setting !== null && isset($themes[$setting])) {
|
||||
return $setting;
|
||||
@@ -161,6 +182,9 @@ function appDefaultTheme(): string
|
||||
return isset($themes[$envTheme]) ? $envTheme : 'light';
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve effective theme with optional per-user override.
|
||||
*/
|
||||
function currentTheme(): string
|
||||
{
|
||||
$themes = appThemes();
|
||||
@@ -176,8 +200,22 @@ function currentTheme(): string
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Feature flag: allow users to choose their own theme.
|
||||
*/
|
||||
function allowUserTheme(): bool
|
||||
{
|
||||
$tenantValue = $_SESSION['current_tenant']['allow_user_theme'] ?? null;
|
||||
if ($tenantValue !== null && $tenantValue !== '') {
|
||||
$tenantValue = strtolower(trim((string) $tenantValue));
|
||||
if (in_array($tenantValue, ['1', 'true', 'yes', 'on'], true)) {
|
||||
return true;
|
||||
}
|
||||
if (in_array($tenantValue, ['0', 'false', 'no', 'off'], true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$value = appSetting('app_theme_user');
|
||||
if ($value === null || $value === '') {
|
||||
return true;
|
||||
@@ -185,6 +223,9 @@ function allowUserTheme(): bool
|
||||
return in_array(strtolower($value), ['1', 'true', 'yes', 'on'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Feature flag: allow public self-registration.
|
||||
*/
|
||||
function allowRegistration(): bool
|
||||
{
|
||||
$value = appSetting('app_registration');
|
||||
@@ -194,8 +235,12 @@ function allowRegistration(): bool
|
||||
return in_array(strtolower($value), ['1', 'true', 'yes', 'on'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve active primary color (tenant override -> app setting).
|
||||
*/
|
||||
function appPrimaryColor(): ?string
|
||||
{
|
||||
// Tenant-scoped branding has precedence over global settings.
|
||||
$tenantColor = $_SESSION['current_tenant']['primary_color'] ?? null;
|
||||
if ($tenantColor !== null) {
|
||||
$tenantColor = strtolower(trim((string) $tenantColor));
|
||||
@@ -215,6 +260,9 @@ function appPrimaryColor(): ?string
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert current hex color to CSS HSL custom properties.
|
||||
*/
|
||||
function appPrimaryCssVars(): string
|
||||
{
|
||||
$hex = appPrimaryColor();
|
||||
@@ -229,6 +277,7 @@ function appPrimaryCssVars(): string
|
||||
$g = hexdec(substr($hex, 2, 2)) / 255;
|
||||
$b = hexdec(substr($hex, 4, 2)) / 255;
|
||||
|
||||
// Short-circuit grayscale values to avoid unstable hue math.
|
||||
$monoThreshold = 0.000001;
|
||||
if (abs($r - $g) < $monoThreshold && abs($g - $b) < $monoThreshold) {
|
||||
$l = round($r * 100, 2) . '%';
|
||||
@@ -239,7 +288,7 @@ function appPrimaryCssVars(): string
|
||||
$min = min($r, $g, $b);
|
||||
$delta = $max - $min;
|
||||
|
||||
if ($delta == 0.0) {
|
||||
if ($delta === 0.0) {
|
||||
$l = round((($max + $min) / 2) * 100, 2) . '%';
|
||||
return "--app-primary-h-base: 0; --app-primary-s-base: 0%; --app-primary-l-base: {$l}; --app-primary-h-light: 0; --app-primary-s-light: 0%; --app-primary-l-light: {$l};";
|
||||
}
|
||||
@@ -258,7 +307,7 @@ function appPrimaryCssVars(): string
|
||||
|
||||
$l = ($max + $min) / 2;
|
||||
$denominator = 1 - abs(2 * $l - 1);
|
||||
if ($delta === 0.0 || $denominator == 0.0) {
|
||||
if ($delta === 0.0 || $denominator === 0.0) {
|
||||
$s = 0.0;
|
||||
} else {
|
||||
$s = $delta / $denominator;
|
||||
@@ -271,6 +320,9 @@ function appPrimaryCssVars(): string
|
||||
return "--app-primary-h-base: {$h}; --app-primary-s-base: {$s}; --app-primary-l-base: {$l}; --app-primary-h-light: {$h}; --app-primary-s-light: {$s}; --app-primary-l-light: {$l};";
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve app logo path (custom upload with fallback asset).
|
||||
*/
|
||||
function appLogoUrl(?int $size = null): string
|
||||
{
|
||||
if (class_exists('MintyPHP\\Service\\Branding\\BrandingLogoService') && \MintyPHP\Service\Branding\BrandingLogoService::hasLogo()) {
|
||||
@@ -280,6 +332,9 @@ function appLogoUrl(?int $size = null): string
|
||||
return asset('brand/logo.svg');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve favicon path (tenant favicon with global fallback).
|
||||
*/
|
||||
function appFaviconUrl(string $file): string
|
||||
{
|
||||
$tenantUuid = $_SESSION['current_tenant']['uuid'] ?? '';
|
||||
@@ -291,11 +346,9 @@ function appFaviconUrl(string $file): string
|
||||
return asset('favicon/' . ltrim($file, '/'));
|
||||
}
|
||||
|
||||
function d()
|
||||
{
|
||||
return call_user_func_array('MintyPHP\\Debugger::debug', func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort array items by 'description' case-insensitively.
|
||||
*/
|
||||
function sortByDescription(array &$items): void
|
||||
{
|
||||
usort($items, static fn($a, $b) =>
|
||||
|
||||
Reference in New Issue
Block a user