Once populated, ClassMetadata instances are usually cached in a serialized form. IMPORTANT NOTE: The fields of this class are only public for 2 reasons: 1) To allow fast READ access. 2) To drastically reduce the size of a serialized instance (public/protected members get the whole class name, namespace inclusive, prepended to every property in the serialized representation).
Since: 1.0
Author: Mike Lohmann (mike.h.lohmann@googlemail.com)
Inheritance: implements Doctrine\Common\Persistence\Mapping\ClassMetadata
Example #1
0
 /**
  * @expectedException \Doctrine\Search\Exception\Driver\PropertyDoesNotExistsInMetadataException
  */
 public function testLoadMetadataForClassAddValuesToMetadata()
 {
     $this->reflectionClass->expects($this->once())->method('getProperties')->will($this->returnValue(array()));
     $this->reader->expects($this->once())->method('getClassAnnotations')->will($this->returnValue(array(0, new TestSearchable(array()))));
     $this->classMetadata->expects($this->once())->method('getReflectionClass')->will($this->returnValue($this->reflectionClass));
     $this->annotationDriver->loadMetadataForClass('Doctrine\\Tests\\Models\\Blog\\BlogPost', $this->classMetadata);
 }
 public function transfuse(SearchMetadata $searchMeta)
 {
     $class = $this->entityManager->getClassMetadata($searchMeta->getName());
     $repository = $this->entityManager->getRepository($searchMeta->getName());
     $this->createAndUpdate($class, $repository);
     $this->dropOld($class, $repository);
 }
Example #3
0
 /**
  * Construct an entity object
  *
  * @param ClassMetadata $class
  * @param object $document
  */
 public function hydrateEntity(ClassMetadata $class, $document)
 {
     // TODO: add support for different result set types from different clients
     // perhaps by wrapping documents in a layer of abstraction
     $data = $document->getData();
     $fields = array_merge($document->hasFields() ? $document->getFields() : array(), array('_version' => $document->getVersion()));
     foreach ($fields as $name => $value) {
         if (isset($class->parameters[$name])) {
             $data[$name] = $value;
         } else {
             foreach ($class->parameters as $param => $mapping) {
                 if ($mapping->name == $name) {
                     $data[$param] = $value;
                     break;
                 }
             }
         }
     }
     $data[$class->getIdentifier()] = $document->getId();
     if (method_exists($document, 'getScore')) {
         $data['score'] = $document->getScore();
     }
     $entity = $this->sm->getSerializer()->deserialize($class->className, json_encode($data));
     if ($this->evm->hasListeners(Events::postLoad)) {
         $this->evm->dispatchEvent(Events::postLoad, new Event\LifecycleEventArgs($entity, $this->sm));
     }
     return $entity;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function updateMapping(ClassMetadata $classMetadata)
 {
     try {
         $elasticaIndex = new Index($this->client, $classMetadata->getIndexForRead());
         $elasticaType = new Type($elasticaIndex, $classMetadata->type);
         $elasticaTypeMapping = new Mapping($elasticaType, $this->getMapping($classMetadata->fieldMappings));
         $elasticaTypeMapping->setParam('_id', array('path' => $classMetadata->getIdentifier()));
         if ($classMetadata->parent) {
             $elasticaTypeMapping->setParam('_parent', array('type' => $classMetadata->parent));
         }
         if ($classMetadata->dynamic) {
             $elasticaTypeMapping->setParam('dynamic', $classMetadata->dynamic);
         }
         $response = $elasticaType->setMapping($elasticaTypeMapping);
     } catch (\Exception $e) {
         return $e->getMessage();
     }
     return 200 == $response->getStatus() ? true : $response->getError();
 }
Example #5
0
 public function testGetAssociationMappedByTargetField()
 {
     $this->assertInternalType('string', $this->classMetadata->getAssociationMappedByTargetField('name'));
 }
Example #6
0
 protected function loadExpectedMetadataFor($className, $type)
 {
     $expected = new ClassMetadata($className);
     $expected->type = $type;
     $expected->identifier = 'id';
     $expected->index = 'searchdemo';
     $expected->numberOfShards = 2;
     $expected->numberOfReplicas = 1;
     $expected->timeToLive = 180;
     $expected->boost = 2.0;
     $expected->source = true;
     $expected->mapRoot(array('fieldName' => 'dynamic_templates', 'id' => 'template_2', 'match' => 'description*', 'mapping' => array('type' => 'multi_field', 'fields' => array(array('fieldName' => '{name}', 'type' => 'string', 'includeInAll' => false), array('fieldName' => 'untouched', 'type' => 'string', 'index' => 'not_analyzed')))));
     $expected->mapRoot(array('fieldName' => 'date_detection', 'value' => 'false'));
     $expected->mapField(array('fieldName' => 'name', 'type' => 'string', 'includeInAll' => false, 'index' => 'no', 'boost' => 2.0));
     $expected->mapField(array('fieldName' => 'username', 'type' => 'multi_field', 'fields' => array(array('fieldName' => 'username', 'type' => 'string', 'includeInAll' => true, 'analyzer' => 'whitespace'), array('fieldName' => 'username.term', 'type' => 'string', 'includeInAll' => false, 'index' => 'not_analyzed'))));
     $expected->mapField(array('fieldName' => 'ip', 'type' => 'ip', 'includeInAll' => false, 'index' => 'no', 'store' => true, 'nullValue' => '127.0.0.1'));
     $expected->mapField(array('fieldName' => 'emails', 'type' => 'nested', 'properties' => array(array('fieldName' => 'email', 'type' => 'string', 'includeInAll' => false, 'index' => 'not_analyzed'), array('fieldName' => 'createdAt', 'type' => 'date'))));
     $expected->mapField(array('fieldName' => 'friends', 'type' => 'string', 'includeInAll' => false, 'index' => 'not_analyzed'));
     $expected->mapField(array('fieldName' => 'active', 'type' => 'boolean', 'nullValue' => false));
     $expected->mapParameter(array('parameterName' => '_routing', 'type' => 'string'));
     return $expected;
 }