Generates property mapping from entity annotations

@param array $mappings
508798
protected function getMapping($mappings)
    {
        $properties = array();

        foreach ($mappings as $propertyName => $fieldMapping) {
            if (isset($fieldMapping['fieldName'])) {
                $propertyName = $fieldMapping['fieldName'];
            }

            if (isset($fieldMapping['type'])) {
                $properties[$propertyName]['type'] = $fieldMapping['type'];
 
                if ($fieldMapping['type'] == 'attachment' && isset($fieldMapping['fields'])) {
                    $callback = function ($field) {
                        unset($field['type']);
                        return $field;
                    };
                    $properties[$propertyName]['fields'] = array_map($callback, $this->getMapping($fieldMapping['fields']));
                }

                if ($fieldMapping['type'] == 'multi_field' && isset($fieldMapping['fields'])) {
                    $properties[$propertyName]['fields'] = $this->getMapping($fieldMapping['fields']);
                }
  
                if (in_array($fieldMapping['type'], array('nested', 'object')) && isset($fieldMapping['properties'])) {
                    $properties[$propertyName]['properties'] = $this->getMapping($fieldMapping['properties']);
                }
            }

            if (isset($fieldMapping['path'])) {
                $properties[$propertyName]['path'] = $fieldMapping['path'];
            }

            if (isset($fieldMapping['includeInAll'])) {
                $properties[$propertyName]['include_in_all'] = $fieldMapping['includeInAll'];
            }

            if (isset($fieldMapping['nullValue'])) {
                $properties[$propertyName]['null_value'] = $fieldMapping['nullValue'];
            }

            if (isset($fieldMapping['store'])) {
                $properties[$propertyName]['store'] = $fieldMapping['store'];
            }

            if (isset($fieldMapping['index'])) {
                $properties[$propertyName]['index'] = $fieldMapping['index'];
            }

            if (isset($fieldMapping['boost'])) {
                $properties[$propertyName]['boost'] = $fieldMapping['boost'];
            }

            if (isset($fieldMapping['analyzer'])) {
                $properties[$propertyName]['analyzer'] = $fieldMapping['analyzer'];
            }

            if (isset($fieldMapping['indexName'])) {
                $properties[$propertyName]['index_name'] = $fieldMapping['indexName'];
            }

            if (isset($fieldMapping['geohash'])) {
                $properties[$propertyName]['geohash'] = $fieldMapping['geohash'];
            }

            if (isset($fieldMapping['geohash_precision'])) {
                $properties[$propertyName]['geohash_precision'] = $fieldMapping['geohash_precision'];
            }

            if (isset($fieldMapping['geohash_prefix'])) {
                $properties[$propertyName]['geohash_prefix'] = $fieldMapping['geohash_prefix'];
            }
        }

        return $properties;
    }
843276
private function buildQueriesMap(array $customEntitiesMap)
    {
        $map = [];

        foreach ($customEntitiesMap as $entitiesMap) {
            foreach ($entitiesMap as $entityMap) {
                foreach ($entityMap as $targetPropertyMap) {
                    $customEntityClass = $targetPropertyMap['class'];
                    $initProperty = $targetPropertyMap['initProperty'];
                    $initPropertyValue = $targetPropertyMap['initPropertyValue'];

                    if (!isset($map[$customEntityClass])) {
                        $map[$customEntityClass] = [];
                    }
                    if (!isset($map[$customEntityClass][$initProperty])) {
                        $map[$customEntityClass][$initProperty] = [];
                    }
                    if (!in_array($initPropertyValue, $map[$customEntityClass][$initProperty])) {
                        $map[$customEntityClass][$initProperty][$initPropertyValue] = $initPropertyValue;
                    }
                }
            }
        }

        return $map;
    }
