TUser implements basic user functionality for a Prado application.
To get the name of the user, use {@link getName Name} property.
The property {@link getIsGuest IsGuest} tells if the user a guest/anonymous user.
To obtain or test the roles that the user is in, use property
{@link getRoles Roles} and call {@link isInRole()}, respectively.
TUser is meant to be used together with {@link IUserManager}.
/** * Returns a user instance given the user name. * @param string user name, null if it is a guest. * @return TUser the user instance, null if the specified username is not in the user database. */ public function getUser($username = null) { if ($username === null) { $user = new TUser($this); $user->setIsGuest(true); return $user; } else { $username = strtolower($username); if (isset($this->_users[$username])) { $user = new TUser($this); $user->setName($username); $user->setIsGuest(false); if (isset($this->_roles[$username])) { $user->setRoles($this->_roles[$username]); } return $user; } else { return null; } } }
public function testStateChanged() { $user = new TUser(self::$mgr); $user->setName('John'); self::assertTrue($user->getStateChanged()); $user->setStateChanged(false); self::assertFalse($user->getStateChanged()); }