/**
  * Gets owner of the given entity
  *
  * @param object $object
  * @return object
  * @throws \RuntimeException
  */
 public function getOwner($object)
 {
     if (!is_object($object)) {
         throw new InvalidEntityException('$object must be an object.');
     }
     $result = null;
     $metadata = $this->metadataProvider->getMetadata($this->entityClassAccessor->getClass($object));
     if ($metadata->hasOwner()) {
         // at first try to use getOwner method to get the owner
         if (method_exists($object, 'getOwner')) {
             $result = $object->getOwner();
         } else {
             // if getOwner method does not exist try to get owner directly from field
             try {
                 $cls = new \ReflectionClass($object);
                 $ownerProp = $cls->getProperty($metadata->getOwnerFieldName());
                 if (!$ownerProp->isPublic()) {
                     $ownerProp->setAccessible(true);
                 }
                 $result = $ownerProp->getValue($object);
             } catch (\ReflectionException $ex) {
                 throw new InvalidEntityException(sprintf('$object must have either "getOwner" method or "%s" property.', $metadata->getOwnerFieldName()), 0, $ex);
             }
         }
     }
     return $result;
 }
 /**
  * Gets class name for given object
  *
  * @param $object
  * @return string
  */
 protected function getObjectClassName($object)
 {
     if ($object instanceof ObjectIdentity) {
         $className = $object->getType();
     } elseif (is_string($object)) {
         $className = $id = null;
         $this->parseDescriptor($object, $className, $id);
     } else {
         $className = $this->entityClassAccessor->getClass($object);
     }
     return $className;
 }
 /**
  * Gets the real class name for the given domain object or the given class name that could be a proxy
  *
  * @param  object|string $domainObjectOrClassName
  * @return string
  */
 protected function getObjectClass($domainObjectOrClassName)
 {
     return $this->entityClassAccessor->getClass($domainObjectOrClassName);
 }