* @package oat\tao\model */ class SessionSubstitutionService extends ConfigurableService implements \oat\tao\model\SessionSubstitutionService { /** * @param User $user * @return PretenderSession new session instance */ public function substituteSession(User $user) { $session = new PretenderSession($user); common_session_SessionManager::startSession($session); return $session; } /** * @return boolean */ public function isSubstituted() { $result = false; $session = common_session_SessionManager::getSession(); if ($session instanceof PretenderSession) { $result = true; } return $result; } /** * @return void * @return common_session_Session original session instance * @throws \Exception */ public function revert() { $session = common_session_SessionManager::getSession(); if ($session instanceof PretenderSession) { $session->restoreOriginal(); } else { throw new \Exception('Session has not been substituted.'); } return common_session_SessionManager::getSession(); } }