Nickname.php 4.1 KB

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