1044861
public function setMapping(array $mappingOptions)
    {
        $coverMapping = new CoverFishMapping();
        $coverMapping->setAnnotation($mappingOptions['coverToken']);
        $coverMapping->setMethod($mappingOptions['coverMethod']);
        $coverMapping->setAccessor($mappingOptions['coverAccessor']);
        $coverMapping->setClass($mappingOptions['coverClass']);
        $coverMapping->setClassFQN($mappingOptions['coverClassFQN']);
        $coverMapping->setValidatorMatch($mappingOptions['validatorMatch']);
        $coverMapping->setValidatorClass($mappingOptions['validatorClass']);
        $coverMapping->setValidatorResult($this->validateMapping($coverMapping));

        return $coverMapping;
    }
347554
public static function isAttributeProperty(array &$mappings, $propertyName, $type)
    {
        return Serializer::CLASS_IDENTIFIER_KEY !== $propertyName
        && !in_array($propertyName, RecursiveFormatterHelper::getIdProperties($mappings, $type));
    }
901282
public function runMappingList(array $mappings, array $options = [])
    {
        // First we will just make sure that there are any migrations to run. If there
        // aren't, we will just make a note of it to the developer.
        if (count($mappings) == 0) {
            $this->note('<info>Nothing to map</info>');

            return;
        }

        $batch = $this->repository->getNextBatchNumber();

        $step = Arr::get($options, 'step', false);
        $index = Arr::get($options, 'index');

        foreach ($mappings as $file) {
            $this->runMap($file, $batch, $index);

            if ($step) {
                $batch++;
            }
        }
    }
870885
public function prepareBindings( array $bindings )
	{
		$grammar = $this->getQueryGrammar();

		foreach( $bindings as $key => $value )
		{
			// We need to transform all instances of DateTimeInterface into the actual
			// date string. Each query grammar maintains its own date string format
			// so we'll just ask the grammar for the format to get from the date.
			if( $value instanceof DateTimeInterface )
			{
				$bindings[ $key ] = $value->format( $grammar->getDateTimeFormatString() );
			}
			else if( $value === false )
			{
				$bindings[ $key ] = 0;
			}
		}

		return $bindings;
	}
447178
protected function getRootMapping($mappings)
    {
        $properties = array();

        foreach ($mappings as $rootMapping) {
            $propertyName = $rootMapping['fieldName'];
            $mapping = array();

            if (isset($rootMapping['value'])) {
                $mapping = $rootMapping['value'];
            }

            if (isset($rootMapping['match'])) {
                $mapping['match'] = $rootMapping['match'];
            }

            if (isset($rootMapping['pathMatch'])) {
                $mapping['path_match'] = $rootMapping['pathMatch'];
            }

            if (isset($rootMapping['unmatch'])) {
                $mapping['unmatch'] = $rootMapping['unmatch'];
            }

            if (isset($rootMapping['pathUnmatch'])) {
                $mapping['path_unmatch'] = $rootMapping['pathUnmatch'];
            }

            if (isset($rootMapping['matchPattern'])) {
                $mapping['match_pattern'] = $rootMapping['matchPattern'];
            }

            if (isset($rootMapping['matchMappingType'])) {
                $mapping['match_mapping_type'] = $rootMapping['matchMappingType'];
            }

            if (isset($rootMapping['mapping'])) {
                $mapping['mapping'] = current($this->getMapping(array($rootMapping['mapping'])));
            }

            if (isset($rootMapping['id'])) {
                $properties[$propertyName][][$rootMapping['id']] = $mapping;
            } else {
                $properties[$propertyName] = $mapping;
            }
        }

        return $properties;
    }
234242
public function addMaps(array $maps)
    {
        foreach ($maps as $locale => $map) {
            $this->addMap($locale, $map);
        }

        return $this;
    }
409630
public function createAssoc(array $properties, array $mapping)
    {
        $values = (array) $properties[$mapping['property']];
        if (!isset($properties[$mapping['assoc']])) {
            return $values;
        }

        $keys = (array) $properties[$mapping['assoc']];
        $nulls = (array) ($properties[$mapping['assocNulls']] ?? []);

        // make sure we start with first value
        reset($values);
        $result = [];
        foreach ($keys as $key) {
            if (in_array($key, $nulls)) {
                $result[$key] = null;
            } else {
                $result[$key] = current($values);
                next($values);
            }
        }

        return $result;
    }
