HtVopFetchPackageIServiceClient.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * Copyright (c) 2008-2016 vip.com, All Rights Reserved.
  4. *
  5. * Powered by com.vip.osp.osp-idlc-2.5.11.
  6. *
  7. */
  8. namespace vipapis\order;
  9. $base_path = dirname(__FILE__).'/../../';
  10. require_once $base_path.'/Osp/Util/PathUtil.php';
  11. require_once $base_path.'/Osp/ClassLoader/ClassLoader.php';
  12. class HtVopFetchPackageIServiceClient{
  13. private static $isRegis;
  14. private static $DEFAULT_PROXY_IP = "127.0.0.1";
  15. private static $DEFAULT_PROXY_PORT = "2080";
  16. private static function regis(){
  17. $path = \Osp\Util\PathUtil::getRootPath ();
  18. $nsLoader = new \Osp\ClassLoader\ClassLoader ();
  19. $nsLoader->registerNamespace ( 'Thrift', $path );
  20. $nsLoader->registerNamespace ( 'Osp', $path );
  21. $nsLoader->registerNamespace ( 'vipapis', $path );
  22. $nsLoader->register ();
  23. }
  24. public static function getService(){
  25. if (! HtVopFetchPackageIServiceClient::$isRegis){
  26. HtVopFetchPackageIServiceClient::regis ();
  27. HtVopFetchPackageIServiceClient::$isRegis = true;
  28. }
  29. $ctx = \Osp\Context\InvocationContextFactory::getInstance ();
  30. $ip = HtVopFetchPackageIServiceClient::$DEFAULT_PROXY_IP;
  31. $port = HtVopFetchPackageIServiceClient::$DEFAULT_PROXY_PORT;
  32. try{
  33. $envCfg = getenv ( "VIP_OSP_PROXY" );
  34. $ipport = explode ( ":", $envCfg );
  35. if (strlen ( $envCfg ) > 0 && count ( $ipport ) == 2){
  36. $ip = $ipport [0];
  37. $port = $ipport [1];
  38. }
  39. }
  40. catch(\Exception $e){
  41. $ip = HtVopFetchPackageIServiceClient::$DEFAULT_PROXY_IP;
  42. $port = HtVopFetchPackageIServiceClient::$DEFAULT_PROXY_PORT;
  43. }
  44. if ($ctx->getCalleeIP () == null){
  45. $ctx->setCalleeIP ( $ip );
  46. }
  47. if ($ctx->getCalleePort () == null){
  48. $ctx->setCalleePort ( $port );
  49. }
  50. //$ctx->setProtocol ( \Osp\Protocol\OspProtocol::$Binary );
  51. return new \vipapis\order\HtVopFetchPackageIServiceHelper();
  52. }
  53. }
  54. ?>