WebsiteConfig.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace OSS\Model;
  3. use OSS\Core\OssException;
  4. /**
  5. * Class WebsiteConfig
  6. * @package OSS\Model
  7. * @link http://help.aliyun.com/document_detail/oss/api-reference/bucket/PutBucketWebsite.html
  8. */
  9. class WebsiteConfig implements XmlConfig
  10. {
  11. /**
  12. * WebsiteConfig constructor.
  13. * @param string $indexDocument
  14. * @param string $errorDocument
  15. */
  16. public function __construct($indexDocument = "", $errorDocument = "")
  17. {
  18. $this->indexDocument = $indexDocument;
  19. $this->errorDocument = $errorDocument;
  20. }
  21. /**
  22. * @param string $strXml
  23. * @return null
  24. */
  25. public function parseFromXml($strXml)
  26. {
  27. $xml = simplexml_load_string($strXml);
  28. if (isset($xml->IndexDocument) && isset($xml->IndexDocument->Suffix)) {
  29. $this->indexDocument = strval($xml->IndexDocument->Suffix);
  30. }
  31. if (isset($xml->ErrorDocument) && isset($xml->ErrorDocument->Key)) {
  32. $this->errorDocument = strval($xml->ErrorDocument->Key);
  33. }
  34. }
  35. /**
  36. * Serialize the WebsiteConfig object into xml string.
  37. *
  38. * @return string
  39. * @throws OssException
  40. */
  41. public function serializeToXml()
  42. {
  43. $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><WebsiteConfiguration></WebsiteConfiguration>');
  44. $index_document_part = $xml->addChild('IndexDocument');
  45. $error_document_part = $xml->addChild('ErrorDocument');
  46. $index_document_part->addChild('Suffix', $this->indexDocument);
  47. $error_document_part->addChild('Key', $this->errorDocument);
  48. return $xml->asXML();
  49. }
  50. /**
  51. * @return string
  52. */
  53. public function getIndexDocument()
  54. {
  55. return $this->indexDocument;
  56. }
  57. /**
  58. * @return string
  59. */
  60. public function getErrorDocument()
  61. {
  62. return $this->errorDocument;
  63. }
  64. private $indexDocument = "";
  65. private $errorDocument = "";
  66. }