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,13 +2,16 @@
namespace MintyPHP\Service\Access;
use MintyPHP\App\Module\ModuleRegistry;
final class UiAccessService
{
/** @var array<string, bool> */
private array $decisionCache = [];
public function __construct(
private readonly AuthorizationService $authorizationService
private readonly AuthorizationService $authorizationService,
private readonly ?ModuleRegistry $moduleRegistry = null
) {
}
@@ -88,17 +91,16 @@ final class UiAccessService
{
$map = UiCapabilityMap::LAYOUT;
// Merge module-contributed layout capabilities dynamically.
try {
/** @var \MintyPHP\App\Module\ModuleRegistry $registry */
$registry = app(\MintyPHP\App\Module\ModuleRegistry::class);
if ($registry instanceof \MintyPHP\App\Module\ModuleRegistry) {
foreach ($registry->getLayoutCapabilities() as $key => $ability) {
$map[$key] = $ability;
// Merge module UI slot abilities directly into the capability map.
// Each ability string is used as both key and value (no indirection).
if ($this->moduleRegistry !== null) {
try {
foreach ($this->moduleRegistry->getModuleUiAbilities() as $ability) {
$map[$ability] = $ability;
}
} catch (\Throwable) {
// fail-open: no module registry available in this context
}
} catch (\Throwable) {
// fail-open: no module registry available in this context
}
return $this->resolveMap($actorUserId, $map);