Config.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace Qiniu;
  3. final class Config
  4. {
  5. const SDK_VER = '7.2.7';
  6. const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改
  7. const RSF_HOST = 'rsf.qiniu.com';
  8. const API_HOST = 'api.qiniu.com';
  9. const RS_HOST = 'rs.qiniu.com'; //RS Host
  10. const UC_HOST = 'https://api.qiniu.com'; //UC Host
  11. const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
  12. const ARGUS_HOST = 'argus.atlab.ai';
  13. const RTCAPI_VERSION = 'v3';
  14. // Zone 空间对应的机房
  15. public $zone;
  16. //BOOL 是否使用https域名
  17. public $useHTTPS;
  18. //BOOL 是否使用CDN加速上传域名
  19. public $useCdnDomains;
  20. // Zone Cache
  21. private $zoneCache;
  22. // 构造函数
  23. public function __construct(Zone $z = null)
  24. {
  25. $this->zone = $z;
  26. $this->useHTTPS = false;
  27. $this->useCdnDomains = false;
  28. $this->zoneCache = array();
  29. }
  30. public function getUpHost($accessKey, $bucket)
  31. {
  32. $zone = $this->getZone($accessKey, $bucket);
  33. if ($this->useHTTPS === true) {
  34. $scheme = "https://";
  35. } else {
  36. $scheme = "http://";
  37. }
  38. $host = $zone->srcUpHosts[0];
  39. if ($this->useCdnDomains === true) {
  40. $host = $zone->cdnUpHosts[0];
  41. }
  42. return $scheme . $host;
  43. }
  44. public function getUpBackupHost($accessKey, $bucket)
  45. {
  46. $zone = $this->getZone($accessKey, $bucket);
  47. if ($this->useHTTPS === true) {
  48. $scheme = "https://";
  49. } else {
  50. $scheme = "http://";
  51. }
  52. $host = $zone->cdnUpHosts[0];
  53. if ($this->useCdnDomains === true) {
  54. $host = $zone->srcUpHosts[0];
  55. }
  56. return $scheme . $host;
  57. }
  58. public function getRsHost($accessKey, $bucket)
  59. {
  60. $zone = $this->getZone($accessKey, $bucket);
  61. if ($this->useHTTPS === true) {
  62. $scheme = "https://";
  63. } else {
  64. $scheme = "http://";
  65. }
  66. return $scheme . $zone->rsHost;
  67. }
  68. public function getRsfHost($accessKey, $bucket)
  69. {
  70. $zone = $this->getZone($accessKey, $bucket);
  71. if ($this->useHTTPS === true) {
  72. $scheme = "https://";
  73. } else {
  74. $scheme = "http://";
  75. }
  76. return $scheme . $zone->rsfHost;
  77. }
  78. public function getIovipHost($accessKey, $bucket)
  79. {
  80. $zone = $this->getZone($accessKey, $bucket);
  81. if ($this->useHTTPS === true) {
  82. $scheme = "https://";
  83. } else {
  84. $scheme = "http://";
  85. }
  86. return $scheme . $zone->iovipHost;
  87. }
  88. public function getApiHost($accessKey, $bucket)
  89. {
  90. $zone = $this->getZone($accessKey, $bucket);
  91. if ($this->useHTTPS === true) {
  92. $scheme = "https://";
  93. } else {
  94. $scheme = "http://";
  95. }
  96. return $scheme . $zone->apiHost;
  97. }
  98. private function getZone($accessKey, $bucket)
  99. {
  100. $cacheId = "$accessKey:$bucket";
  101. if (isset($this->zoneCache[$cacheId])) {
  102. $zone = $this->zoneCache[$cacheId];
  103. } elseif (isset($this->zone)) {
  104. $zone = $this->zone;
  105. $this->zoneCache[$cacheId] = $zone;
  106. } else {
  107. $zone = Zone::queryZone($accessKey, $bucket);
  108. $this->zoneCache[$cacheId] = $zone;
  109. }
  110. return $zone;
  111. }
  112. }