protected function mergeMetadata($source, $target)
{
if ($source instanceof \ArrayAccess) {
if ($target instanceof \ArrayAccess) {
if ($source instanceof MetadataInterface) {
$metadata = $source->getMetadata();
foreach ($metadata as $offset => $value) {
$target->offsetSet($offset, $value);
}
} else {
throw new \RuntimeException('Source had to make all metadata available!');
}
} else {
throw new \RuntimeException('Source metadata can not be merged!');
}
}
}