Property.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 Gapps
  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: EmailList.php 20096 2010-01-06 02:05:09Z bkarwin $
  21. */
  22. /**
  23. * @see Zend_Gdata_Extension
  24. */
  25. require_once 'Zend/Gdata/Extension.php';
  26. /**
  27. * @see Zend_Gdata_Gapps
  28. */
  29. require_once 'Zend/Gdata/Gapps.php';
  30. /**
  31. * Represents the apps:Property element used by the Apps data API.
  32. *
  33. * @category Zend
  34. * @package Zend_Gdata
  35. * @subpackage Gapps
  36. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Gdata_Gapps_Extension_Property extends Zend_Gdata_Extension
  40. {
  41. protected $_rootNamespace = 'apps';
  42. protected $_rootElement = 'property';
  43. /**
  44. * The name of the property
  45. *
  46. * @var string
  47. */
  48. protected $_name = null;
  49. /**
  50. * The value of the property
  51. * @var string
  52. */
  53. protected $_value = null;
  54. /**
  55. * Constructs a new Zend_Gdata_Gapps_Extension_Property object.
  56. *
  57. * @param string $name The name of the property
  58. * @param string $value The value of the property
  59. */
  60. public function __construct($name = null, $value = null)
  61. {
  62. $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
  63. parent::__construct();
  64. $this->_name = $name;
  65. $this->_value = $value;
  66. }
  67. /**
  68. * Retrieves a DOMElement which corresponds to this element and all
  69. * child properties. This is used to build an entry back into a DOM
  70. * and eventually XML text for sending to the server upon updates, or
  71. * for application storage/persistence.
  72. *
  73. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  74. * @return DOMElement The DOMElement representing this element and all
  75. * child properties.
  76. */
  77. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  78. {
  79. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  80. if ($this->_name !== null) {
  81. $element->setAttribute('name', $this->_name);
  82. }
  83. if ($this->_value !== null) {
  84. $element->setAttribute('value', $this->_value);
  85. }
  86. return $element;
  87. }
  88. /**
  89. * Given a DOMNode representing an attribute, tries to map the data into
  90. * instance members. If no mapping is defined, the name and value are
  91. * stored in an array.
  92. *
  93. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  94. */
  95. protected function takeAttributeFromDOM($attribute)
  96. {
  97. switch ($attribute->localName) {
  98. case 'name':
  99. $this->_name = $attribute->nodeValue;
  100. break;
  101. case 'value':
  102. $this->_value = $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. * @see setName
  112. * @return string The requested attribute.
  113. */
  114. public function getName()
  115. {
  116. return $this->_name;
  117. }
  118. /**
  119. * Set the value for this element's name attribute.
  120. * @param string $value The desired value for this attribute.
  121. * @return Zend_Gdata_Gapps_Extension_Property 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 value attribute.
  130. *
  131. * @see setName
  132. * @return string The requested attribute.
  133. */
  134. public function getValue()
  135. {
  136. return $this->_value;
  137. }
  138. /**
  139. * Set the value for this element's value attribute.
  140. *
  141. * @param string $value The desired value for this attribute.
  142. * @return Zend_Gdata_Gapps_Extension_Property The element being modified.
  143. */
  144. public function setValue($value)
  145. {
  146. $this->_value = $value;
  147. return $this;
  148. }
  149. /**
  150. * Magic toString method allows using this directly via echo
  151. * Works best in PHP >= 4.2.0
  152. *
  153. * @return string
  154. */
  155. public function __toString()
  156. {
  157. return "Property Name: " . $this->getName() .
  158. "\nProperty Value: " . $this->getValue();
  159. }
  160. }