Common.php 1.5 KB

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