/** * This function tries, given an array of data, to convert it to an object if the given array contains * an identifier for the object. This is useful in a context of updating existing entities, without ugly * tricks like setting manually the existing id directly into the entity * * @param array $data * @param object $object * @return object */ protected function tryConvertArrayToObject($data, $object) { $identifierNames = $this->metadata->getIdentifierFieldNames($object); $identifierValues = array(); if (empty($identifierNames)) { return $object; } foreach ($identifierNames as $identifierName) { if (!isset($data[$identifierName]) || empty($data[$identifierName])) { return $object; } $identifierValues[$identifierName] = $data[$identifierName]; } return $this->find(get_class($object), $identifierValues); }