Scope.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. class Scope{
  3. var $action;
  4. var $bucket;
  5. var $region;
  6. var $resourcePrefix;
  7. var $effect = 'allow';
  8. function __construct($action, $bucket, $region, $resourcePrefix){
  9. $this->action = $action;
  10. $this->bucket = $bucket;
  11. $this->region = $region;
  12. $this->resourcePrefix = $resourcePrefix;
  13. }
  14. function set_effect($isAllow){
  15. if($isAllow){
  16. $this->effect = 'allow';
  17. }else{
  18. $this->effect = 'deny';
  19. }
  20. }
  21. function get_action(){
  22. if($this->action == null){
  23. throw new \Exception("action == null");
  24. }
  25. return $this->action;
  26. }
  27. function get_resource(){
  28. if($this->bucket == null){
  29. throw new \Exception("bucket == null");
  30. }
  31. if($this->resourcePrefix == null){
  32. throw new \Exception("resourcePrefix == null");
  33. }
  34. $index = strripos($this->bucket, '-');
  35. if($index < 0){
  36. throw new Exception("bucket is invalid: " + $this->bucket);
  37. }
  38. $appid = substr($this->bucket, $index + 1);
  39. if(!(strpos($this->resourcePrefix, '/') === 0)){
  40. $this->resourcePrefix = '/' . $this->resourcePrefix;
  41. }
  42. return 'qcs::cos:' . $this->region . ':uid/' . $appid . ':' . $this->bucket . $this->resourcePrefix;
  43. }
  44. function get_effect(){
  45. return $this->effect;
  46. }
  47. }
  48. ?>