getIdentifier() public méthode

The returned structure is an array of the identifier field names.
public getIdentifier ( ) : array
Résultat array
Exemple #1
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;
 }
 public function testGetIdentifier()
 {
     $this->assertNull($this->classMetadata->getIdentifier());
 }
Exemple #3
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();
 }
 public function testGetIdentifier()
 {
     $this->assertEquals(array(), $this->classMetadata->getIdentifier());
 }