We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 70932c6 commit cacd7c6Copy full SHA for cacd7c6
Controller/Controller.php
@@ -165,6 +165,24 @@ public function getDoctrine()
165
return $this->container->get('doctrine');
166
}
167
168
+ /**
169
+ * Get a user from the Security Context
170
+ *
171
+ * @return mixed
172
173
+ * @throws \LogicException If SecurityBundle is not available
174
+ */
175
+ public function getUser()
176
+ {
177
+ if (!$this->container->has('security.context')) {
178
+ throw new \LogicException('The SecurityBundle is not installed in your application.');
179
+ }
180
+
181
+ $token = $this->container->get('security.context')->getToken();
182
183
+ return null === $token ?: $token->getUser();
184
185
186
/**
187
* Returns true if the service id is defined.
188
*
0 commit comments