ObsTransform.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. class ObsTransform implements ITransform {
  19. private static $instance;
  20. private function __construct(){}
  21. public static function getInstance() {
  22. if (!(self::$instance instanceof ObsTransform)) {
  23. self::$instance = new ObsTransform();
  24. }
  25. return self::$instance;
  26. }
  27. public function transform($sign, $para) {
  28. if ($sign === 'aclHeader') {
  29. $para = $this->transAclHeader($para);
  30. } else if ($sign === 'aclUri') {
  31. $para = $this->transAclGroupUri($para);
  32. } else if ($sign == 'event') {
  33. $para = $this->transNotificationEvent($para);
  34. } else if ($sign == 'storageClass') {
  35. $para = $this->transStorageClass($para);
  36. }
  37. return $para;
  38. }
  39. private function transAclHeader($para) {
  40. if ($para === ObsClient::AclAuthenticatedRead || $para === ObsClient::AclBucketOwnerRead ||
  41. $para === ObsClient::AclBucketOwnerFullControl || $para === ObsClient::AclLogDeliveryWrite) {
  42. $para = null;
  43. }
  44. return $para;
  45. }
  46. private function transAclGroupUri($para) {
  47. if ($para === ObsClient::GroupAllUsers) {
  48. $para = ObsClient::AllUsers;
  49. }
  50. return $para;
  51. }
  52. private function transNotificationEvent($para) {
  53. $pos = strpos($para, 's3:');
  54. if ($pos !== false && $pos === 0) {
  55. $para = substr($para, 3);
  56. }
  57. return $para;
  58. }
  59. private function transStorageClass($para) {
  60. $search = array('STANDARD', 'STANDARD_IA', 'GLACIER');
  61. $repalce = array(ObsClient::StorageClassStandard, ObsClient::StorageClassWarm, ObsClient::StorageClassCold);
  62. $para = str_replace($search, $repalce, $para);
  63. return $para;
  64. }
  65. }