Refactor helper drift in lib: centralize theme/translation and remove app() hotspots
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user