UserDataInterface.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Drupal\user;
  3. /**
  4. * Defines the user data service interface.
  5. */
  6. interface UserDataInterface {
  7. /**
  8. * Returns data stored for a user account.
  9. *
  10. * @param string $module
  11. * The name of the module the data is associated with.
  12. * @param int $uid
  13. * (optional) The user account ID the data is associated with.
  14. * @param string $name
  15. * (optional) The name of the data key.
  16. *
  17. * @return mixed|array
  18. * The requested user account data, depending on the arguments passed:
  19. * - For $module, $name, and $uid, the stored value is returned, or NULL if
  20. * no value was found.
  21. * - For $module and $uid, an associative array is returned that contains
  22. * the stored data name/value pairs.
  23. * - For $module and $name, an associative array is returned whose keys are
  24. * user IDs and whose values contain the stored values.
  25. * - For $module only, an associative array is returned that contains all
  26. * existing data for $module in all user accounts, keyed first by user ID
  27. * and $name second.
  28. */
  29. public function get($module, $uid = NULL, $name = NULL);
  30. /**
  31. * Stores data for a user account.
  32. *
  33. * @param string $module
  34. * The name of the module the data is associated with.
  35. * @param int $uid
  36. * The user account ID the data is associated with.
  37. * @param string $name
  38. * The name of the data key.
  39. * @param mixed $value
  40. * The value to store. Non-scalar values are serialized automatically.
  41. */
  42. public function set($module, $uid, $name, $value);
  43. /**
  44. * Deletes data stored for a user account.
  45. *
  46. * @param string|array $module
  47. * (optional) The name of the module the data is associated with. Can also
  48. * be an array to delete the data of multiple modules.
  49. * @param int|array $uid
  50. * (optional) The user account ID the data is associated with. If omitted,
  51. * all data for $module is deleted. Can also be an array of IDs to delete
  52. * the data of multiple user accounts.
  53. * @param string $name
  54. * (optional) The name of the data key. If omitted, all data associated with
  55. * $module and $uid is deleted.
  56. */
  57. public function delete($module = NULL, $uid = NULL, $name = NULL);
  58. }