private static function &getStorage(ServerRequestInterface $request, $key = null)
    {
        if (!self::hasAttribute($request, Middleware::STORAGE_KEY)) {
            throw new RuntimeException('No session storage initialized');
        }

        $storage = self::getAttribute($request, Middleware::STORAGE_KEY);

        if (!isset($storage->$key)) {
            $storage->$key = [];
        }

        return $storage->$key;
    }