add($relation); } } public function getIterator(): ArrayIterator { return new ArrayIterator($this->relations); } public function add(ResourceRelation $relation): self { $this->relations[] = $relation; return $this; } public function filterNewSourceIds(array $currentSourceIds): array { return array_diff($currentSourceIds, $this->getSourceIds()); } public function filterRemovedSourceIds(array $currentSourceIds): array { return array_diff($this->getSourceIds(), $currentSourceIds); } public function jsonSerialize(): array { return $this->relations; } private function getSourceIds(): array { $sourceIds = []; foreach ($this->relations as $relation) { $sourceIds[] = $relation->getSourceId(); } return $sourceIds; } }