summaryrefslogtreecommitdiffstats
path: root/Core/SecurityContext.php
diff options
context:
space:
mode:
authorKris Wallsmith <kris.wallsmith@gmail.com>2011-12-08 08:53:01 -0800
committerKris Wallsmith <kris.wallsmith@gmail.com>2011-12-08 08:53:01 -0800
commit571b855fb77836023b28fc3bfd5d5a3b8459e847 (patch)
tree5929eff8b929f7af11bb2f41055f81d25ec10b01 /Core/SecurityContext.php
parent223aaf86a0173c799556c935afa9144d41c76fa2 (diff)
downloadsymfony-security-571b855fb77836023b28fc3bfd5d5a3b8459e847.zip
symfony-security-571b855fb77836023b28fc3bfd5d5a3b8459e847.tar.gz
symfony-security-571b855fb77836023b28fc3bfd5d5a3b8459e847.tar.bz2
[Security] added SecurityContextInterface::getUser()
This changes helps the common use case of fetching the current user and better complies with the Law of Demeter (http://en.wikipedia.org/wiki/Law_of_Demeter). Before (still works): $token = $context->getToken(); $user = $token ? $token->getUser() : null; After: $user = $context->getUser();
Diffstat (limited to 'Core/SecurityContext.php')
-rw-r--r--Core/SecurityContext.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/Core/SecurityContext.php b/Core/SecurityContext.php
index 6d11850..fc39407 100644
--- a/Core/SecurityContext.php
+++ b/Core/SecurityContext.php
@@ -89,4 +89,18 @@ class SecurityContext implements SecurityContextInterface
{
$this->token = $token;
}
+
+ /**
+ * Returns the current user, if one exists.
+ *
+ * @return mixed Returns either an object which implements __toString(),
+ * or a primitive string if there is a token, otherwise
+ * returns null.
+ */
+ public function getUser()
+ {
+ if ($this->token) {
+ return $this->token->getUser();
+ }
+ }
}