CategoryPriceMapper
extends Mapper
in package
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 : CategoryPriceRepository
Methods
- __construct() : mixed
- beginTransaction() : void
- commit() : void
- delete() : Result
- 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
- isInTransaction() : bool
- rollback() : void
- save() : Result
- setupEntityManager() : void
- updateAllRelations() : Result
- Updates all relations of parent entity with given scalar values.
- updateColumns() : Result
- Updates columns of the given rows and fully replaces to-many relations, all in one transaction.
- updateRelations() : Result
- Updates existing relation entities in a join/relation table.
- 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
CategoryPriceRepository
$repository
Methods
__construct()
public
__construct(CategoryPriceRepository $repository) : mixed
Parameters
- $repository : CategoryPriceRepository
beginTransaction()
public
beginTransaction() : void
commit()
public
commit() : void
delete()
public
delete(BaseEntity $entity) : Result
Parameters
- $entity : BaseEntity
Return values
Resultfind()
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
intisInTransaction()
public
isInTransaction() : bool
Return values
boolrollback()
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
updateAllRelations()
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
ResultupdateColumns()
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
ResultupdateRelations()
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
ResultresolveRelations()
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