/**
  * Deserialize according to the rules set up in the template into the repository
  *
  * @param array $template Seriplater template
  * @param mixed $repository Target repository
  * @param array $toDeserialize Serialized data
  * @param array $inherited Inherited data from a parent entity
  * @param string $primaryKeyField Name of primary key field
  * @return array The created entity
  */
 public function deserialize(array $template, $repository, array $toDeserialize, array $inherited = [], $primaryKeyField = "id")
 {
     foreach ($template as $field => $rule) {
         if ($rule instanceof RuleInterface && $rule->isId() && isset($toDeserialize["_id"]) && isset($toDeserialize[$primaryKeyField])) {
             $this->idResolver->bind($toDeserialize["_id"], $toDeserialize[$primaryKeyField]);
         }
     }
 }
 /**
  * Deserialize from the given (de)serializer id entity name and downwards
  *
  * @param string $entityName The registrered entity's name as provided via the id() rule
  * @param array $serializedTree Serialized data
  * @return Unserialized entity data
  * @throws HierarchicalCompositionException on structure errors or missing fields
  */
 public function deserialize($entityName, array $serializedTree)
 {
     if (!isset($this->templateRegistry[$entityName])) {
         throw new HierarchicalCompositionException("Entity '{$entityName}' wasn't found in the registry");
     }
     // Perform deserialization recursively
     $entityData = $this->deserializeRelations($this->templateRegistry[$entityName], $serializedTree);
     // Resolve deferred updates
     $this->idResolver->resolve();
     return $entityData;
 }
 /**
  * Tell the id resolver to defer our caught updates until they can be resolved
  *
  * @param mixed $repository Target repository
  * @param mixed $primaryKey Primary key of the created entity
  * @param array $createdEntity The created entity
  */
 protected function deferUpdates($repository, $primaryKey, array $createdEntity)
 {
     foreach ($this->updatesToDefer as $updateToDefer) {
         $this->idResolver->defer($updateToDefer["internalId"], $repository, $primaryKey, $updateToDefer["fullDotPath"], $createdEntity, $updateToDefer["fallback"]);
     }
 }