diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index f17db0a..9370a2a 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2044,7 +2044,7 @@ function drupal_hash_base64($data) { /** * Generates a default anonymous $user object. * - * @return Drupal\Core\Session\UserSessionInterface + * @return \Drupal\Core\Session\UserSessionInterface * The user session object. */ function drupal_anonymous_user() { diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index b82167a..0f9acc6 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Entity; use Drupal\Core\Session\UserSessionInterface; -use Drupal\user\Plugin\Core\Entity\User; /** * Defines a default implementation for entity access controllers. @@ -82,8 +81,8 @@ public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * (optional) The language code for which to check access. Defaults to * LANGUAGE_DEFAULT. * @param \Drupal\Core\Session\UserSessionInterface $account - * (optional) The user for which to check access, or NULL to check access - * for the current user. Defaults to NULL. + * (optional) The user session for which to check access, or NULL to check + * access for the current user. Defaults to NULL. * * @return bool|null * TRUE if access was granted, FALSE if access was denied and NULL if access diff --git a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php index 7ff9f83..11da8c9 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php @@ -23,8 +23,8 @@ * (optional) The language code for which to check access. Defaults to * LANGUAGE_DEFAULT. * @param \Drupal\Core\Session\UserSessionInterface $account - * (optional) The user for which to check access, or NULL to check access - * for the current user. Defaults to NULL. + * (optional) The user session for which to check access, or NULL to check + * access for the current user. Defaults to NULL. * * @return bool * TRUE if access was granted, FALSE otherwise. @@ -40,8 +40,8 @@ public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT * (optional) The language code for which to check access. Defaults to * LANGUAGE_DEFAULT. * @param \Drupal\Core\Session\UserSessionInterface $account - * (optional) The user for which to check access, or NULL to check access - * for the current user. Defaults to NULL. + * (optional) The user session for which to check access, or NULL to check + * access for the current user. Defaults to NULL. * * @return bool * TRUE if access was granted, FALSE otherwise. @@ -57,8 +57,8 @@ public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * (optional) The language code for which to check access. Defaults to * LANGUAGE_DEFAULT. * @param \Drupal\Core\Session\UserSessionInterface $account - * (optional) The user for which to check access, or NULL to check access - * for the current user. Defaults to NULL. + * (optional) The user session for which to check access, or NULL to check + * access for the current user. Defaults to NULL. * * @return bool * TRUE if access was granted, FALSE otherwise. @@ -74,8 +74,8 @@ public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * (optional) The language code for which to check access. Defaults to * LANGUAGE_DEFAULT. * @param \Drupal\Core\Session\UserSessionInterface $account - * (optional) The user for which to check access, or NULL to check access - * for the current user. Defaults to NULL. + * (optional) The user session for which to check access, or NULL to check + * access for the current user. Defaults to NULL. * * @return bool * TRUE if access was granted, FALSE otherwise. diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php index 5c50ccd..3ed8247 100644 --- a/core/lib/Drupal/Core/Session/UserSession.php +++ b/core/lib/Drupal/Core/Session/UserSession.php @@ -7,40 +7,109 @@ namespace Drupal\Core\Session; +/** + * An implementation of the user session interface for the global user. + * + * @todo: Change all properties to protected. + */ class UserSession implements UserSessionInterface { - // @todo: Make these protected. + /** + * User ID. + * + * @var int + */ public $uid; + + /** + * Session hostname. + * + * @todo: This does not seem to be used, remove? + * + * @var string + */ public $hostname; + + /** + * List of the roles this user has. + * + * @var array + */ public $roles; + + /** + * Session ID. + * + * @var string. + */ public $sid; + + /** + * Secure session ID. + * + * @var string. + */ public $ssid; + + /** + * Session data. + * + * @var array. + */ public $session; + + /** + * . + * + * @var string. + */ public $timestamp; + /** + * Constructs a new user session. + * + * @param array $values + * Array of initial values for the user sesion. + */ public function __construct(array $values = array()) { foreach ($values as $key => $value) { $this->$key = $value; } } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::id(). + */ public function id() { return $this->uid; } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::getRoles(). + */ public function getRoles() { return $this->roles; } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::getSecureSessionId(). + */ public function getSecureSessionId() { return $this->ssid; } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::getSessionData(). + */ public function getSessionData() { return $this->session; } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::getSessionId(). + */ public function getSessionId() { return $this->sid; } + } \ No newline at end of file diff --git a/core/lib/Drupal/Core/Session/UserSessionInterface.php b/core/lib/Drupal/Core/Session/UserSessionInterface.php index 8dbd7a7..2e7cac7 100644 --- a/core/lib/Drupal/Core/Session/UserSessionInterface.php +++ b/core/lib/Drupal/Core/Session/UserSessionInterface.php @@ -7,10 +7,50 @@ namespace Drupal\Core\Session; +/** + * A user session object. + * + * Defines an object that has a user id, roles and can have session data. The + * interface is implemented both by the global session and the user entity. + */ interface UserSessionInterface { + /** + * Returns the user ID or 0 for anonymous. + * + * @return int + * The user ID. + */ public function id(); + + /** + * Returns a list of roles. + * + * @return array + * List of role IDs. + */ public function getRoles(); + + /** + * Returns the session ID. + * + * @return string|NULL + * The session ID or NULL if this user does not have an active session. + */ public function getSessionId(); + + /** + * Returns the secure session ID. + * + * @return string|NULL + * The session ID or NULL if this user does not have an active secure session. + */ public function getSecureSessionId(); + + /** + * Returns the session data. + * + * @return array + * Array with the session data that belongs to this object. + */ public function getSessionData(); } \ No newline at end of file diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index c062538..06f8438 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -91,8 +91,8 @@ protected function access(EntityInterface $node, $operation, $langcode = LANGUAG * (optional) The language code for which to check access. Defaults to * LANGUAGE_DEFAULT. * @param \Drupal\Core\Session\UserSessionInterface $account - * (optional) The user for which to check access, or NULL to check access - * for the current user. Defaults to NULL. + * (optional) The user session for which to check access, or NULL to check + * access for the current user. Defaults to NULL. * * @return bool|null * TRUE if access was granted, FALSE if access was denied or NULL if no diff --git a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php index efcb8c8..dc71a88 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php @@ -176,18 +176,30 @@ public function id() { return $this->uid; } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::getRoles(). + */ public function getRoles() { return $this->roles; } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::getSecureSessionId(). + */ public function getSecureSessionId() { return NULL; } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::getSessionData(). + */ public function getSessionData() { return array(); } + /** + * Implements \Drupal\Core\Session\UserSessionInterface::getSessionId(). + */ public function getSessionId() { return NULL; }