CoolCMS API

UserMapper extends ApiMapper
in package
uses SaveTrait

FinalYes

Front mapper that hydrates Api repository data into entities.

Tags
extends

Table of Contents

Properties

$hydrator  : EntityHydrator
$repository  : UserRepository

Methods

__construct()  : mixed
activateUser()  : Result
Pass-through; the response is only a Result, there is nothing to hydrate.
cancelDeletion()  : Result
confirmDeletion()  : Result
confirmExternalLink()  : Result
deauthorizeExternal()  : Result
emailExists()  : bool|null
See {@see self::usernameExists()}.
find()  : T|null
findAll()  : T>, 1: int}
findBy()  : T|null
findPublicProfile()  : PublicProfile|null
Hydrates the public profile by hand into {@see PublicProfile}.
findPublicProfiles()  : array<int, PublicProfile>
Bulk variant of {@see self::findPublicProfile()}.
login()  : Result
loginExternal()  : Result
referralOverview()  : Result
Affiliate program for the "My account" page (`:Api:System:User:referralOverview`).
requestDeletion()  : Result
resetPassword()  : Result
revealPhone()  : string
Raw phone from {@see UserRepository::revealPhone()}.
save()  : Result
sendActivationEmail()  : Result
sendNewPassword()  : Result
Replaced `generateNewPassword(int $userId)`, see the repository.
updateColumns()  : Result
updatePassword()  : Result
usernameExists()  : bool|null
Pass-through; the response is a single bool, there is nothing to hydrate.
getEntityClass()  : T>
initalizeEntity()  : User|null
toDate()  : DateTimeImmutable|null
`ATOM` string from the Api payload to `DateTimeImmutable`; an unreadable value gives `null`, not an exception.
toPublicProfile()  : PublicProfile|null
The only place that builds {@see PublicProfile} from the Api payload; shared by the single and bulk paths so the allowlist is maintained once.

Properties

Methods

activateUser()

Pass-through; the response is only a Result, there is nothing to hydrate.

public activateUser(string $email, string $activationKey) : Result
Parameters
$email : string
$activationKey : string
Return values
Result

cancelDeletion()

public cancelDeletion(string $key) : Result
Parameters
$key : string
Return values
Result

confirmDeletion()

public confirmDeletion(string $key) : Result
Parameters
$key : string
Return values
Result
public confirmExternalLink(string $key) : Result
Parameters
$key : string
Return values
Result

deauthorizeExternal()

public deauthorizeExternal(string $provider, string $externalId) : Result
Parameters
$provider : string
$externalId : string
Return values
Result

emailExists()

See {@see self::usernameExists()}.

public emailExists(string $email[, int|null $excludeId = null ]) : bool|null
Parameters
$email : string
$excludeId : int|null = null
Return values
bool|null

find()

