* @package generis */ class SessionService extends ConfigurableService { const SERVICE_ID = 'generis/session'; /** * Returns the currently active session * @return \common_session_Session */ public function getCurrentSession() { return \common_session_SessionManager::getSession(); } /** * Returns the current user * @throws \common_exception_Error * @return \oat\oatbox\user\User */ public function getCurrentUser() { return $this->getCurrentSession()->getUser(); } /** * Is the current session anonymous or associated to a user? * @return boolean */ public function isAnonymous() { return $this->getCurrentUser() instanceof AnonymousUser; } /** * Starts a new session and stores it in the session if stateful * * @param \common_session_Session $session * @return boolean */ public function setSession(\common_session_Session $session) { return \common_session_SessionManager::startSession($session); } }