Config.php 3.2 KB

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