DownloadADR-004: ???????????? ????????? ??????? ??????????????? ???????
| ???? | ???????? |
|-----------------|------------------------------------------------------------------------------|
| ?????? | Proposed |
| ???? | 2026-05-05 |
| ????? | Ruslan Kabirov |
| ?????????? ????? | Persistence/UnitOfWork.php, Event/EntityEvent.php, AdaptiveEntityManager.php |
????????
AEM ?????????????? lifecycle-??????? ??? commit-?: PrePersistEvent, PostPersistEvent, PreUpdateEvent, PostUpdateEvent, PreRemoveEvent, PostRemoveEvent. ? ??????? ?????????? ?????????????? ???? CommitEventDispatchOrderTest, ??????? ????????? ?????????? ??????? ???????. ??? ????????, ??? ??????? ????? ??? ???????????? ??????.
?????? ????? ? ????????? ?????????? ???? ??????? ?? ????????????:
-
UnitOfWork ?? ????????????? ??????? ? ? ???? ??????? ???????????? ??????????? ?????? `commit()`, ?? ??? ???????????? ????????, ??? ?? ????????? ????? ?? ? ??????? ???????.
-
???????????? ????? ????????
UnitOfWork ? ????????? `UnitOfWorkInterface` ????????? ???????????? ??????????? ??????????. ?? ????? ?? ???????, ??? ?????? ?????? ????????? ???????????? ??????? ???????.
-
??????? ????? ?????? ???????? ?????????? ? ???? ? ????? commit-? ???? ? inserts, ? updates, ? deletes, ? ????? ??????? ??? ???????????? ??????? ??? inserts, ????? ??? updates, ????? ??? deletes? ??? ???????????? ?? ??????????
??????? ??????? (?? ???? UnitOfWork)
1. ??? PrePersistEvent (??? ?????? ??????????? ????????)
2. ??? insert() (????? ???????? ??? ?????? ????????)
3. ??? PostPersistEvent (??? ?????? ??????????? ????????)
4. ??? PreUpdateEvent (??? ?????? ??????????? ????????)
5. ??? update() (????? ???????? ??? ?????? ????????)
6. ??? PostUpdateEvent (??? ?????? ??????????? ????????)
7. ??? PreRemoveEvent (??? ?????? ????????? ????????)
8. ??? delete() (????? ???????? ??? ?????? ????????)
9. ??? PostRemoveEvent (??? ?????? ????????? ????????)
??? "batch-??-????-????????" ? ??????? ??? ???????, ????? ??? ??????????, ????? ??? ????????. ?????????????? ?????? ? "??-????????": ??? ?????? ???????? ??????????? ?????? ???? pre??????????post ????? ????????? ? ?????????.
???????
????????????? ??????? ??????????????? ??????? ??? ????? ????????? UnitOfWorkInterface.
1. ??????????????? ???????? ? ??????????
interface UnitOfWorkInterface
{
/
* Commits all pending changes in the following order:
*
* 1. Pre-persist events for all new entities
* 2. Insert operations for all new entities
* 3. Post-persist events for all new entities
* 4. Pre-update events for all modified entities
* 5. Update operations for all modified entities
* 6. Post-update events for all modified entities
* 7. Pre-remove events for all removed entities
* 8. Delete operations for all removed entities
* 9. Post-remove events for all removed entities
*
* This ordering guarantees that:
* - Pre-events always precede their corresponding operation
* - Post-events always follow their corresponding operation
* - All inserts are completed before any updates begin
* - All updates are completed before any deletes begin
* - Listeners can rely on this order for cross-entity invariants
*
* @throws CommitFailedException If any operation fails
*/
public function commit(): void;
}
2. ???????? CommitOrder enum ??? ?????????????
enum CommitOrder: string
{
/
* Batch by operation type: all inserts, then all updates, then all deletes.
* Best for SQL adapters where batch operations are possible.
*/
case BATCH_BY_OPERATION = 'batch_by_operation';
/
* Per-entity: for each entity, execute full lifecycle (pre ? operation ? post).
* Best for REST/GraphQL adapters where each operation is independent.
*/
case PER_ENTITY = 'per_entity';
}
3. Configurable commit order
class AdaptiveEntityManager
{
public function __construct(
ConfigInterface $config,
// ... existing params
CommitOrder $commitOrder = CommitOrder::BATCH_BY_OPERATION,
) {
$this->unitOfWork = new UnitOfWork(
$this,
commitOrder: $commitOrder,
);
}
}
4. ???????? ??? event listeners
???????? ???????????? ? ????????:
class PrePersistEvent extends EntityEvent
{
/
* Dispatched before the entity is inserted into the data source.
*
* Guarantees at the time of dispatch:
* - No entities have been updated or deleted yet in this commit cycle
* - The entity's identifier may not be assigned yet
* - Modifications to the entity will be included in the insert operation
* - Stopping propagation prevents the insert and all subsequent operations
*/
}
???????????
?????????????
-
????? ???????? ? ???????????? ?????????? ????? ?????????? ?? ??????? ???????, ?? ????? ???????? ??? `UnitOfWork`.
-
????????????? ????????????????? ???? ? ???? ??????? ????????????, ???????????? ????? ?????? ?????, ????????? ?? ???????, ??? ?????, ??? ???????? ?????????? ?? ???????.
-
????????????? ? `CommitOrder` enum ????????? ???????? ????? ????????? (????????, `TOPOLOGICAL_SORT` ??? ????????? ? ?????????????) ??? ????????? ??????????.
-
????????????? ? Doctrine ? Doctrine ORM ?????????? ??????????? batch-??-???? ???????, ??? ???????? ????????.
?????????????
-
??????????? ???????? ? ???????????? ???????, ?? ?????? ??????????? ???????? ??? ??? semver-major bump. ???? ???????????, ??? ?????????????? ??????? ???????????, ???????? ????? 2.0.
-
Complexity ? ?????????? `CommitOrder` enum ? ???????????????? ? ??? ?????????????? ????????? ??? ??????? use cases.
-
PER_ENTITY ??????? ??????? ???????????? ?????? ? ?????????? ????? ???????? ? `UnitOfWork` ??????????? ????? ????.
???? ??????????
???? 1: ???????????? (patch release)
-
???????? docblock ? ???????? commit ? `UnitOfWorkInterface::commit()`.
-
???????? ???????? ? ??????? event-??????.
-
???????? `ARCHITECTURE_DIAGRAMS.md` ??? `INTERACTION_DIAGRAMS.md` ? ?????????? ??????? ???????.
-
??????? ????????? ? ???? ? ?????? ????????????.
???? 2: CommitOrder enum (minor release)
-
??????? `CommitOrder` enum.
-
???????? ???????? ? ??????????? `AdaptiveEntityManager`.
-
??????????? `PER_ENTITY` ??????? ? `UnitOfWork` (?? feature flag).
-
?????? ? `BATCH_BY_OPERATION` (??????? ?????????).
-
???????? ????? ??? ????? ????????.
???? 3: ????????? ????????? (minor release)
-
???????? `CommitOrderValidator`, ??????? ? dev-?????? ?????????, ??? ??????? ????????????? ???????????????? ? ?????????? ??????? (????? assertion layer).
-
???????? ? CI ????????? ????-??? ? assertion-??? ???????.
????????????
???????????? 1: ?????? ????????????, ??? CommitOrder
????????????? ??????? ? docblock, ?? ?? ????????? ?????????????? ?????????.
????: ??????? ????????? ? ????.
?????: REST/GraphQL ???????? ????? ???????????? PER_ENTITY ??????? (???? HTTP-?????? = ?????? lifecycle ????? ????????). ??? CommitOrder ??? ?? ????? ????? ????????.
???????????? 2: Transactional event listeners (Doctrine approach)
????????? ??????? ?? "?????? ??????????" ? "????? ???????", ??? Doctrine ORM (onFlush vs postFlush).
????: ????? ?????????? between "????? ????????" ? "??? ???????????".
?????: ??????????? ????????? API. AEM ??????????????? ??? ??????? ?????????? ? ?????????? ???? ??? ??????? ????? ???? over-engineering ?? ?????? ?????.
|