$roles * @property array $data */ class SimpleIdentity implements IIdentity { private string|int $id; /** @var list */ private array $roles; /** @var array */ private array $data; /** * @param string|list|null $roles * @param ?iterable $data */ public function __construct(string|int $id, string|array|null $roles = null, ?iterable $data = null) { $this->setId($id); $this->setRoles((array) $roles); $this->data = iterator_to_array($data ?? []); } /** * Sets the ID of user. */ public function setId(string|int $id): static { $this->id = is_string($id) && ctype_digit($id) && (string) ($tmp = (int) $id) === $id ? $tmp : $id; return $this; } /** * Returns the ID of user. */ public function getId(): string|int { return $this->id; } /** * Sets a list of roles that the user is a member of. * @param list $roles */ public function setRoles(array $roles): static { $this->roles = $roles; return $this; } /** * Returns a list of roles that the user is a member of. * @return list */ public function getRoles(): array { return $this->roles; } /** * Returns user data. * @return array */ public function getData(): array { return $this->data; } /** * Sets user data value. */ public function __set(string $key, mixed $value): void { match ($key) { 'id' => $this->setId($value), 'roles' => $this->setRoles($value), 'data' => $this->data = $value, default => $this->data[$key] = $value, }; } /** * Returns user data value. */ public function &__get(string $key): mixed { if (in_array($key, ['id', 'roles', 'data'], strict: true)) { $res = $this->{'get' . ucfirst($key)}(); return $res; } else { return $this->data[$key]; } } public function __isset(string $key): bool { return isset($this->data[$key]) || in_array($key, ['id', 'roles', 'data'], strict: true); } public function __serialize(): array { return [ 'id' => $this->id, 'roles' => $this->roles, 'data' => $this->data, ]; } public function __unserialize(array $data): void { $this->id = $data['id'] ?? $data["\00Nette\\Security\\Identity\00id"] ?? 0; $this->roles = $data['roles'] ?? $data["\00Nette\\Security\\Identity\00roles"] ?? []; $this->data = $data['data'] ?? $data["\00Nette\\Security\\Identity\00data"] ?? []; } }