LiveChannelConfig.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace OSS\Model;
  3. /**
  4. * Class LiveChannelConfig
  5. * @package OSS\Model
  6. */
  7. class LiveChannelConfig implements XmlConfig
  8. {
  9. public function __construct($option = array())
  10. {
  11. if (isset($option['description'])) {
  12. $this->description = $option['description'];
  13. }
  14. if (isset($option['status'])) {
  15. $this->status = $option['status'];
  16. }
  17. if (isset($option['type'])) {
  18. $this->type = $option['type'];
  19. }
  20. if (isset($option['fragDuration'])) {
  21. $this->fragDuration = $option['fragDuration'];
  22. }
  23. if (isset($option['fragCount'])) {
  24. $this->fragCount = $option['fragCount'];
  25. }
  26. if (isset($option['playListName'])) {
  27. $this->playListName = $option['playListName'];
  28. }
  29. }
  30. public function getDescription()
  31. {
  32. return $this->description;
  33. }
  34. public function getStatus()
  35. {
  36. return $this->status;
  37. }
  38. public function getType()
  39. {
  40. return $this->type;
  41. }
  42. public function getFragDuration()
  43. {
  44. return $this->fragDuration;
  45. }
  46. public function getFragCount()
  47. {
  48. return $this->fragCount;
  49. }
  50. public function getPlayListName()
  51. {
  52. return $this->playListName;
  53. }
  54. public function parseFromXml($strXml)
  55. {
  56. $xml = simplexml_load_string($strXml);
  57. $this->description = strval($xml->Description);
  58. $this->status = strval($xml->Status);
  59. $target = $xml->Target;
  60. $this->type = strval($target->Type);
  61. $this->fragDuration = intval($target->FragDuration);
  62. $this->fragCount = intval($target->FragCount);
  63. $this->playListName = strval($target->PlayListName);
  64. }
  65. public function serializeToXml()
  66. {
  67. $strXml = <<<EOF
  68. <?xml version="1.0" encoding="utf-8"?>
  69. <LiveChannelConfiguration>
  70. </LiveChannelConfiguration>
  71. EOF;
  72. $xml = new \SimpleXMLElement($strXml);
  73. if (isset($this->description)) {
  74. $xml->addChild('Description', $this->description);
  75. }
  76. if (isset($this->status)) {
  77. $xml->addChild('Status', $this->status);
  78. }
  79. $node = $xml->addChild('Target');
  80. $node->addChild('Type', $this->type);
  81. if (isset($this->fragDuration)) {
  82. $node->addChild('FragDuration', $this->fragDuration);
  83. }
  84. if (isset($this->fragCount)) {
  85. $node->addChild('FragCount', $this->fragCount);
  86. }
  87. if (isset($this->playListName)) {
  88. $node->addChild('PlayListName', $this->playListName);
  89. }
  90. return $xml->asXML();
  91. }
  92. public function __toString()
  93. {
  94. return $this->serializeToXml();
  95. }
  96. private $description;
  97. private $status = "enabled";
  98. private $type;
  99. private $fragDuration = 5;
  100. private $fragCount = 3;
  101. private $playListName = "playlist.m3u8";
  102. }