GraphUser.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Copyright 2014 Facebook, Inc.
  4. *
  5. * You are hereby granted a non-exclusive, worldwide, royalty-free license to
  6. * use, copy, modify, and distribute this software in source code or binary
  7. * form for use in connection with the web services and APIs provided by
  8. * Facebook.
  9. *
  10. * As with any software that integrates with the Facebook platform, your use
  11. * of this software is subject to the Facebook Developer Principles and
  12. * Policies [http://developers.facebook.com/policy/]. This copyright notice
  13. * shall be included in all copies or substantial portions of the software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24. namespace Facebook;
  25. /**
  26. * Class GraphUser
  27. * @package Facebook
  28. * @author Fosco Marotto <fjm@fb.com>
  29. * @author David Poll <depoll@fb.com>
  30. */
  31. class GraphUser extends GraphObject
  32. {
  33. /**
  34. * Returns the ID for the user as a string if present.
  35. *
  36. * @return string|null
  37. */
  38. public function getId()
  39. {
  40. return $this->getProperty('id');
  41. }
  42. /**
  43. * Returns the name for the user as a string if present.
  44. *
  45. * @return string|null
  46. */
  47. public function getName()
  48. {
  49. return $this->getProperty('name');
  50. }
  51. public function getEmail()
  52. {
  53. return $this->getProperty('email');
  54. }
  55. /**
  56. * Returns the first name for the user as a string if present.
  57. *
  58. * @return string|null
  59. */
  60. public function getFirstName()
  61. {
  62. return $this->getProperty('first_name');
  63. }
  64. /**
  65. * Returns the middle name for the user as a string if present.
  66. *
  67. * @return string|null
  68. */
  69. public function getMiddleName()
  70. {
  71. return $this->getProperty('middle_name');
  72. }
  73. /**
  74. * Returns the last name for the user as a string if present.
  75. *
  76. * @return string|null
  77. */
  78. public function getLastName()
  79. {
  80. return $this->getProperty('last_name');
  81. }
  82. /**
  83. * Returns the Facebook URL for the user as a string if available.
  84. *
  85. * @return string|null
  86. */
  87. public function getLink()
  88. {
  89. return $this->getProperty('link');
  90. }
  91. /**
  92. * Returns the users birthday, if available.
  93. *
  94. * @return \DateTime|null
  95. */
  96. public function getBirthday()
  97. {
  98. $value = $this->getProperty('birthday');
  99. if ($value) {
  100. return new \DateTime($value);
  101. }
  102. return null;
  103. }
  104. /**
  105. * Returns the current location of the user as a FacebookGraphLocation
  106. * if available.
  107. *
  108. * @return GraphLocation|null
  109. */
  110. public function getLocation()
  111. {
  112. return $this->getProperty('location', GraphLocation::className());
  113. }
  114. }