ApiClientMapper
extends Mapper
in package
uses
SaveTrait
Base Api mapper over a Doctrine repository.
Every concrete mapper declares protected readonly XRepository $repository (a concrete
subclass of OrmRepository); the base cannot declare it because PHP property types are
invariant and a child could not narrow the type.
The repository returns the generic BaseEntity; narrowing to the service entity is done by the service.
Table of Contents
Properties
- $em : EntityManagerInterface
- $repository : ApiClientRepository
Methods
- __construct() : mixed
- beginTransaction() : void
- commit() : void
- countValidKeys() : int
- delete() : Result
- deleteKey() : int
-
fetchByKeyHash()
: array{id: int, name: string, enabled: bool, revoked: bool, roleCodes: list
, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null, lastUsedAt: int|null, keyId: int, keyExpiresAt: int|null, keyRevoked: bool, keyLastUsedAt: int|null}|null - fetchKeyHashes() : array<int, string>
- fetchKeys() : array<int, array<int, array{id: int, keyPrefix: string, label: string|null, createdAt: string|null, expiresAt: string|null, revokedAt: string|null, lastUsedAt: string|null}>>
- fetchRoleIds() : array<int, array<int, int>>
- fetchRoleOptions() : array<int, array{id: int, code: string, name: string, implicit: string, conditional: bool, privileged: bool}>
- fetchRows() : array<int, array{id: int, name: string, enabled: bool, revoked: bool, createdAt: string|null, updatedAt: string|null, revokedAt: string|null, lastUsedAt: string|null, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null}>
- find() : BaseEntity|null
- findAll() : array<string|int, mixed>
- findBy() : BaseEntity|null
- findRelatedIds() : array<int, int>|null
- Returns ids of target entities linked to the parent through the relation collection `$property`.
- getTransactionLevel() : int
- insertClient() : int
- insertKey() : int
- isInTransaction() : bool
- replaceRoles() : void
- revokeKey() : int
- rollback() : void
- save() : Result
- setupEntityManager() : void
- touchLastUsed() : int
- updateAllRelations() : Result
- Updates all relations of parent entity with given scalar values.
- updateClient() : int
- updateColumns() : Result
- Updates columns of the given rows and fully replaces to-many relations, all in one transaction.
- updateEnabled() : int
- updateKey() : int
- updateRelations() : Result
- Updates existing relation entities in a join/relation table.
- updateRevoked() : int
- resolveRelations() : void
- bridgeScalarFkToAssociation() : void
- Fills a ManyToOne association from the value of the scalar foreign key that shares the same join column (typically `$menuId` and `menu`, `$pageId` and `page`). Does nothing when the association is not mapped in this entity variant or the scalar is missing or empty (null/0).
- doUpdateRelations() : Result
- insertRelations() : Result
- Inserts relation entities into a join/relation table.
- linkOwnedCollections() : void
- Links the owning side of owned collections (cascade persist OneToMany, for example translations): sets the back-reference to the parent (`mappedBy`) on every child so that Doctrine writes the FK on flush. Without it newly hydrated children would be saved with a null foreign key (or the insert would fail).
- resolveFkIdentifierField() : string|null
- Finds the name of the identifier field of the target entity whose database column equals the join column of the back association (`mappedBy`), that is an identifier which is also a foreign key to the parent. Returns null when there is none.
- rollBackOwnedLevel() : Throwable|null
- Rolls back the transaction levels opened by this mapper (level above the entry level), never foreign ones.
- updateColumnsUnguarded() : Result
Properties
$em
protected
EntityManagerInterface
$em
$repository read-only
protected
ApiClientRepository
$repository
Methods
__construct()
public
__construct(ApiClientRepository $repository) : mixed
Parameters
- $repository : ApiClientRepository
beginTransaction()
public
beginTransaction() : void
commit()
public
commit() : void
countValidKeys()
public
countValidKeys(int $clientId, DateTimeInterface $now) : int
Parameters
- $clientId : int
- $now : DateTimeInterface
Return values
intdelete()
public
delete(BaseEntity $entity) : Result
Parameters
- $entity : BaseEntity
Return values
ResultdeleteKey()
public
deleteKey(int $clientId, int $keyId, DateTimeInterface $now) : int
Parameters
- $clientId : int
- $keyId : int
- $now : DateTimeInterface
Return values
intfetchByKeyHash()
public
fetchByKeyHash(string $keyHash) : array{id: int, name: string, enabled: bool, revoked: bool, roleCodes: list, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null, lastUsedAt: int|null, keyId: int, keyExpiresAt: int|null, keyRevoked: bool, keyLastUsedAt: int|null}|null
Parameters
- $keyHash : string
Return values
array{id: int, name: string, enabled: bool, revoked: bool, roleCodes: listfetchKeyHashes()
public
fetchKeyHashes(int $clientId) : array<int, string>
Parameters
- $clientId : int
Return values
array<int, string>fetchKeys()
public
fetchKeys(array<int, int> $clientIds) : array<int, array<int, array{id: int, keyPrefix: string, label: string|null, createdAt: string|null, expiresAt: string|null, revokedAt: string|null, lastUsedAt: string|null}>>
Parameters
- $clientIds : array<int, int>
Return values
array<int, array<int, array{id: int, keyPrefix: string, label: string|null, createdAt: string|null, expiresAt: string|null, revokedAt: string|null, lastUsedAt: string|null}>>fetchRoleIds()
public
fetchRoleIds(array<int, int> $clientIds) : array<int, array<int, int>>
Parameters
- $clientIds : array<int, int>
Return values
array<int, array<int, int>>fetchRoleOptions()
public
fetchRoleOptions() : array<int, array{id: int, code: string, name: string, implicit: string, conditional: bool, privileged: bool}>
Return values
array<int, array{id: int, code: string, name: string, implicit: string, conditional: bool, privileged: bool}>fetchRows()
public
fetchRows([int|null $clientId = null ]) : array<int, array{id: int, name: string, enabled: bool, revoked: bool, createdAt: string|null, updatedAt: string|null, revokedAt: string|null, lastUsedAt: string|null, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null}>
Parameters
- $clientId : int|null = null
Return values
array<int, array{id: int, name: string, enabled: bool, revoked: bool, createdAt: string|null, updatedAt: string|null, revokedAt: string|null, lastUsedAt: string|null, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null}>find()
public
find(int $id[, string|array<string|int, mixed> $includes = [] ]) : BaseEntity|null
Parameters
- $id : int
- $includes : string|array<string|int, mixed> = []
Return values
BaseEntity|nullfindAll()
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>|null $includes = [] ]) : array<string|int, mixed>
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>|null = []
Return values
array<string|int, mixed>findBy()
public
findBy([array<string|int, mixed>|null $filters = [] ][, string|array<string|int, mixed> $includes = [] ]) : BaseEntity|null
Parameters
- $filters : array<string|int, mixed>|null = []
- $includes : string|array<string|int, mixed> = []
Return values
BaseEntity|nullfindRelatedIds()
Returns ids of target entities linked to the parent through the relation collection `$property`.
public
findRelatedIds(int $parentId, string $property, string $targetAssociation) : array<int, int>|null
For example ('assetRels', 'asset') returns the asset ids of a record gallery. Table and
columns come from Doctrine metadata (same as self::updateAllRelations()).
Parameters
- $parentId : int
- $property : string
- $targetAssociation : string
Return values
array<int, int>|null —null when metadata or the database failed
getTransactionLevel()
public
getTransactionLevel() : int
Return values
intinsertClient()
public
insertClient(array{name: string, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null} $values, DateTimeInterface $now) : int
Parameters
- $values : array{name: string, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null}
- $now : DateTimeInterface
Return values
intinsertKey()
public
insertKey(int $clientId, string $keyHash, string $keyPrefix, string|null $label, DateTimeInterface|null $expiresAt, DateTimeInterface $now, int $maxValidKeys) : int
Parameters
- $clientId : int
- $keyHash : string
- $keyPrefix : string
- $label : string|null
- $expiresAt : DateTimeInterface|null
- $now : DateTimeInterface
- $maxValidKeys : int
Return values
intisInTransaction()
public
isInTransaction() : bool
Return values
boolreplaceRoles()
public
replaceRoles(int $clientId, array<int, int> $roleIds) : void
Parameters
- $clientId : int
- $roleIds : array<int, int>
revokeKey()
public
revokeKey(int $clientId, int $keyId, DateTimeInterface $now) : int
Parameters
- $clientId : int
- $keyId : int
- $now : DateTimeInterface
Return values
introllback()
public
rollback() : void
save()
public
save(TEntity $entity[, array<int, string> $skipFields = [] ]) : Result
Parameters
- $entity : TEntity
- $skipFields : array<int, string> = []
Return values
ResultsetupEntityManager()
public
setupEntityManager(EntityManagerInterface $entityManager) : void
Parameters
- $entityManager : EntityManagerInterface
touchLastUsed()
public
touchLastUsed(int $clientId, int $keyId, DateTimeInterface $now, int $intervalSeconds) : int
Parameters
- $clientId : int
- $keyId : int
- $now : DateTimeInterface
- $intervalSeconds : int
Return values
intupdateAllRelations()
Updates all relations of parent entity with given scalar values.
public
updateAllRelations(array<string|int, mixed> $parentEntityIds, string $property, array<string, mixed> $values) : Result
Sets values on every row matching the parent FK.
Parameters
- $parentEntityIds : array<string|int, mixed>
-
Parent entity IDs (scalar or composite-id arrays)
- $property : string
- $values : array<string, mixed>
-
relation property name => value
Return values
ResultupdateClient()
public
updateClient(int $clientId, array{name: string, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null} $values, DateTimeInterface $now) : int
Parameters
- $clientId : int
- $values : array{name: string, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null}
- $now : DateTimeInterface
Return values
intupdateColumns()
Updates columns of the given rows and fully replaces to-many relations, all in one transaction.
public
updateColumns(array<string|int, mixed> $entityIds, array<string, mixed> $values) : Result
A collection (one-to-many) is written as a full replace: delete of all parent rows plus
per-row inserts. A failure halfway would leave the parent with part of its history or none
(price snapshots of product sets), so a failed Result or an exception rolls everything
back. A nested call inside a foreign transaction is handled by DBAL with a savepoint.
IMPORTANT: the mapper owns only the transaction level it opened itself. DBAL lowers the
level in finally even after a failed commit or savepoint release, so a blind rollback in
catch would throw NoActiveTransaction and hide the original error, or inside a foreign
transaction it would roll back the caller's level. Rollback therefore runs only while the
level is above the entry level; its own failure is logged and never replaces the primary
error or Result (a failed Result with a failed rollback becomes DB_ERROR). An
ambiguous commit is not retried.
Parameters
- $entityIds : array<string|int, mixed>
-
ids or composite-id arrays (
[prop => value]) - $values : array<string, mixed>
-
property name => new value
Return values
ResultupdateEnabled()
public
updateEnabled(int $clientId, bool $enabled, DateTimeInterface $now) : int
Parameters
- $clientId : int
- $enabled : bool
- $now : DateTimeInterface
Return values
intupdateKey()
public
updateKey(int $clientId, int $keyId, string|null $label, DateTimeInterface|null $expiresAt) : int
Parameters
- $clientId : int
- $keyId : int
- $label : string|null
- $expiresAt : DateTimeInterface|null
Return values
intupdateRelations()
Updates existing relation entities in a join/relation table.
public
updateRelations(array<string|int, mixed> $parentEntityIds, string $property, array<string|int, object> $relationEntities) : Result
Parameters
- $parentEntityIds : array<string|int, mixed>
-
Parent entity IDs (scalar or composite-id arrays)
- $property : string
-
Association property name on parent entity
- $relationEntities : array<string|int, object>
-
Relation entities with updated values
Return values
ResultupdateRevoked()
public
updateRevoked(int $clientId, DateTimeInterface $now) : int
Parameters
- $clientId : int
- $now : DateTimeInterface
Return values
intresolveRelations()
protected
resolveRelations(object $entity) : void
Parameters
- $entity : object
bridgeScalarFkToAssociation()
Fills a ManyToOne association from the value of the scalar foreign key that shares the same join column (typically `$menuId` and `menu`, `$pageId` and `page`). Does nothing when the association is not mapped in this entity variant or the scalar is missing or empty (null/0).
private
bridgeScalarFkToAssociation(object $entity, string $associationName) : void
Parameters
- $entity : object
- $associationName : string
doUpdateRelations()
private
doUpdateRelations(array<string|int, mixed> $parentEntityIds, AssociationMapping $mapping, array<string|int, object> $relationEntities) : Result
Parameters
- $parentEntityIds : array<string|int, mixed>
-
Parent entity IDs (scalar or composite-id arrays)
- $mapping : AssociationMapping
-
OneToMany/ManyToMany association mapping
- $relationEntities : array<string|int, object>
-
Relation entities with updated values
Return values
ResultinsertRelations()
Inserts relation entities into a join/relation table.
private
insertRelations(array<string|int, mixed> $parentEntityIds, AssociationMapping $mapping, array<int, object> $relationEntities) : Result
Parameters
- $parentEntityIds : array<string|int, mixed>
-
Parent entity IDs (scalar or composite-id arrays)
- $mapping : AssociationMapping
-
OneToMany/ManyToMany association mapping
- $relationEntities : array<int, object>
-
relation entities (validated in
updateColumnsUnguarded())
Return values
ResultlinkOwnedCollections()
Links the owning side of owned collections (cascade persist OneToMany, for example translations): sets the back-reference to the parent (`mappedBy`) on every child so that Doctrine writes the FK on flush. Without it newly hydrated children would be saved with a null foreign key (or the insert would fail).
private
linkOwnedCollections(object $entity) : void
For children whose identifier is itself a foreign key to the parent (typically
translations: PK = page_id + language_id, where page_id is also the FK), the scalar
identifier is filled from the parent id. Doctrine does not derive it from the association
(it is not a derived identity through #[Id] on the association), so it would fail with
EntityMissingAssignedId. Works for an existing parent (the id is known); a brand-new
parent (the id appears only on flush) needs a two-phase write.
Parameters
- $entity : object
resolveFkIdentifierField()
Finds the name of the identifier field of the target entity whose database column equals the join column of the back association (`mappedBy`), that is an identifier which is also a foreign key to the parent. Returns null when there is none.
private
resolveFkIdentifierField(class-string $targetEntity, string $mappedBy) : string|null
Parameters
- $targetEntity : class-string
- $mappedBy : string
Return values
string|nullrollBackOwnedLevel()
Rolls back the transaction levels opened by this mapper (level above the entry level), never foreign ones.
private
rollBackOwnedLevel(Connection $connection, int $entryLevel, Throwable|null $primary) : Throwable|null
Returns the rollback exception (logged together with $primary), or null on success.
Parameters
- $connection : Connection
- $entryLevel : int
- $primary : Throwable|null
Return values
Throwable|nullupdateColumnsUnguarded()
private
updateColumnsUnguarded(array<string|int, mixed> $entityIds, array<string, mixed> $values) : Result
Parameters
- $entityIds : array<string|int, mixed>
-
ids or composite-id arrays (
[prop => value]) - $values : array<string, mixed>
-
property name => new value