public function getRepository($need = true) { if ($this->repository === null && $need) { throw new InvalidStateException('Entity is not attached to repository.'); } return $this->repository; }