public function getRepository() { if (!$this->repository) { $name = get_class($this); throw new InvalidStateException("Mapper '{$name}' is not attached to repository."); } return $this->repository; }