State.php 5.6 KB

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