LanguageServer\Protocol\Methods\TextDocument\DidOpenNotification $class = __NAMESPACE__ . '\\Methods\\' . implode('\\', array_map('ucfirst', explode('/', $decoded->method))) . (isset($decoded->id) ? 'Request' : 'Notification'); // If the Request/Notification type is unknown, instantiate a basic Request or Notification class // (this is the reason Request and Notification are not abstract) if (!class_exists($class)) { fwrite(STDERR, "Unknown method {$decoded->method}\n"); if (!isset($decoded->id)) { $class = Notification::class; } else { $class = $fallbackClass; } } // JsonMapper will take care of recursively using the right classes for $params etc. $mapper = new JsonMapper(); $message = $mapper->map($decoded, new $class); return $message; } }