/library/Zend/Gdata/Gapps/Extension/Name.php

https://bitbucket.org/hamidrezas/melobit · PHP · 181 lines · 63 code · 16 blank · 102 comment · 3 complexity · 9e2864388fb6e16766381e9f6c786046 MD5 · raw file

  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Name.php 24594 2012-01-05 21:27:01Z matthew $
  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:name element used by the Apps data API. This is used
  32. * to represent a user's full name. This class is usually contained within
  33. * instances of Zend_Gdata_Gapps_UserEntry.
  34. *
  35. * @category Zend
  36. * @package Zend_Gdata
  37. * @subpackage Gapps
  38. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Gdata_Gapps_Extension_Name extends Zend_Gdata_Extension
  42. {
  43. protected $_rootNamespace = 'apps';
  44. protected $_rootElement = 'name';
  45. /**
  46. * The associated user's family name.
  47. *
  48. * @var string
  49. */
  50. protected $_familyName = null;
  51. /**
  52. * The associated user's given name.
  53. *
  54. * @var string
  55. */
  56. protected $_givenName = null;
  57. /**
  58. * Constructs a new Zend_Gdata_Gapps_Extension_Name object.
  59. *
  60. * @param string $familyName (optional) The familyName to be set for this
  61. * object.
  62. * @param string $givenName (optional) The givenName to be set for this
  63. * object.
  64. */
  65. public function __construct($familyName = null, $givenName = null)
  66. {
  67. $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
  68. parent::__construct();
  69. $this->_familyName = $familyName;
  70. $this->_givenName = $givenName;
  71. }
  72. /**
  73. * Retrieves a DOMElement which corresponds to this element and all
  74. * child properties. This is used to build an entry back into a DOM
  75. * and eventually XML text for sending to the server upon updates, or
  76. * for application storage/persistence.
  77. *
  78. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  79. * @return DOMElement The DOMElement representing this element and all
  80. * child properties.
  81. */
  82. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  83. {
  84. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  85. if ($this->_familyName !== null) {
  86. $element->setAttribute('familyName', $this->_familyName);
  87. }
  88. if ($this->_givenName !== null) {
  89. $element->setAttribute('givenName', $this->_givenName);
  90. }
  91. return $element;
  92. }
  93. /**
  94. * Given a DOMNode representing an attribute, tries to map the data into
  95. * instance members. If no mapping is defined, the name and value are
  96. * stored in an array.
  97. *
  98. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  99. */
  100. protected function takeAttributeFromDOM($attribute)
  101. {
  102. switch ($attribute->localName) {
  103. case 'familyName':
  104. $this->_familyName = $attribute->nodeValue;
  105. break;
  106. case 'givenName':
  107. $this->_givenName = $attribute->nodeValue;
  108. break;
  109. default:
  110. parent::takeAttributeFromDOM($attribute);
  111. }
  112. }
  113. /**
  114. * Get the value for this element's familyName attribute.
  115. *
  116. * @see setFamilyName
  117. * @return string The requested attribute.
  118. */
  119. public function getFamilyName()
  120. {
  121. return $this->_familyName;
  122. }
  123. /**
  124. * Set the value for this element's familyName attribute. This
  125. * represents a user's family name.
  126. *
  127. * @param string $value The desired value for this attribute.
  128. * @return Zend_Gdata_Gapps_Extension_Name Provides a fluent interface..
  129. */
  130. public function setFamilyName($value)
  131. {
  132. $this->_familyName = $value;
  133. return $this;
  134. }
  135. /**
  136. * Get the value for this element's givenName attribute.
  137. *
  138. * @see setGivenName
  139. * @return string The requested attribute.
  140. */
  141. public function getGivenName()
  142. {
  143. return $this->_givenName;
  144. }
  145. /**
  146. * Set the value for this element's givenName attribute. This
  147. * represents a user's given name.
  148. *
  149. * @param string $value The desired value for this attribute.
  150. * @return Zend_Gdata_Gapps_Extension_Name Provides a fluent interface.
  151. */
  152. public function setGivenName($value)
  153. {
  154. $this->_givenName = $value;
  155. return $this;
  156. }
  157. /**
  158. * Magic toString method allows using this directly via echo
  159. * Works best in PHP >= 4.2.0
  160. */
  161. public function __toString()
  162. {
  163. return $this->getGivenName() . ' ' . $this->getFamilyName();
  164. }
  165. }