setCurrentUserAttribute($request); return $handler->handle($request); } private function setCurrentUserAttribute(ServerRequestInterface $request): ServerRequestInterface { if (session_status() !== PHP_SESSION_ACTIVE) { return $request; } $user_id = $_SESSION['user_id'] ?? null; if ($user_id === null) { return $request; } assert(is_int($user_id) || (is_string($user_id) && is_numeric($user_id))); $user_id = (int) $user_id; $user = $this->userRepo->findById($user_id); if ($user === null) { return $request; } return $request->withAttribute('current_user', $user); } }