Config.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace Qiniu;
  3. final class Config
  4. {
  5. const SDK_VER = '7.2.5';
  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 RTCAPI_VERSION = 'v3';
  13. // Zone 空间对应的机房
  14. public $zone;
  15. //BOOL 是否使用https域名
  16. public $useHTTPS;
  17. //BOOL 是否使用CDN加速上传域名
  18. public $useCdnDomains;
  19. // Zone Cache
  20. private $zoneCache;
  21. // 构造函数
  22. public function __construct(Zone $z = null)
  23. {
  24. $this->zone = $z;
  25. $this->useHTTPS = false;
  26. $this->useCdnDomains = false;
  27. $this->zoneCache = array();
  28. }
  29. public function getUpHost($accessKey, $bucket)
  30. {
  31. $zone = $this->getZone($accessKey, $bucket);
  32. if ($this->useHTTPS === true) {
  33. $scheme = "https://";
  34. } else {
  35. $scheme = "http://";
  36. }
  37. $host = $zone->srcUpHosts[0];
  38. if ($this->useCdnDomains === true) {
  39. $host = $zone->cdnUpHosts[0];
  40. }
  41. return $scheme . $host;
  42. }
  43. public function getUpBackupHost($accessKey, $bucket)
  44. {
  45. $zone = $this->getZone($accessKey, $bucket);
  46. if ($this->useHTTPS === true) {
  47. $scheme = "https://";
  48. } else {
  49. $scheme = "http://";
  50. }
  51. $host = $zone->cdnUpHosts[0];
  52. if ($this->useCdnDomains === true) {
  53. $host = $zone->srcUpHosts[0];
  54. }
  55. return $scheme . $host;
  56. }
  57. public function getRsHost($accessKey, $bucket)
  58. {
  59. $zone = $this->getZone($accessKey, $bucket);
  60. if ($this->useHTTPS === true) {
  61. $scheme = "https://";
  62. } else {
  63. $scheme = "http://";
  64. }
  65. return $scheme . $zone->rsHost;
  66. }
  67. public function getRsfHost($accessKey, $bucket)
  68. {
  69. $zone = $this->getZone($accessKey, $bucket);
  70. if ($this->useHTTPS === true) {
  71. $scheme = "https://";
  72. } else {
  73. $scheme = "http://";
  74. }
  75. return $scheme . $zone->rsfHost;
  76. }
  77. public function getIovipHost($accessKey, $bucket)
  78. {
  79. $zone = $this->getZone($accessKey, $bucket);
  80. if ($this->useHTTPS === true) {
  81. $scheme = "https://";
  82. } else {
  83. $scheme = "http://";
  84. }
  85. return $scheme . $zone->iovipHost;
  86. }
  87. public function getApiHost($accessKey, $bucket)
  88. {
  89. $zone = $this->getZone($accessKey, $bucket);
  90. if ($this->useHTTPS === true) {
  91. $scheme = "https://";
  92. } else {
  93. $scheme = "http://";
  94. }
  95. return $scheme . $zone->apiHost;
  96. }
  97. private function getZone($accessKey, $bucket)
  98. {
  99. $cacheId = "$accessKey:$bucket";
  100. if (isset($this->zoneCache[$cacheId])) {
  101. $zone = $this->zoneCache[$cacheId];
  102. } elseif (isset($this->zone)) {
  103. $zone = $this->zone;
  104. $this->zoneCache[$cacheId] = $zone;
  105. } else {
  106. $zone = Zone::queryZone($accessKey, $bucket);
  107. $this->zoneCache[$cacheId] = $zone;
  108. }
  109. return $zone;
  110. }
  111. }