V2Transform.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. private static $instance;
  21. private function __construct(){}
  22. public static function getInstance() {
  23. if (!(self::$instance instanceof V2Transform)) {
  24. self::$instance = new V2Transform();
  25. }
  26. return self::$instance;
  27. }
  28. public function transform($sign, $para) {
  29. if ($sign === 'storageClass') {
  30. $para = $this->transStorageClass($para);
  31. } else if ($sign === 'aclHeader') {
  32. $para = $this->transAclHeader($para);
  33. } else if ($sign === 'aclUri') {
  34. $para = $this->transAclGroupUri($para);
  35. } else if ($sign == 'event') {
  36. $para = $this->transNotificationEvent($para);
  37. }
  38. return $para;
  39. }
  40. private function transStorageClass($para) {
  41. $search = array(ObsClient::StorageClassStandard, ObsClient::StorageClassWarm, ObsClient::StorageClassCold);
  42. $repalce = array('STANDARD', 'STANDARD_IA', 'GLACIER');
  43. $para = str_replace($search, $repalce, $para);
  44. return $para;
  45. }
  46. private function transAclHeader($para) {
  47. if ($para === ObsClient::AclPublicReadDelivered || $para === ObsClient::AclPublicReadWriteDelivered) {
  48. $para = null;
  49. }
  50. return $para;
  51. }
  52. private function transAclGroupUri($para) {
  53. if ($para === ObsClient::GroupAllUsers) {
  54. $para = V2Constants::GROUP_ALL_USERS_PREFIX . $para;
  55. } else if ($para === ObsClient::GroupAuthenticatedUsers) {
  56. $para = V2Constants::GROUP_AUTHENTICATED_USERS_PREFIX . $para;
  57. } else if ($para === ObsClient::GroupLogDelivery) {
  58. $para = V2Constants::GROUP_LOG_DELIVERY_PREFIX . $para;
  59. } else if ($para === ObsClient::AllUsers) {
  60. $para = V2Constants::GROUP_ALL_USERS_PREFIX . ObsClient::GroupAllUsers;
  61. }
  62. return $para;
  63. }
  64. private function transNotificationEvent($para) {
  65. $pos = strpos($para, 's3:');
  66. if ($pos === false || $pos !== 0) {
  67. $para = 's3:' . $para;
  68. }
  69. return $para;
  70. }
  71. }