/** * 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 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") { // Save these for some special use in the recursive walk $this->toUnserialize = $toDeserialize; $this->inherited = $inherited; // This class is almost always re-used, reset stuff $this->updatesToDefer = []; // Recurse the template and data $entityData = $this->walkDeserializedData($template, $toDeserialize, ""); // Create the entity via the repository $createdEntity = $this->repositoryAction($repository, $entityData); $primaryKey = $createdEntity[$primaryKeyField]; // Was an internal id to this entity caught? if (isset($this->idName)) { // Bind the internal id to the real created id $this->idResolver->bind($this->idName, $primaryKey); } // Optimize and defer updates to be performed at a later time $this->deferUpdates($repository, $primaryKey, $createdEntity); // Return the created entity return $createdEntity; }