142152
public function setShardKey(array $keys, array $options = array())
    {
        if ($this->inheritanceType == self::INHERITANCE_TYPE_SINGLE_COLLECTION && !is_null($this->shardKey)) {
            throw MappingException::shardKeyInSingleCollInheritanceSubclass($this->getName());
        }

        if ($this->isEmbeddedDocument) {
            throw MappingException::embeddedDocumentCantHaveShardKey($this->getName());
        }

        $this->shardKey = array(
            'keys' => array_map(function($value) {
                if ($value == 1 || $value == -1) {
                    return (int) $value;
                }
                if (is_string($value)) {
                    $lower = strtolower($value);
                    if ($lower === 'asc') {
                        return 1;
                    } elseif ($lower === 'desc') {
                        return -1;
                    }
                }
                return $value;
            }, $keys),
            'options' => $options
        );
    }
1097426
public function setMappings($mappings)
    {
        if ($mappings instanceof \Closure) {
            $mappings = $mappings();
        }

        $this->mappings = (array) $mappings;

        return $this;
    }
239635
protected function normalizeMappingSources(array $mappingSources): array
    {
        return \array_map(
            function ($mappingSource): array {
                if (!\is_array($mappingSource)) {
                    $mappingSource = [
                        'type' => DriverFactoryInterface::DRIVER_ANNOTATION,
                        'path' => $mappingSource,
                    ];
                }

                return $mappingSource;
            },
            $mappingSources
        );
    }
1080718
public static function getIdValues(array $mappings, array $value, $type)
    {
        $ids = [];
        foreach (\array_keys($value) as $propertyName) {
            if (\in_array($propertyName, RecursiveFormatterHelper::getIdProperties($mappings, $type), true)) {
                $id = RecursiveFormatterHelper::getIdValue($value[$propertyName]);
                $ids[] = (\is_array($id)) ? \implode(JsonApiTransformer::ID_SEPARATOR, $id) : $id;
            }
        }

        return $ids;
    }
301671
protected function findObjects(array $ids)
    {
        $foundObjects = $this->domain->getRepository()->findBy([
            $this->identifier => array_unique($ids),
        ]);
        $mapFinds = [];
        $objects = [];

        foreach ($foundObjects as $foundObject) {
            $id = $this->propertyAccessor->getValue($foundObject, $this->identifier);
            $mapFinds[$id] = $foundObject;
        }

        foreach ($ids as $i => $id) {
            $objects[$i] = $mapFinds[$id]
                ?? $this->domain->newInstance($this->defaultValueOptions);
        }

        return $objects;
    }
577958
protected function generateForeignKeys( array $tables )
	{
		$this->method = 'table';

		foreach ( $tables as $table ) {
			$this->table = $table;
			$this->migrationName = 'add_foreign_keys_to_'. $this->table .'_table';
			$this->fields = $this->schemaGenerator->getForeignKeyConstraints( $this->table );

			$this->generate();
		}
	}
172075
public static function map($array, $mapping) {
        $result = array();
        foreach($mapping as $src=>$dest) {
            if(array_key_exists($src, $array)) {
                $result[$dest] = $array[$src];
            }
        }
        return $result;
    }
244858
public static function serializedObjectToArray(array &$array, array &$mappings)
    {
        foreach ($array as $key => &$value) {
            if ($key === Serializer::CLASS_IDENTIFIER_KEY) {
                $type = $array[Serializer::CLASS_IDENTIFIER_KEY];
                if (empty($mappings[$type])) {
                    unset($array[Serializer::CLASS_IDENTIFIER_KEY]);
                }
            }
            if (is_array($value)) {
                foreach($value as $k => &$v) {
                    if (is_array($v)) {
                        $v = self::serializedObjectToArray($v, $mappings);
                    }
                }
            }
        }
        return $array;
    }