3 namespace BookStack\References;
5 use BookStack\Entities\Models\Entity;
7 class ReferenceChangeContext
10 * Entity pairs where the first is the old entity and the second is the new entity.
11 * @var array<array{0: Entity, 1: Entity}>
13 protected array $changes = [];
15 public function add(Entity $oldEntity, Entity $newEntity): void
17 $this->changes[] = [$oldEntity, $newEntity];
21 * Get all the new entities from the changes.
23 public function getNewEntities(): array
25 return array_column($this->changes, 1);
29 * Get all the old entities from the changes.
31 public function getOldEntities(): array
33 return array_column($this->changes, 0);
36 public function getNewForOld(Entity $oldEntity): ?Entity
38 foreach ($this->changes as [$old, $new]) {
39 if ($old->id === $oldEntity->id && $old->type === $oldEntity->type) {