API / Minn\Content / Users

Users final readonly class

Minn\Content\Users · public/minn/src/Minn/Content/Users.php · 286 lines

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

Public

new__construct(Minn\Db $db)#
methodfind(int $id): ?Minn\Content\UserRecord#

The user with this id, or null.

methodfindByLogin(string $login): ?Minn\Content\UserRecord#

The user with this login, or null.

methodfindByEmail(string $email): ?Minn\Content\UserRecord#

The user with this email, or null.

methodfindBySlug(string $nicename): ?Minn\Content\UserRecord#

The user with this nicename, or null.

methoduniqueNicename(string $base, int $skipId = 0): string#

The unique-nicename rule: sanitized login, -2, -3 on collision.

methodcreateAccount(array $fields): int#

Inserts a user and the 14 default meta rows the reference writes.

login: string, email: string, password: string, role: string, display_name: string, url?: string, nicename?: string, nickname?: string, first_name?: string, last_name?: string, description?: string, locale?: string, } $fields

staticdefaultDisplayName(string $first, string $last, string $login): string#

The display name an account gets when none is given, as the reference picks it: first and last name, whichever of the two there is, or the login. The nickname plays no part.

methodinsertAccount(array $fields): int#

A new account's row alone: the caller adds its meta and role, and keeps the count. @param array<string, mixed> $fields

$fieldsarray<string, mixed>
staticprofileMeta(array $fields): array#

The twelve profile meta rows the reference gives a new account, in its order (the role's two follow).

$fieldsarray<string, mixed>
@return array<string, string>
methodrecount(): void#

Recounts the accounts into user_count, quietly.

methoddeleteRow(int $id): void#

Removes the account's row alone: the caller removes its meta and keeps the count.

methodinsert(array $columns): int#

Inserts a users row from column => value pairs and returns the new id.

$columnsarray<string, mixed>
methodupdate(int $id, array $columns): void#

Sets the given columns on one user.

$columnsarray<string, mixed>
methoddelete(int $id): void#

Removes the user and their meta; their posts are reassigned or removed first by the caller.

methodids(int $limit): array#

User ids in login order, optionally the first N. @return list<int>

@return list<int>
methodsetPassword(int $userId, string $hash): void#

Stores a new password hash and clears any pending reset key.

methodcount(): int#

How many users the site has.

methodregisteredAfter(string $since, int $limit): array#

The newest users registered since a site-local time, up to the limit.

@return list<array> the newest registrations after a site-local timestamp
methoddeleteMeta(int $userId, string $key): void#

Removes one meta key from a user.

methodwithCapabilities(string $capabilitiesKey): array#

Every user with a capabilities row under the key given, as the old get_users_of_blog listed them: id twice, login, display name, email and the stored capabilities, in id order.

@return list<array<string, string>>
methodwithoutRole(string $capabilitiesKey, string $rolePattern): array#

The ids of users whose capabilities row names none of the roles (a pattern of their names). @return list<string>

@return list<string>
methodmeta(int $userId, string $key): ?string#

One usermeta value, raw. Serialized blobs come back as stored.

methodsetMeta(int $userId, string $key, string $value): void#

Replaces one usermeta row. The (user_id, meta_key) pair carries no unique index on the stock schema, so this is a delete plus insert rather than an upsert.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privaterecord(?array $row): ?Minn\Content\UserRecord#
$rowarray<string, mixed>|null
privaterefreshCount(): void#

The user_count option, which the reference keeps current as accounts come and go. A site without the row is left without it.

privatewriteAccount(array $fields): int#

The account's row and the fourteen meta rows the reference gives a new user, written as one unit by createAccount().

$fieldsarray<string, mixed>