用户界面

4.2.0 2023-05-26 17:50 UTC

This package is auto-updated.

Last update: 2024-08-26 20:48:31 UTC


README

Build Status

用户界面描述单个用户

  1. ID(如果可用),
  2. 名,
  3. 姓,
  4. 电子邮件地址。

名和姓可以从全名解析,或者根据您选择的实现策略,全名可以由名和姓组成。

已识别和未识别访客

此库提供了两个稳定的类:`ActiveCollab\User\UnidentifiedVisitor` 是我们一无所知的访客,而 `ActiveCollab\User\IdentifiedVisitor` 描述了一个通过提供电子邮件地址(可选全名)来宣布其身份的单个用户。

$user = new ActiveCollab\User\IdentifiedVisitor('Ilija Studen', 'ilija@example.com');

print $user->getFirstName() . "\n";
print $user->getLastName() . "\n";
print $user->formatName(ActiveCollab\User\UserInterface::NAME_INITIALS) . "\n";

拥有账户的用户

如果应用程序具有用户账户的概念,则这些类应实现 `ActiveCollab\User\UserInterface` 并提供访问所需属性

  1. 用户ID,
  2. 用户的电子邮件地址,
  3. 用户的名和姓或全名。

根据您存储的 #3 的内容,您可以使用这两个特质之一将大多数 UserInterface 实现粘贴到您的用户类中

  1. ActiveCollab\User\UserInterface\ImplementationUsingFirstAndLastName
  2. ActiveCollab\User\UserInterface\ImplementationUsingFullName

序列化

所有实现 ActiveCollab\User\UserInterface 的实例都可以序列化为 JSON

$user = new ActiveCollab\User\IdentifiedVisitor('Ilija Studen', 'ilija@example.com');
print_r(json_decode(json_encode($user), true));

将输出

(
    [id] => 0
    [class] => ActiveCollab\User\IdentifiedVisitor
    [first_name] => Ilija
    [last_name] => Studen
    [full_name] => Ilija Studen
    [email] => ilija@example.com
)

比较用户

`UserInterface::is()` 方法在您需要检查特定用户实例是否与另一个实例是同一个人时很有用

$user1 = new ActiveCollab\User\IdentifiedVisitor('John Doe', 'john@example.com');
$user2 = new ActiveCollab\User\IdentifiedVisitor('Jane Doe', 'jane@example.com');

if ($user1->is($user2)) {
    print "Same person\n";
} else {
    print "Not the same person\n";
}

拥有账户的用户(ID > 0)通过其 ID 进行比较,而未拥有账户的访客则通过其电子邮件地址进行比较。比较不混合,因此拥有账户的用户永远不会被识别为访客,即使他们的电子邮件地址匹配。