Nickname.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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-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. * @see Zend_Gdata_Gapps
  27. */
  28. require_once 'Zend/Gdata/Gapps.php';
  29. /**
  30. * Represents the apps:nickname element used by the Apps data API. This
  31. * is used to describe a nickname's properties, and is usually contained
  32. * within instances of Zend_Gdata_Gapps_NicknameEntry.
  33. *
  34. * @category Zend
  35. * @package Zend_Gdata
  36. * @subpackage Gapps
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Gdata_Gapps_Extension_Nickname extends Zend_Gdata_Extension
  41. {
  42. protected $_rootNamespace = 'apps';
  43. protected $_rootElement = 'nickname';
  44. /**
  45. * The name of the nickname. This name is used as the email address
  46. * for this nickname.
  47. *
  48. * @var string
  49. */
  50. protected $_name = null;
  51. /**
  52. * Constructs a new Zend_Gdata_Gapps_Extension_Nickname object.
  53. * @param string $name (optional) The nickname being represented.
  54. */
  55. public function __construct($name = null)
  56. {
  57. $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
  58. parent::__construct();
  59. $this->_name = $name;
  60. }
  61. /**
  62. * Retrieves a DOMElement which corresponds to this element and all
  63. * child properties. This is used to build an entry back into a DOM
  64. * and eventually XML text for sending to the server upon updates, or
  65. * for application storage/persistence.
  66. *
  67. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  68. * @return DOMElement The DOMElement representing this element and all
  69. * child properties.
  70. */
  71. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  72. {
  73. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  74. if ($this->_name !== null) {
  75. $element->setAttribute('name', $this->_name);
  76. }
  77. return $element;
  78. }
  79. /**
  80. * Given a DOMNode representing an attribute, tries to map the data into
  81. * instance members. If no mapping is defined, the name and value are
  82. * stored in an array.
  83. *
  84. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  85. */
  86. protected function takeAttributeFromDOM($attribute)
  87. {
  88. switch ($attribute->localName) {
  89. case 'name':
  90. $this->_name = $attribute->nodeValue;
  91. break;
  92. default:
  93. parent::takeAttributeFromDOM($attribute);
  94. }
  95. }
  96. /**
  97. * Get the value for this element's name attribute.
  98. *
  99. * @see setName
  100. * @return string The requested attribute.
  101. */
  102. public function getName()
  103. {
  104. return $this->_name;
  105. }
  106. /**
  107. * Set the value for this element's name attribute. This name uniquely
  108. * describes this nickname within the domain. Emails addressed to this
  109. * name will be delivered to the user who owns this nickname.
  110. *
  111. * @param string $value The desired value for this attribute.
  112. * @return Zend_Gdata_Gapps_Extension_Nickname Provides a fluent
  113. * interface.
  114. */
  115. public function setName($value)
  116. {
  117. $this->_name = $value;
  118. return $this;
  119. }
  120. /**
  121. * Magic toString method allows using this directly via echo
  122. * Works best in PHP >= 4.2.0
  123. */
  124. public function __toString()
  125. {
  126. return $this->getName();
  127. }
  128. }