ObsTransform.php 2.5 KB

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