/**
  * @param array|mixed $id
  *
  * @return array
  * @throws MappingException
  */
 private function fixScalarId($id, $className)
 {
     if (is_array($id)) {
         return $id;
     }
     $id = (array) $id;
     $identifiers = $this->getClassMetadata($className)->getIdentifierFieldNames();
     if (count($id) !== count($identifiers)) {
         throw MappingException::invalidIdentifierStructure();
     }
     return array_combine($identifiers, (array) $id);
 }
 /**
  * @param array|mixed $id
  *
  * @return array
  * @throws MappingException
  */
 protected function fixScalarId($id, ApiMetadata $metadata)
 {
     if (is_array($id)) {
         return $id;
     }
     $id = (array) $id;
     $identifiers = $metadata->getIdentifierFieldNames();
     if (count($id) !== count($identifiers)) {
         throw MappingException::invalidIdentifierStructure();
     }
     return array_combine($identifiers, (array) $id);
 }
 /** {@inheritdoc} */
 public function getAssociationMapping($fieldName)
 {
     if (!isset($this->associations[$fieldName])) {
         throw MappingException::unknownAssociation($fieldName, $this->getName());
     }
     return $this->associations[$fieldName];
 }
 /**
  * Actually loads the metadata from the underlying metadata.
  *
  * @param EntityMetadata      $class
  * @param EntityMetadata|null $parent
  * @param bool                $rootEntityFound
  * @param array               $nonSuperclassParents    All parent class names
  *                                                     that are not marked as mapped superclasses.
  *
  * @return void
  * @throws MappingException
  */
 protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents)
 {
     /* @var $class EntityMetadata */
     /* @var $parent EntityMetadata */
     if ($parent) {
         $this->addInheritedFields($class, $parent);
         $this->addInheritedRelations($class, $parent);
         $class->setIdentifier($parent->identifier);
         $class->clientName = $parent->clientName;
         $class->searcher = $parent->searcher;
         $class->methodProvider = $parent->methodProvider;
         if ($parent->isMappedSuperclass) {
             $class->setCustomRepositoryClass($parent->repositoryClass);
         }
     }
     // Invoke driver
     try {
         $this->getDriver()->loadMetadataForClass($class->getName(), $class);
     } catch (ReflectionException $e) {
         throw MappingException::nonExistingClass($class->getName());
     }
 }
 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string                       $className
  * @param EntityMetadata|ClassMetadata $metadata
  *
  * @return void
  * @throws MappingException
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $element = $this->getElement($className);
     switch ($element['type']) {
         case 'entity':
             if (array_key_exists('repositoryClass', $element)) {
                 $metadata->setCustomRepositoryClass($element['repositoryClass']);
             }
             break;
         case 'mappedSuperclass':
             $metadata->isMappedSuperclass = true;
             $metadata->setCustomRepositoryClass(array_key_exists('repositoryClass', $element) ? $element['repositoryClass'] : null);
             break;
     }
     if (null === $metadata->searcher) {
         $metadata->searcher = DoctrineApi::class;
     }
     if (null === $metadata->finder) {
         $metadata->finder = DoctrineApi::class;
     }
     // Configure client
     if (array_key_exists('client', $element)) {
         if (array_key_exists('name', $element['client'])) {
             $metadata->clientName = $element['client']['name'];
         }
         if (array_key_exists('searcher', $element['client'])) {
             $metadata->searcher = $element['client']['searcher'];
         }
         if (array_key_exists('finder', $element['client'])) {
             $metadata->finder = $element['client']['finder'];
         }
         assert(in_array(Searcher::class, class_implements($metadata->searcher), true), 'Searcher ' . $metadata->searcher . ' should implement ' . Searcher::class);
         assert(in_array(Finder::class, class_implements($metadata->finder), true), 'Finder ' . $metadata->finder . ' should implement ' . Finder::class);
         $methodProvider = null;
         if (array_key_exists('methods', $element['client'])) {
             $methodProvider = new MethodProvider($element['client']['methods']);
         }
         if (array_key_exists('entityPath', $element['client'])) {
             $pathSeparator = array_key_exists('entityPathSeparator', $element['client']) ? $element['client']['entityPathSeparator'] : null;
             $methodProvider = new EntityMethodProvider($element['client']['entityPath'], $pathSeparator, $methodProvider);
         }
         if (null === $methodProvider) {
             throw MappingException::noMethods();
         }
         $metadata->methodProvider = $methodProvider;
     }
     // Configure fields
     if (array_key_exists('fields', $element)) {
         foreach ($element['fields'] as $field => $mapping) {
             $mapping = $this->fieldToArray($field, $mapping);
             $metadata->mapField($mapping);
         }
     }
     // Configure identifiers
     $associationIds = [];
     if (array_key_exists('id', $element)) {
         // Evaluate identifier settings
         foreach ($element['id'] as $name => $idElement) {
             if (isset($idElement['associationKey']) && (bool) $idElement['associationKey'] === true) {
                 $associationIds[$name] = true;
                 continue;
             }
             $mapping = $this->fieldToArray($name, $idElement);
             $mapping['id'] = true;
             $metadata->mapField($mapping);
         }
     }
     foreach (['oneToOne', 'manyToOne', 'oneToMany'] as $type) {
         if (array_key_exists($type, $element)) {
             $associations = $element[$type];
             foreach ($associations as $name => $association) {
                 $this->mapAssociation($metadata, $type, $name, $association, $associationIds);
             }
         }
     }
 }