You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
2.4 KiB

6 years ago
  1. <?php
  2. namespace OSS\Model;
  3. /**
  4. * Class LifecycleRule
  5. * @package OSS\Model
  6. *
  7. * @link http://help.aliyun.com/document_detail/oss/api-reference/bucket/PutBucketLifecycle.html
  8. */
  9. class LifecycleRule
  10. {
  11. /**
  12. * 得到规则ID
  13. *
  14. * @return string
  15. */
  16. public function getId()
  17. {
  18. return $this->id;
  19. }
  20. /**
  21. * @param string $id 规则ID
  22. */
  23. public function setId($id)
  24. {
  25. $this->id = $id;
  26. }
  27. /**
  28. * 得到文件前缀
  29. *
  30. * @return string
  31. */
  32. public function getPrefix()
  33. {
  34. return $this->prefix;
  35. }
  36. /**
  37. * 设置文件前缀
  38. *
  39. * @param string $prefix 文件前缀
  40. */
  41. public function setPrefix($prefix)
  42. {
  43. $this->prefix = $prefix;
  44. }
  45. /**
  46. * Lifecycle规则的状态
  47. *
  48. * @return string
  49. */
  50. public function getStatus()
  51. {
  52. return $this->status;
  53. }
  54. /**
  55. * 设置Lifecycle规则状态
  56. *
  57. * @param string $status
  58. */
  59. public function setStatus($status)
  60. {
  61. $this->status = $status;
  62. }
  63. /**
  64. *
  65. * @return LifecycleAction[]
  66. */
  67. public function getActions()
  68. {
  69. return $this->actions;
  70. }
  71. /**
  72. * @param LifecycleAction[] $actions
  73. */
  74. public function setActions($actions)
  75. {
  76. $this->actions = $actions;
  77. }
  78. /**
  79. * LifecycleRule constructor.
  80. *
  81. * @param string $id 规则ID
  82. * @param string $prefix 文件前缀
  83. * @param string $status 规则状态,可选[self::LIFECYCLE_STATUS_ENABLED, self::LIFECYCLE_STATUS_DISABLED]
  84. * @param LifecycleAction[] $actions
  85. */
  86. public function __construct($id, $prefix, $status, $actions)
  87. {
  88. $this->id = $id;
  89. $this->prefix = $prefix;
  90. $this->status = $status;
  91. $this->actions = $actions;
  92. }
  93. /**
  94. * @param \SimpleXMLElement $xmlRule
  95. */
  96. public function appendToXml(&$xmlRule)
  97. {
  98. $xmlRule->addChild('ID', $this->id);
  99. $xmlRule->addChild('Prefix', $this->prefix);
  100. $xmlRule->addChild('Status', $this->status);
  101. foreach ($this->actions as $action) {
  102. $action->appendToXml($xmlRule);
  103. }
  104. }
  105. private $id;
  106. private $prefix;
  107. private $status;
  108. private $actions = array();
  109. const LIFECYCLE_STATUS_ENABLED = 'Enabled';
  110. const LIFECYCLE_STATUS_DISABLED = 'Disabled';
  111. }