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.

92 lines
2.1 KiB

6 years ago
  1. <?php
  2. namespace OSS\Model;
  3. /**
  4. * Class RefererConfig
  5. *
  6. * @package OSS\Model
  7. * @link http://help.aliyun.com/document_detail/oss/api-reference/bucket/PutBucketReferer.html
  8. */
  9. class RefererConfig implements XmlConfig
  10. {
  11. /**
  12. * @param string $strXml
  13. * @return null
  14. */
  15. public function parseFromXml($strXml)
  16. {
  17. $xml = simplexml_load_string($strXml);
  18. if (!isset($xml->AllowEmptyReferer)) return;
  19. if (!isset($xml->RefererList)) return;
  20. $this->allowEmptyReferer =
  21. (strval($xml->AllowEmptyReferer) === 'TRUE' || strval($xml->AllowEmptyReferer) === 'true') ? true : false;
  22. foreach ($xml->RefererList->Referer as $key => $refer) {
  23. $this->refererList[] = strval($refer);
  24. }
  25. }
  26. /**
  27. * 把RefererConfig序列化成xml
  28. *
  29. * @return string
  30. */
  31. public function serializeToXml()
  32. {
  33. $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><RefererConfiguration></RefererConfiguration>');
  34. if ($this->allowEmptyReferer) {
  35. $xml->addChild('AllowEmptyReferer', 'true');
  36. } else {
  37. $xml->addChild('AllowEmptyReferer', 'false');
  38. }
  39. $refererList = $xml->addChild('RefererList');
  40. foreach ($this->refererList as $referer) {
  41. $refererList->addChild('Referer', $referer);
  42. }
  43. return $xml->asXML();
  44. }
  45. /**
  46. * @return string
  47. */
  48. function __toString()
  49. {
  50. return $this->serializeToXml();
  51. }
  52. /**
  53. * @param boolean $allowEmptyReferer
  54. */
  55. public function setAllowEmptyReferer($allowEmptyReferer)
  56. {
  57. $this->allowEmptyReferer = $allowEmptyReferer;
  58. }
  59. /**
  60. * @param string $referer
  61. */
  62. public function addReferer($referer)
  63. {
  64. $this->refererList[] = $referer;
  65. }
  66. /**
  67. * @return boolean
  68. */
  69. public function isAllowEmptyReferer()
  70. {
  71. return $this->allowEmptyReferer;
  72. }
  73. /**
  74. * @return array
  75. */
  76. public function getRefererList()
  77. {
  78. return $this->refererList;
  79. }
  80. private $allowEmptyReferer = true;
  81. private $refererList = array();
  82. }