/**
* {@inheritDoc}
*
* Merge the state of the detached object into the persistence context of
* this ObjectManager and returns the managed copy of the object.
*
* This will copy all fields of $document over the fields of the managed
* document and then cascade the merge to relations as configured.
*
* The object passed to merge will *not* become associated/managed with
* this ObjectManager.
*
* @param object $document The document to merge over a persisted document
* with the same id.
*
* @return object The managed document where $document has been merged
* into. This is *not* the same instance as the parameter.
*
* @throws InvalidArgumentException if $document is not an object.
*/
public function merge($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, ' . gettype($document) . ' given');
}
$this->errorIfClosed();
return $this->unitOfWork->merge($document);
}