public find(int $pageId[, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : T|null
Parameters
$pageId : int
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
T|null

findAll()

public findAll([array<string|int, mixed>|null $filters = [] ][, array<string|int, mixed>|null $orderBys = null ][, int|null $offset = null ][, int|null $limit = null ][, array<string|int, mixed>|null $columns = null ][, bool $computeTotalCount = false ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : T>, 1: int}
Parameters
$filters : array<string|int, mixed>|null = []
$orderBys : array<string|int, mixed>|null = null
$offset : int|null = null
$limit : int|null = null
$columns : array<string|int, mixed>|null = null
$computeTotalCount : bool = false
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
T>, 1: int}

findBy()

public findBy([array<string|int, mixed>|null $filters = [] ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : T|null
Parameters
$filters : array<string|int, mixed>|null = []
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
T|null

findPublicProfile()

Hydrates the public profile by hand into {@see PublicProfile}.

public findPublicProfile(int $id) : PublicProfile|null

IMPORTANT: $this->hydrator and the User entity are deliberately not used: the hydrator would fill missing keys with User constructor defaults and the result would answer getEmail()/getPhone()/getPassword() with empty values instead of the method not existing at all. The manual mapping to a narrow type is a security measure, not needless work (see the docblock of PublicProfile).

The Api payload is a positive allowlist (UserPresenter::PUBLIC_PROFILE_FIELDS); what is missing from it is filled with a safe default here, so a Result::failure from the guard ends as null, not as a half-empty profile.

Parameters
$id : int
Return values
PublicProfile|null

findPublicProfiles()

Bulk variant of {@see self::findPublicProfile()}.

public findPublicProfiles(array<int, int> $ids) : array<int, PublicProfile>

The result is keyed by userId, so callers (comment, review and discussion templates) get the same shape as from findAll(['id' => InFilter]), but with the narrow PublicProfile instead of the User entity. A profile the Api did not return (nonexistent or refused by the guard) is simply missing from the map; templates handle that already ($users[$userId] ?? null).

Parameters
$ids : array<int, int>
Return values
array<int, PublicProfile>

login()

public login(string $username, string $password[, string|null $deviceToken = null ]) : Result
Parameters
$username : string
$password : string
$deviceToken : string|null = null
Return values
Result

loginExternal()

public loginExternal(string $provider, string $id, string $email, string $firstname, string $lastname[, bool $emailVerified = false ][, string $referralCode = '' ]) : Result
Parameters
$provider : string
$id : string
$email : string
$firstname : string
$lastname : string
$emailVerified : bool = false
$referralCode : string = ''
Return values
Result

referralOverview()

Affiliate program for the "My account" page (`:Api:System:User:referralOverview`).

public referralOverview(int $userId) : Result
Parameters
$userId : int
Return values
Result

requestDeletion()

public requestDeletion(int $userId, string $password) : Result
Parameters
$userId : int
$password : string
Return values
Result

resetPassword()

public resetPassword(string $email, string $key, string $password) : Result
Parameters
$email : string
$key : string
$password : string
Return values
Result

revealPhone()

Raw phone from {@see UserRepository::revealPhone()}.

public revealPhone(int $id) : string

An empty string for a missing or refused call: the front end shows it as "stay with the masked value", not as an error (see front UserPresenter::handleShowPhone()).

Parameters
$id : int
Return values
string

save()

public save(BaseEntity $entity[, array<string, mixed> $meta = [] ][, array<int, string> $skipFields = [] ]) : Result
Parameters
$entity : BaseEntity
$meta : array<string, mixed> = []
$skipFields : array<int, string> = []
Return values
Result

sendActivationEmail()

public sendActivationEmail(string $username) : Result
Parameters
$username : string
Return values
Result

sendNewPassword()

Replaced `generateNewPassword(int $userId)`, see the repository.

public sendNewPassword(string $username) : Result
Parameters
$username : string
Return values
Result

updateColumns()

public updateColumns(array<string|int, mixed> $ids, array<string, mixed> $values) : Result
Parameters
$ids : array<string|int, mixed>

ids or composite-id arrays

$values : array<string, mixed>

property name => new value

Return values
Result

updatePassword()

public updatePassword(int $userId, string $currentPassword, string $password) : Result
Parameters
$userId : int
$currentPassword : string
$password : string
Return values
Result

usernameExists()

Pass-through; the response is a single bool, there is nothing to hydrate.

public usernameExists(string $username[, int|null $excludeId = null ]) : bool|null
Parameters
$username : string
$excludeId : int|null = null
Return values
bool|null —

null = could not be determined, see the repository

getEntityClass()

protected getEntityClass() : T>
Return values
T>

initalizeEntity()

protected initalizeEntity(array<string, mixed> $row) : User|null
Parameters
$row : array<string, mixed>
Return values
User|null

toDate()

`ATOM` string from the Api payload to `DateTimeImmutable`; an unreadable value gives `null`, not an exception.

private static toDate(mixed $value) : DateTimeImmutable|null
Parameters
$value : mixed
Return values
DateTimeImmutable|null

toPublicProfile()

The only place that builds {@see PublicProfile} from the Api payload; shared by the single and bulk paths so the allowlist is maintained once.

private static toPublicProfile(array<string, mixed> $row) : PublicProfile|null
Parameters
$row : array<string, mixed>
Return values
PublicProfile|null
On this page

Search results