/** * @param object $entity * * @return MetaInformation * * @throws \RuntimeException if no declaration for document found in $entity */ public function loadInformation($entity) { $className = $this->getClass($entity); if (!is_object($entity)) { $reflectionClass = new \ReflectionClass($className); if (!$reflectionClass->isInstantiable()) { throw new \RuntimeException(sprintf('cannot instantiate entity %s', $className)); } $entity = $reflectionClass->newInstanceWithoutConstructor(); } if (!$this->annotationReader->hasDocumentDeclaration($entity)) { throw new \RuntimeException(sprintf('no declaration for document found in entity %s', $className)); } $metaInformation = new MetaInformation(); $metaInformation->setEntity($entity); $metaInformation->setClassName($className); $metaInformation->setDocumentName($this->getDocumentName($className)); $metaInformation->setFieldMapping($this->annotationReader->getFieldMapping($entity)); $metaInformation->setFields($this->annotationReader->getFields($entity)); $metaInformation->setRepository($this->annotationReader->getRepository($entity)); $metaInformation->setIdentifier($this->annotationReader->getIdentifier($entity)); $metaInformation->setBoost($this->annotationReader->getEntityBoost($entity)); $metaInformation->setSynchronizationCallback($this->annotationReader->getSynchronizationCallback($entity)); $metaInformation->setIndex($this->annotationReader->getDocumentIndex($entity)); $metaInformation->setIsDoctrineEntity($this->annotationReader->isDoctrineEntity($entity)); return $metaInformation; }
/** * @expectedException RuntimeException */ public function testGetRepository_UserdefinedInvalidRepository() { $metaInformation = new MetaInformation(); $metaInformation->setClassName(get_class(new EntityWithRepository())); $metaInformation->setRepository('FS\\SolrBundle\\Tests\\Doctrine\\Annotation\\Entities\\InvalidEntityRepository'); $this->setupMetaFactoryLoadOneCompleteInformation($metaInformation); $solr = new SolrFacade($this->connectionFactory, $this->commandFactory, $this->eventManager, $this->metaFactory); $solr->getRepository('Tests:EntityWithInvalidRepository'); }
/** * @param string|object entityAlias * @return MetaInformation */ public function loadInformation($entity) { $className = $this->getClass($entity); if (!is_object($entity)) { $entity = new $className(); } if (!$this->annotationReader->hasDocumentDeclaration($entity)) { throw new \RuntimeException(sprintf('no declaration for document found in entity %s', $className)); } $metaInformation = new MetaInformation(); $metaInformation->setEntity($entity); $metaInformation->setClassName($className); $metaInformation->setDocumentName($this->getDocumentName($className)); $metaInformation->setFieldMapping($this->annotationReader->getFieldMapping($entity)); $metaInformation->setFields($this->annotationReader->getFields($entity)); $metaInformation->setRepository($this->annotationReader->getRepository($entity)); $metaInformation->setIdentifier($this->annotationReader->getIdentifier($entity)); $metaInformation->setBoost($this->annotationReader->getEntityBoost($entity)); $metaInformation->setSynchronizationCallback($this->annotationReader->getSynchronizationCallback($entity)); return $metaInformation; }