Exemplo n.º 1
0
 /**
  * Loads an entity or creates a new one if it does not already exist.
  *
  * @param  Metadata $metadata
  * @param  array    $data
  * @return object
  */
 public function load(Metadata $metadata, array $data)
 {
     $id = $data[$metadata->getIdentifier()];
     $class = $metadata->getClass();
     if (isset($this->entities[$class][$id])) {
         $entity = $this->entities[$class][$id];
     } else {
         $entity = $metadata->newInstance();
         $metadata->setValues($entity, $data, true, true);
         $this->identifiers[spl_object_hash($entity)] = $id;
         $this->entities[$class][$id] = $entity;
     }
     $this->manager->dispatchEvent(Events::postLoad, $entity, $metadata);
     return $entity;
 }