State.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage YouTube
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata_Extension
  24. */
  25. require_once 'Zend/Gdata/Extension.php';
  26. /**
  27. * Represents the yt:state element used by the YouTube data API
  28. *
  29. * @category Zend
  30. * @package Zend_Gdata
  31. * @subpackage YouTube
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Gdata_YouTube_Extension_State extends Zend_Gdata_Extension
  36. {
  37. protected $_rootNamespace = 'yt';
  38. protected $_rootElement = 'state';
  39. protected $_name = null;
  40. protected $_reasonCode = null;
  41. protected $_helpUrl = null;
  42. /**
  43. * Constructs a new Zend_Gdata_YouTube_Extension_State object.
  44. *
  45. * @param string $explanation(optional) The explanation of this state
  46. * @param string $name(optional) The name value
  47. * @param string $reasonCode(optional) The reasonCode value
  48. * @param string $helpUrl(optional) The helpUrl value
  49. */
  50. public function __construct($explanation = null, $name = null,
  51. $reasonCode = null, $helpUrl = null)
  52. {
  53. $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
  54. parent::__construct();
  55. $this->_text = $explanation;
  56. $this->_name = $name;
  57. $this->_reasonCode = $reasonCode;
  58. $this->_helpUrl = $reasonCode;
  59. }
  60. /**
  61. * Retrieves a DOMElement which corresponds to this element and all
  62. * child properties. This is used to build an entry back into a DOM
  63. * and eventually XML text for sending to the server upon updates, or
  64. * for application storage/persistence.
  65. *
  66. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  67. * @return DOMElement The DOMElement representing this element and all
  68. * child properties.
  69. */
  70. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  71. {
  72. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  73. if ($this->_name !== null) {
  74. $element->setAttribute('name', $this->_name);
  75. }
  76. if ($this->_reasonCode !== null) {
  77. $element->setAttribute('reasonCode', $this->_reasonCode);
  78. }
  79. if ($this->_helpUrl !== null) {
  80. $element->setAttribute('helpUrl', $this->_helpUrl);
  81. }
  82. return $element;
  83. }
  84. /**
  85. * Given a DOMNode representing an attribute, tries to map the data into
  86. * instance members. If no mapping is defined, the name and valueare
  87. * stored in an array.
  88. * TODO: Convert attributes to proper types
  89. *
  90. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  91. */
  92. protected function takeAttributeFromDOM($attribute)
  93. {
  94. switch ($attribute->localName) {
  95. case 'name':
  96. $this->_name = $attribute->nodeValue;
  97. break;
  98. case 'reasonCode':
  99. $this->_reasonCode = $attribute->nodeValue;
  100. break;
  101. case 'helpUrl':
  102. $this->_helpUrl = $attribute->nodeValue;
  103. break;
  104. default:
  105. parent::takeAttributeFromDOM($attribute);
  106. }
  107. }
  108. /**
  109. * Get the value for this element's name attribute.
  110. *
  111. * @return int The value associated with this attribute.
  112. */
  113. public function getName()
  114. {
  115. return $this->_name;
  116. }
  117. /**
  118. * Set the value for this element's name attribute.
  119. *
  120. * @param int $value The desired value for this attribute.
  121. * @return Zend_Gdata_YouTube_Extension_State The element being modified.
  122. */
  123. public function setName($value)
  124. {
  125. $this->_name = $value;
  126. return $this;
  127. }
  128. /**
  129. * Get the value for this element's reasonCode attribute.
  130. *
  131. * @return int The value associated with this attribute.
  132. */
  133. public function getReasonCode()
  134. {
  135. return $this->_reasonCode;
  136. }
  137. /**
  138. * Set the value for this element's reasonCode attribute.
  139. *
  140. * @param int $value The desired value for this attribute.
  141. * @return Zend_Gdata_YouTube_Extension_State The element being modified.
  142. */
  143. public function setReasonCode($value)
  144. {
  145. $this->_reasonCode = $value;
  146. return $this;
  147. }
  148. /**
  149. * Get the value for this element's helpUrl attribute.
  150. *
  151. * @return int The value associated with this attribute.
  152. */
  153. public function getHelpUrl()
  154. {
  155. return $this->_helpUrl;
  156. }
  157. /**
  158. * Set the value for this element's helpUrl attribute.
  159. *
  160. * @param int $value The desired value for this attribute.
  161. * @return Zend_Gdata_YouTube_Extension_State The element being modified.
  162. */
  163. public function setHelpUrl($value)
  164. {
  165. $this->_helpUrl = $value;
  166. return $this;
  167. }
  168. /**
  169. * Magic toString method allows using this directly via echo
  170. * Works best in PHP >= 4.2.0
  171. *
  172. * @return string
  173. */
  174. public function __toString()
  175. {
  176. return $this->_text;
  177. }
  178. }