/**
  * @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;
 }
 /**
  * @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;
 }
Exemplo n.º 3
0
 public function testAddEntity_FilteredEntityWithUnknownCallback()
 {
     $this->eventManager->expects($this->never())->method('handle');
     $information = new MetaInformation();
     $information->setSynchronizationCallback('shouldBeIndex');
     $this->setupMetaFactoryLoadOneCompleteInformation($information);
     $solr = new SolrFacade($this->connectionFactory, $this->commandFactory, $this->eventManager, $this->metaFactory);
     try {
         $solr->addDocument(new InvalidTestEntityFiltered());
         $this->fail('BadMethodCallException expected');
     } catch (\BadMethodCallException $e) {
         $this->assertTrue(true);
     }
 }
Exemplo n.º 4
0
 public function testHasCallback_CallbackSet()
 {
     $information = new MetaInformation();
     $information->setSynchronizationCallback('function');
     $this->assertTrue($information->hasSynchronizationFilter(), 'has callback');
 }
Exemplo n.º 5
0
 public function testAddEntity_ShouldNotIndexEntity()
 {
     $this->assertUpdateQueryWasNotExecuted();
     $this->eventDispatcher->expects($this->never())->method('dispatch');
     $entity = new ValidTestEntityFiltered();
     $information = new MetaInformation();
     $information->setSynchronizationCallback('shouldBeIndex');
     $this->setupMetaFactoryLoadOneCompleteInformation($information);
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $solr->addDocument($entity);
     $this->assertTrue($entity->getShouldBeIndexedWasCalled(), 'filter method was not called');
 }