/**
  * Build the config for the id key
  *
  * @return NodeDefinition
  */
 protected function addIdNode()
 {
     $builder = new TreeBuilder();
     $node = $builder->root('id');
     $node->useAttributeAsKey('name')->requiresAtLeastOneElement()->prototype('array')->children()->scalarNode('type')->isRequired()->cannotBeEmpty()->end()->arrayNode('generator')->children()->enumNode('strategy')->values(Generators::getStrategies())->defaultValue('UUID')->end()->end()->end()->end()->end();
     return $node;
 }
Beispiel #2
0
 /**
  * Generate an id for the given entity
  *
  * @param object $entity
  *
  * @return mixed
  */
 protected function generateId($entity)
 {
     $class = $this->getClass($entity);
     $metadata = $this->metadataRegistry->getMetadata($class);
     $id = Generators::getGenerator($metadata->getId()->getStrategy())->generate($this, $entity);
     $idProp = $metadata->getId()->getProperty();
     $refl = new \ReflectionObject($entity);
     $refl = $refl->getProperty($idProp);
     $refl->setAccessible(true);
     $refl->setValue($entity, $id);
     $refl->setAccessible(false);
     return $id;
 }