57f6f1d697f7268bd9d2a716f323fa9c6770c6cf
[yaffs-website] / web / core / lib / Drupal / Core / Session / AccountInterface.php
1 <?php
2
3 namespace Drupal\Core\Session;
4
5 /**
6  * Defines an account interface which represents the current user.
7  *
8  * Defines an object that has a user id, roles and can have session data. The
9  * interface is implemented both by the global session and the user entity.
10  *
11  * @ingroup user_api
12  */
13 interface AccountInterface {
14
15   /**
16    * Role ID for anonymous users.
17    */
18   const ANONYMOUS_ROLE = 'anonymous';
19
20   /**
21    * Role ID for authenticated users.
22    */
23   const AUTHENTICATED_ROLE = 'authenticated';
24
25   /**
26    * Returns the user ID or 0 for anonymous.
27    *
28    * @return int
29    *   The user ID.
30    */
31   public function id();
32
33   /**
34    * Returns a list of roles.
35    *
36    * @param bool $exclude_locked_roles
37    *   (optional) If TRUE, locked roles (anonymous/authenticated) are not returned.
38    *
39    * @return array
40    *   List of role IDs.
41    */
42   public function getRoles($exclude_locked_roles = FALSE);
43
44   /**
45    * Checks whether a user has a certain permission.
46    *
47    * @param string $permission
48    *   The permission string to check.
49    *
50    * @return bool
51    *   TRUE if the user has the permission, FALSE otherwise.
52    */
53   public function hasPermission($permission);
54
55   /**
56    * Returns TRUE if the account is authenticated.
57    *
58    * @return bool
59    *   TRUE if the account is authenticated.
60    */
61   public function isAuthenticated();
62
63   /**
64    * Returns TRUE if the account is anonymous.
65    *
66    * @return bool
67    *   TRUE if the account is anonymous.
68    */
69   public function isAnonymous();
70
71   /**
72    * Returns the preferred language code of the account.
73    *
74    * @param bool $fallback_to_default
75    *   (optional) Whether the return value will fall back to the site default
76    *   language if the user has no language preference.
77    *
78    * @return string
79    *   Returned language code depends upon following:
80    *   - The user preferred language code is returned if set in the account.
81    *   - If the user has no preferred language and $fallback_to_default is TRUE
82    *     then the site default language code is returned.
83    *   - If the user has no preferred language and $fallback_to_default is FALSE
84    *     then empty string is returned.
85    */
86   public function getPreferredLangcode($fallback_to_default = TRUE);
87
88   /**
89    * Returns the preferred administrative language code of the account.
90    *
91    * Defines which language is used on administrative pages.
92    *
93    * @param bool $fallback_to_default
94    *   (optional) Whether the return value will fall back to the site default
95    *   language if the user has no administration language preference.
96    *
97    * @return string
98    *   The language code that is preferred by the account for administration
99    *   pages. If the preferred language is not set or is a language not
100    *   configured anymore on the site, the site default is returned or an empty
101    *   string is returned (if $fallback_to_default is FALSE).
102    */
103   public function getPreferredAdminLangcode($fallback_to_default = TRUE);
104
105   /**
106    * Returns the unaltered login name of this account.
107    *
108    * @return string
109    *   An unsanitized plain-text string with the name of this account that is
110    *   used to log in. Only display this name to admins and to the user who owns
111    *   this account, and only in the context of the name used to log in. For
112    *   any other display purposes, use
113    *   \Drupal\Core\Session\AccountInterface::getDisplayName() instead.
114    *
115    * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
116    *   Use \Drupal\Core\Session\AccountInterface::getAccountName() or
117    *   \Drupal\user\UserInterface::getDisplayName() instead.
118    */
119   public function getUsername();
120
121   /**
122    * Returns the unaltered login name of this account.
123    *
124    * @return string
125    *   An unsanitized plain-text string with the name of this account that is
126    *   used to log in. Only display this name to admins and to the user who owns
127    *   this account, and only in the context of the name used to login. For
128    *   any other display purposes, use
129    *   \Drupal\Core\Session\AccountInterface::getDisplayName() instead.
130    */
131   public function getAccountName();
132
133   /**
134    * Returns the display name of this account.
135    *
136    * By default, the passed-in object's 'name' property is used if it exists, or
137    * else, the site-defined value for the 'anonymous' variable. However, a
138    * module may override this by implementing
139    * hook_user_format_name_alter(&$name, $account).
140    *
141    * @see hook_user_format_name_alter()
142    *
143    * @return string|\Drupal\Component\Render\MarkupInterface
144    *   Either a string that will be auto-escaped on output or a
145    *   MarkupInterface object that is already HTML escaped. Either is safe
146    *   to be printed within HTML fragments.
147    */
148   public function getDisplayName();
149
150   /**
151    * Returns the email address of this account.
152    *
153    * @return string|null
154    *   The email address, or NULL if the account is anonymous or the user does
155    *   not have an email address.
156    */
157   public function getEmail();
158
159   /**
160    * Returns the timezone of this account.
161    *
162    * @return string
163    *   Name of the timezone.
164    */
165   public function getTimeZone();
166
167   /**
168    * The timestamp when the account last accessed the site.
169    *
170    * A value of 0 means the user has never accessed the site.
171    *
172    * @return int
173    *   Timestamp of the last access.
174    */
175   public function getLastAccessedTime();
176
177 }