Refactor helper drift in lib: centralize theme/translation and remove app() hotspots

This commit is contained in:
2026-03-19 08:23:14 +01:00
parent 5da506a20f
commit 5739cc1200
24 changed files with 197 additions and 88 deletions

View File

@@ -2,6 +2,7 @@
namespace MintyPHP\Service\Access;
use MintyPHP\App\Module\ModuleRegistry;
use MintyPHP\Service\Tenant\TenantScopeService;
class AccessPolicyFactory
@@ -17,7 +18,8 @@ class AccessPolicyFactory
public function __construct(
private readonly PermissionService $permissionService,
private readonly TenantScopeService $tenantScopeService
private readonly TenantScopeService $tenantScopeService,
private readonly ?ModuleRegistry $moduleRegistry = null
) {
}
@@ -85,20 +87,20 @@ class AccessPolicyFactory
];
// Append module-contributed authorization policies.
try {
/** @var \MintyPHP\App\Module\ModuleRegistry $registry */
$registry = app(\MintyPHP\App\Module\ModuleRegistry::class);
foreach ($registry->getAuthorizationPolicies() as $policyClass) {
if (!is_string($policyClass) || trim($policyClass) === '') {
continue;
}
$policy = $this->instantiateModulePolicy($policyClass);
if ($policy instanceof AuthorizationPolicyInterface) {
$policies[] = $policy;
if ($this->moduleRegistry !== null) {
try {
foreach ($this->moduleRegistry->getAuthorizationPolicies() as $policyClass) {
if (!is_string($policyClass) || trim($policyClass) === '') {
continue;
}
$policy = $this->instantiateModulePolicy($policyClass);
if ($policy instanceof AuthorizationPolicyInterface) {
$policies[] = $policy;
}
}
} catch (\Throwable) {
// fail-open: no module registry available in this context
}
} catch (\Throwable) {
// fail-open: no module registry available in this context
}
return $this->authorizationService = new AuthorizationService($policies);