user(); $targetClass = User::CLASS_MODERATOR; $log = sprintf('user: %s, class: %s, target class: %s', $user->id, $user->class, $targetClass); if (!$user || $user->class < $targetClass) { do_log("$log, denied!"); throw new UnauthorizedException('Unauthorized!'); } do_log("$log, allow!"); return $next($request); } }