public function runAs($userId, $call, array $args = array()) { $origUser = $this->_loggedUser; $exception = NULL; if ($this->_runAs) { throw new RM_Base_Exception_BadUsage("Nested runAs() is prohibited!"); } $this->_runAs = 1; $this->_loggedUser = $userId == 0 ? $this->_mapper->getAnonymousUser() : $this->_mapper->loadUserById($userId); // change user context try { $result = call_user_func_array($call, $args); } catch (Exception $e) { $exception = $e; } $this->_loggedUser = $origUser; // restore user context $this->_runAs = 0; if ($exception) { throw $exception; } return $result; }
public function loadUserById($id) { return $this->_mapper->loadUserById($id); }