private function attach(IRepository $repository) { if ($this->repository !== null && $this->repository !== $repository) { throw new InvalidStateException('Entity is already attached.'); } $this->repository = $repository; }