denialReason($user) === null; } /** * Az első nem teljesülő feltétel magyarázata, vagy null, ha minden rendben. */ public function denialReason(?User $user = null): ?string { if (! config('deployment.enabled')) { return 'A deployment csomagoló ki van kapcsolva (DEPLOYMENT_PACKAGE_ENABLED).'; } /** @var array $stages */ $stages = (array) config('deployment.stages', []); if (! in_array((string) config('app.stage'), $stages, true)) { return sprintf( 'A deployment csomagoló csak fejlesztői környezetben használható (engedélyezett stage: %s, jelenlegi: %s).', implode(', ', $stages), (string) config('app.stage'), ); } if (! $user) { return 'Bejelentkezés szükséges.'; } if (! $user->hasRole((string) config('deployment.role'))) { return 'A deployment csomagoló csak fejlesztői szerepkörrel érhető el.'; } if (! Feature::for($user)->active((string) config('deployment.feature_flag'))) { return 'A deployment csomagoló feature flag nincs bekapcsolva erre a felhasználóra.'; } return null; } public function ensureAllowed(?User $user = null): void { if ($reason = $this->denialReason($user)) { abort(403, $reason); } } }