V2Transform.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright 2019 Huawei Technologies Co.,Ltd.
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  5. * this file except in compliance with the License. You may obtain a copy of the
  6. * License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed
  11. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. * specific language governing permissions and limitations under the License.
  14. *
  15. */
  16. namespace Obs\Internal\Common;
  17. use Obs\ObsClient;
  18. use Obs\Internal\Resource\V2Constants;
  19. class V2Transform implements ITransform
  20. {
  21. private static $instance;
  22. private function __construct()
  23. {
  24. }
  25. public static function getInstance()
  26. {
  27. if (!(self::$instance instanceof V2Transform)) {
  28. self::$instance = new V2Transform();
  29. }
  30. return self::$instance;
  31. }
  32. public function transform($sign, $para)
  33. {
  34. $res = $para;
  35. if ($sign === 'storageClass') {
  36. $res = $this->transStorageClass($para);
  37. } elseif ($sign === 'aclHeader') {
  38. $res = $this->transAclHeader($para);
  39. } elseif ($sign === 'aclUri') {
  40. $res = $this->transAclGroupUri($para);
  41. } elseif ($sign == 'event') {
  42. $res = $this->transNotificationEvent($para);
  43. } else {
  44. // nothing handle
  45. }
  46. return $res;
  47. }
  48. private function transStorageClass($para)
  49. {
  50. $search = array(ObsClient::StorageClassStandard, ObsClient::StorageClassWarm, ObsClient::StorageClassCold);
  51. $repalce = array('STANDARD', 'STANDARD_IA', 'GLACIER');
  52. return str_replace($search, $repalce, $para);
  53. }
  54. private function transAclHeader($para)
  55. {
  56. if ($para === ObsClient::AclPublicReadDelivered || $para === ObsClient::AclPublicReadWriteDelivered) {
  57. $para = null;
  58. }
  59. return $para;
  60. }
  61. private function transAclGroupUri($para)
  62. {
  63. $res = $para;
  64. if ($para === ObsClient::GroupAllUsers) {
  65. $res = V2Constants::GROUP_ALL_USERS_PREFIX . $para;
  66. } elseif ($para === ObsClient::GroupAuthenticatedUsers) {
  67. $res = V2Constants::GROUP_AUTHENTICATED_USERS_PREFIX . $para;
  68. } elseif ($para === ObsClient::GroupLogDelivery) {
  69. $res = V2Constants::GROUP_LOG_DELIVERY_PREFIX . $para;
  70. } elseif ($para === ObsClient::AllUsers) {
  71. $res = V2Constants::GROUP_ALL_USERS_PREFIX . ObsClient::GroupAllUsers;
  72. } else {
  73. // nothing handle
  74. }
  75. return $res;
  76. }
  77. private function transNotificationEvent($para)
  78. {
  79. $pos = strpos($para, 's3:');
  80. if ($pos === false || $pos !== 0) {
  81. $para = 's3:' . $para;
  82. }
  83. return $para;
  84. }
  85. }