Scope.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  9. * +----------------------------------------------------------------------
  10. * | Author: CRMEB Team <admin@crmeb.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace crmeb\services\upload\extend\cos;
  14. class Scope
  15. {
  16. protected $action;
  17. protected $bucket;
  18. protected $region;
  19. protected $resourcePrefix;
  20. protected $effect = 'allow';
  21. public function __construct($action, $bucket, $region, $resourcePrefix)
  22. {
  23. $this->action = $action;
  24. $this->bucket = $bucket;
  25. $this->region = $region;
  26. $this->resourcePrefix = $resourcePrefix;
  27. }
  28. public function set_effect($isAllow)
  29. {
  30. if ($isAllow) {
  31. $this->effect = 'allow';
  32. } else {
  33. $this->effect = 'deny';
  34. }
  35. }
  36. public function get_action()
  37. {
  38. if ($this->action == null) {
  39. throw new \Exception("action == null");
  40. }
  41. return $this->action;
  42. }
  43. public function get_resource()
  44. {
  45. if ($this->bucket == null) {
  46. throw new \Exception("bucket == null");
  47. }
  48. if ($this->region == null) {
  49. throw new \Exception("region == null");
  50. }
  51. if ($this->resourcePrefix == null) {
  52. throw new \Exception("resourcePrefix == null");
  53. }
  54. $index = strripos($this->bucket, '-');
  55. if ($index < 0) {
  56. throw new Exception("bucket is invalid: " . $this->bucket);
  57. }
  58. $appid = substr($this->bucket, $index + 1);
  59. if (!(strpos($this->resourcePrefix, '/') === 0)) {
  60. $this->resourcePrefix = '/' . $this->resourcePrefix;
  61. }
  62. return 'qcs::cos:' . $this->region . ':uid/' . $appid . ':' . $this->bucket . $this->resourcePrefix;
  63. }
  64. public function get_effect()
  65. {
  66. return $this->effect;
  67. }
  68. }