RequestFactory.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Libs\Api\OpenSRS;
  3. class RequestFactory
  4. {
  5. public static $RequestRoutes = [
  6. 'fastdomainlookup' => 'Fastlookup\FastDomainLookup'
  7. ];
  8. public static function build($func, $type, $dataObject)
  9. {
  10. $route = '';
  11. $routeKey = strtolower($func);
  12. $returnFullResponse = true;
  13. if (array_key_exists($routeKey, self::$RequestRoutes))
  14. {
  15. $route = self::$RequestRoutes[$routeKey];
  16. }
  17. $class = '\ModulesGarden\ProxmoxAddon\App\Libs\Api\OpenSRS\\' . $route;
  18. if (class_exists($class))
  19. {
  20. /* if (!isset($dataObject->attributes)) {
  21. $dataconversionRoute = '\ModulesGarden\ProxmoxAddon\App\Api\OpenSRS\backwardcompatibility\dataconversion\\'.$route;
  22. if (class_exists($dataconversionRoute)) {
  23. $dc = new $dataconversionRoute();
  24. $dataObject = $dc->convertDataObject($dataObject);
  25. $returnFullResponse = false;
  26. }
  27. } */
  28. return new $class($type, $dataObject, $returnFullResponse);
  29. }
  30. else
  31. {
  32. throw new \Exception("OSRS Error - $func is unsupported.");
  33. }
  34. }
  35. }