major update
This commit is contained in:
@@ -24,6 +24,59 @@ function templatePath(string $path): string
|
||||
return dirname(__DIR__, 3) . '/templates/' . ltrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the app service container for the current request.
|
||||
*/
|
||||
function setAppContainer(\MintyPHP\App\AppContainer $container): void
|
||||
{
|
||||
$GLOBALS['minty_app_container'] = $container;
|
||||
|
||||
\MintyPHP\Http\ApiAuth::configure(
|
||||
static fn (): \MintyPHP\Service\Auth\AuthScopeGateway => $container->get(\MintyPHP\Service\Auth\AuthScopeGateway::class),
|
||||
static fn (): \MintyPHP\Service\Auth\ApiTokenService => $container->get(\MintyPHP\Service\Auth\ApiTokenService::class),
|
||||
static fn (): \MintyPHP\Repository\Access\UserRoleRepository => $container->get(\MintyPHP\Repository\Access\UserRoleRepository::class),
|
||||
static fn (): \MintyPHP\Repository\Access\RolePermissionRepository => $container->get(\MintyPHP\Repository\Access\RolePermissionRepository::class),
|
||||
static fn (): \MintyPHP\Service\User\UserTenantContextService => $container->get(\MintyPHP\Service\User\UserTenantContextService::class),
|
||||
static fn (): \MintyPHP\Service\Access\AuthorizationService => $container->get(\MintyPHP\Service\Access\AuthorizationService::class)
|
||||
);
|
||||
|
||||
\MintyPHP\Http\ApiBootstrap::configure(
|
||||
static fn (): \MintyPHP\Service\Audit\ApiAuditService => $container->get(\MintyPHP\Service\Audit\ApiAuditService::class),
|
||||
static fn (): \MintyPHP\Service\Settings\SettingGateway => $container->get(\MintyPHP\Service\Settings\SettingGateway::class),
|
||||
static fn (): \MintyPHP\Service\Security\RateLimiterService => $container->get(\MintyPHP\Service\Security\RateLimiterService::class),
|
||||
static fn (): \MintyPHP\Http\ApiSystemAuditReporter => $container->get(\MintyPHP\Http\ApiSystemAuditReporter::class)
|
||||
);
|
||||
|
||||
\MintyPHP\Http\ApiResponse::configure(
|
||||
static fn (): \MintyPHP\Service\Audit\ApiAuditService => $container->get(\MintyPHP\Service\Audit\ApiAuditService::class),
|
||||
static fn (): \MintyPHP\Service\Access\AuthorizationService => $container->get(\MintyPHP\Service\Access\AuthorizationService::class),
|
||||
static fn (): \MintyPHP\Http\ApiSystemAuditReporter => $container->get(\MintyPHP\Http\ApiSystemAuditReporter::class)
|
||||
);
|
||||
|
||||
\MintyPHP\Support\Guard::configure(
|
||||
static fn (): \MintyPHP\Service\Auth\AuthService => $container->get(\MintyPHP\Service\Auth\AuthService::class),
|
||||
static fn (): \MintyPHP\Service\Tenant\TenantService => $container->get(\MintyPHP\Service\Tenant\TenantService::class),
|
||||
static fn (): \MintyPHP\Service\Access\AuthorizationService => $container->get(\MintyPHP\Service\Access\AuthorizationService::class)
|
||||
);
|
||||
|
||||
\MintyPHP\Support\Search\SearchItemMapperProvider::configure(
|
||||
static fn (): \MintyPHP\Service\User\UserAvatarService => $container->get(\MintyPHP\Service\User\UserAvatarService::class)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a service from the app container.
|
||||
*/
|
||||
function app(string $id): mixed
|
||||
{
|
||||
$container = $GLOBALS['minty_app_container'] ?? null;
|
||||
if (!$container instanceof \MintyPHP\App\AppContainer) {
|
||||
throw new \RuntimeException('App container is not initialized');
|
||||
}
|
||||
|
||||
return $container->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an asset URL with filemtime cache-busting when available.
|
||||
*/
|
||||
@@ -127,72 +180,11 @@ function appLogoUrlAbsolute(int $size = 128): string
|
||||
*/
|
||||
function appSetting(string $key): ?string
|
||||
{
|
||||
if (!class_exists('MintyPHP\\Service\\Settings\\SettingServicesFactory')) {
|
||||
if (!class_exists('MintyPHP\\Service\\Settings\\SettingCacheService')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
static $settingsFactory = null;
|
||||
if (!$settingsFactory instanceof \MintyPHP\Service\Settings\SettingServicesFactory) {
|
||||
$settingsFactory = new \MintyPHP\Service\Settings\SettingServicesFactory();
|
||||
}
|
||||
|
||||
return $settingsFactory->createSettingCacheService()->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared per-request factory for tenant/department/role domain services.
|
||||
*/
|
||||
function directoryServicesFactory(): \MintyPHP\Service\Directory\DirectoryServicesFactory
|
||||
{
|
||||
static $factory = null;
|
||||
if (!$factory instanceof \MintyPHP\Service\Directory\DirectoryServicesFactory) {
|
||||
$factory = new \MintyPHP\Service\Directory\DirectoryServicesFactory();
|
||||
}
|
||||
return $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared per-request factory for access/permission services.
|
||||
*/
|
||||
function accessServicesFactory(): \MintyPHP\Service\Access\AccessServicesFactory
|
||||
{
|
||||
static $factory = null;
|
||||
if (!$factory instanceof \MintyPHP\Service\Access\AccessServicesFactory) {
|
||||
$factory = new \MintyPHP\Service\Access\AccessServicesFactory();
|
||||
}
|
||||
return $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared per-request permission gateway wrapper.
|
||||
*/
|
||||
function permissionGateway(): \MintyPHP\Service\Access\PermissionGateway
|
||||
{
|
||||
return accessServicesFactory()->createPermissionGateway();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared per-request factory for audit services.
|
||||
*/
|
||||
function auditServicesFactory(): \MintyPHP\Service\Audit\AuditServicesFactory
|
||||
{
|
||||
static $factory = null;
|
||||
if (!$factory instanceof \MintyPHP\Service\Audit\AuditServicesFactory) {
|
||||
$factory = new \MintyPHP\Service\Audit\AuditServicesFactory();
|
||||
}
|
||||
return $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared per-request factory for branding services.
|
||||
*/
|
||||
function brandingServicesFactory(): \MintyPHP\Service\Branding\BrandingServicesFactory
|
||||
{
|
||||
static $factory = null;
|
||||
if (!$factory instanceof \MintyPHP\Service\Branding\BrandingServicesFactory) {
|
||||
$factory = new \MintyPHP\Service\Branding\BrandingServicesFactory();
|
||||
}
|
||||
return $factory;
|
||||
return app(\MintyPHP\Service\Settings\SettingCacheService::class)->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,19 +192,14 @@ function brandingServicesFactory(): \MintyPHP\Service\Branding\BrandingServicesF
|
||||
*/
|
||||
function appThemes(): array
|
||||
{
|
||||
if (!class_exists('MintyPHP\\Service\\Settings\\SettingServicesFactory')) {
|
||||
if (!class_exists('MintyPHP\\Service\\Settings\\ThemeConfigService')) {
|
||||
return [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
];
|
||||
}
|
||||
|
||||
static $settingsFactory = null;
|
||||
if (!$settingsFactory instanceof \MintyPHP\Service\Settings\SettingServicesFactory) {
|
||||
$settingsFactory = new \MintyPHP\Service\Settings\SettingServicesFactory();
|
||||
}
|
||||
|
||||
return $settingsFactory->createThemeConfigService()->all();
|
||||
return app(\MintyPHP\Service\Settings\ThemeConfigService::class)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,8 +380,8 @@ function appPrimaryCssVars(): string
|
||||
*/
|
||||
function appLogoUrl(?int $size = null): string
|
||||
{
|
||||
if (class_exists('MintyPHP\\Service\\Branding\\BrandingServicesFactory')) {
|
||||
$logoService = brandingServicesFactory()->createBrandingLogoService();
|
||||
if (class_exists('MintyPHP\\Service\\Branding\\BrandingLogoService')) {
|
||||
$logoService = app(\MintyPHP\Service\Branding\BrandingLogoService::class);
|
||||
if ($logoService->hasLogo()) {
|
||||
$query = $size ? '?size=' . (int) $size : '';
|
||||
return lurl('branding/logo' . $query);
|
||||
@@ -409,13 +396,8 @@ function appLogoUrl(?int $size = null): string
|
||||
function appFaviconUrl(string $file): string
|
||||
{
|
||||
$tenantUuid = $_SESSION['current_tenant']['uuid'] ?? '';
|
||||
if ($tenantUuid !== '' && class_exists('MintyPHP\\Service\\Tenant\\TenantServicesFactory')) {
|
||||
static $tenantServicesFactory = null;
|
||||
if (!$tenantServicesFactory instanceof \MintyPHP\Service\Tenant\TenantServicesFactory) {
|
||||
$tenantServicesFactory = new \MintyPHP\Service\Tenant\TenantServicesFactory();
|
||||
}
|
||||
|
||||
if ($tenantServicesFactory->createTenantFaviconService()->hasFavicon($tenantUuid)) {
|
||||
if ($tenantUuid !== '' && class_exists('MintyPHP\\Service\\Tenant\\TenantFaviconService')) {
|
||||
if (app(\MintyPHP\Service\Tenant\TenantFaviconService::class)->hasFavicon($tenantUuid)) {
|
||||
return asset('favicon/tenants/' . $tenantUuid . '/favicon/' . ltrim($file, '/'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user