Common.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Qcloud\Cos;
  3. function region_map($region) {
  4. $regionmap = array('cn-east'=>'ap-shanghai',
  5. 'cn-south'=>'ap-guangzhou',
  6. 'cn-north'=>'ap-beijing-1',
  7. 'cn-south-2'=>'ap-guangzhou-2',
  8. 'cn-southwest'=>'ap-chengdu',
  9. 'sg'=>'ap-singapore',
  10. 'tj'=>'ap-beijing-1',
  11. 'bj'=>'ap-beijing',
  12. 'sh'=>'ap-shanghai',
  13. 'gz'=>'ap-guangzhou',
  14. 'cd'=>'ap-chengdu',
  15. 'sgp'=>'ap-singapore');
  16. if (array_key_exists($region, $regionmap)) {
  17. return $regionmap[$region];
  18. }
  19. return $region;
  20. }
  21. function encodeKey($key) {
  22. return str_replace('%2F', '/', rawurlencode($key));
  23. }
  24. function endWith($haystack, $needle) {
  25. $length = strlen($needle);
  26. if($length == 0)
  27. {
  28. return true;
  29. }
  30. return (substr($haystack, -$length) === $needle);
  31. }
  32. function headersMap($command, $request) {
  33. $headermap = array(
  34. 'TransferEncoding'=>'Transfer-Encoding',
  35. 'ChannelId'=>'x-cos-channel-id'
  36. );
  37. foreach ($headermap as $key => $value) {
  38. if (isset($command[$key])) {
  39. $request = $request->withHeader($value, $command[$key]);
  40. }
  41. }
  42. return $request;
  43. }