Unset the closures that have been associated to the foreign keys by ColumnTypeGuesser,
so that attach() will automatically set them to the correct values.

@param  array $guessedFormatters
@return array The formatters.
169056
protected function unsetForeignKeys(array $guessedFormatters)
    {
        unset($guessedFormatters[$this->getForeignKeyName()], $guessedFormatters[$this->getRelatedKeyName()]);

        // If we're dealing with an inverse MorphToMany relation, we'll unset the morph type as well.
        if ($this->relation instanceof MorphToMany) {
            unset($guessedFormatters[$this->relation->getMorphType()]);
        }

        return $guessedFormatters;
    }
1193320
public function delete($key1, $key2, $unsets = null)
    {
        if (!is_array($unsets)) {
            $unsets = (array) $unsets;
        }

        switch ($key1) {
            case 'entityDefs':
                //unset related additional fields, e.g. a field with "address" type
                $fieldDefinitionList = $this->get('fields');

                $unsetList = $unsets;
                foreach ($unsetList as $unsetItem) {
                    if (preg_match('/fields\.([^\.]+)/', $unsetItem, $matches) && isset($matches[1])) {
                        $fieldName = $matches[1];
                        $fieldPath = [$key1, $key2, 'fields', $fieldName];

                        $additionalFields = $this->getMetadataHelper()->getAdditionalFieldList($fieldName, $this->get($fieldPath, []), $fieldDefinitionList);
                        if (is_array($additionalFields)) {
                            foreach ($additionalFields as $additionalFieldName => $additionalFieldParams) {
                                $unsets[] = 'fields.' . $additionalFieldName;
                            }
                        }
                    }
                }
                break;
        }

        $normalizedData = array(
            '__APPEND__',
        );
        $metadataUnsetData = array();
        foreach ($unsets as $unsetItem) {
            $normalizedData[] = $unsetItem;
            $metadataUnsetData[] = implode('.', array($key1, $key2, $unsetItem));
        }

        $unsetData = array(
            $key1 => array(
                $key2 => $normalizedData
            )
        );

        $this->deletedData = Util::merge($this->deletedData, $unsetData);
        $this->deletedData = Util::unsetInArrayByValue('__APPEND__', $this->deletedData, true);

        $this->data = Util::unsetInArray($this->getData(), $metadataUnsetData, true);
    }
719620
public function setFormatter(FormatterInterface $formatter, array $columns): self
    {
        $this->search()->in($columns)->setFormatter($formatter);

        return $this;
    }
1109960
protected function clearDeferredByPrefixes(array $prefixes): void
    {
        $deferred = AdapterUtil::getPropertyValue($this, 'deferred');

        foreach ($prefixes as $prefix) {
            foreach ($deferred as $key => $value) {
                if ('' === $prefix || 0 === strpos($key, $prefix)) {
                    unset($deferred[$key]);
                }
            }
        }

        AdapterUtil::setPropertyValue($this, 'deferred', $deferred);
    }
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;
	}
396400
private function initFormatters()
    {
        $formatter = $this->getFormatter();

        $formatter->setStyle('warning', new OutputFormatterStyle('black', 'yellow'));
        $formatter->setStyle('error',   new OutputFormatterStyle('black', 'red', ['bold']));
        $formatter->setStyle('aside',   new OutputFormatterStyle('blue'));
        $formatter->setStyle('strong',  new OutputFormatterStyle(null, null, ['bold']));
        $formatter->setStyle('return',  new OutputFormatterStyle('cyan'));
        $formatter->setStyle('urgent',  new OutputFormatterStyle('red'));
        $formatter->setStyle('hidden',  new OutputFormatterStyle('black'));

        // Visibility
        $formatter->setStyle('public',    new OutputFormatterStyle(null, null, ['bold']));
        $formatter->setStyle('protected', new OutputFormatterStyle('yellow'));
        $formatter->setStyle('private',   new OutputFormatterStyle('red'));
        $formatter->setStyle('global',    new OutputFormatterStyle('cyan', null, ['bold']));
        $formatter->setStyle('const',     new OutputFormatterStyle('cyan'));
        $formatter->setStyle('class',     new OutputFormatterStyle('blue', null, ['underscore']));
        $formatter->setStyle('function',  new OutputFormatterStyle(null));
        $formatter->setStyle('default',   new OutputFormatterStyle(null));

        // Types
        $formatter->setStyle('number',   new OutputFormatterStyle('magenta'));
        $formatter->setStyle('string',   new OutputFormatterStyle('green'));
        $formatter->setStyle('bool',     new OutputFormatterStyle('cyan'));
        $formatter->setStyle('keyword',  new OutputFormatterStyle('yellow'));
        $formatter->setStyle('comment',  new OutputFormatterStyle('blue'));
        $formatter->setStyle('object',   new OutputFormatterStyle('blue'));
        $formatter->setStyle('resource', new OutputFormatterStyle('yellow'));
    }
758289
public function setAssignNonMappedColumns($assignNonMappedColumns)
    {
        if (empty($this->mappingOptions)) $this->resetMappingOptions();

        $this->mappingOptions->assignNonMappedColumns = $assignNonMappedColumns;

        return $this;
    }
417890
protected function makeRelations(array $models)
    {
        foreach ($models as $model) {
            $localTable  = $model->getTable();
            $foreignKeys = $localTable->getTableForeignKeys();

            foreach ($foreignKeys as $foreignKey) {
                if (!isset($models[$foreignKey->getForeignTableName()])) {
                    continue;
                }

                $foreignModel = $models[$foreignKey->getForeignTableName()];
                $foreignTable = $foreignModel->getTable();

                $localColumns   = $foreignKey->getLocalColumns();
                $foreignColumns = $foreignKey->getForeignColumns();

                $localIndex   = $localTable->getTableIndexByColumnsName($localColumns);
                $foreignIndex = $foreignTable->getTableIndexByColumnsName($foreignColumns);

                $localTableClass   = str_singular($model->getFullClass());
                $foreignTableClass = str_singular($foreignModel->getFullClass());

                $localColumn   = reset($localColumns);
                $foreignColumn = reset($foreignColumns);

                // Guess foreign method name
                $localMethodName   = str_replace(['_id'], '', snake_case($localColumn));
                $foreignMethodName = $model->getClass();

                // Try to find out connection type
                if ($localIndex !== false && $foreignIndex !== false && $localIndex->isUnique() && $foreignIndex->isUnique()) {
                    // One To One
                    $localTable->addHasOneRelation($foreignTableClass, $localMethodName, $foreignColumn, $localColumn);
                    $foreignTable->addBelongsToRelation($localTableClass, $foreignMethodName, $localColumn, $foreignColumn);
                } elseif ($foreignIndex !== false && $foreignIndex->isUnique()) {
                    // Many To One
                    $localTable->addBelongsToRelation($foreignTableClass, $localMethodName, $localColumn, $foreignColumn);
                    $foreignTable->addHasManyRelation($localTableClass, $foreignMethodName, $localColumn, $foreignColumn);
                } elseif ($localIndex !== false && $localIndex->isUnique()) {
                    // One To Many
                    $localTable->addHasManyRelation($foreignTableClass, $localMethodName, $foreignColumn, $localColumn);
                    $foreignTable->addBelongsToRelation($localTableClass, $foreignMethodName, $localColumn, $foreignColumn);
                } else {
                    // Many To Many without pivot table
                    $localTable->addHasManyRelation($foreignTableClass, $localMethodName, $foreignColumn, $localColumn);
                    $foreignTable->addHasManyRelation($localTableClass, $foreignMethodName, $localColumn, $foreignColumn);
                }
            }
        }
    }
380337
private function checkLinesBetweenAnnotationsTypes($annotations)
    {
        if (empty($annotations)) {
            return;
        }

        $previousAnnotation = null;

        foreach ($annotations as $annotation) {
            if ($previousAnnotation === null) {
                $previousAnnotation = $annotation;
                continue;
            }

            $lines = $this->countLinesBetweenAnnotations($annotation, $previousAnnotation);
            $currentName = $this->getAnnotationName($annotation);
            $previousName = $this->getAnnotationName($previousAnnotation);

            $currentName === $previousName
                ? $this->checkSameAnnotations($annotation, $lines)
                : $this->checkDifferentAnnotations($annotation, $lines);

            $previousAnnotation = $annotation;
        }
    }
774045
private function mergeDefaults(array $given, $methods)
    {
        $defaults = array_merge(array_combine(self::$keys, array_pad([], count(self::$keys), null)), $given);

        if (null === $defaults[self::K_SCHEME]) {
            $defaults[self::K_SCHEME] = 'http|https';
        }

        if (null === $defaults[self::K_NAME]) {
            $defaults[self::K_NAME] = $this->generateName($methods);
        }

        return $defaults;
    }
184532
private function cleanFields(array $fields): array
    {
        foreach ($fields['fields'] as &$field) {
            if (array_key_exists('generator', $field[key($field)])) {
                unset($field[key($field)]['generator']);
            }
        }

        unset($fields['section']);
        return $fields;
    }
1319651
public function formatters($formatters = null)
    {
        if (!func_num_args()) {
            return $this->_formatters;
        }
        $this->_formatters = $formatters;
        return $this;
    }
1256178
public function setRemovedIndices(array $removedIndices)
    {
        $this->removedIndices = [];
        foreach ($removedIndices as $removedIndex) {
            $this->addRemovedIndex($removedIndex->getName(), $removedIndex);
        }
    }
540788
public function prepareBindingsForDelete(array $bindings)
    {
        $cleanBindings = Arr::except($bindings, ['select', 'join']);

        return array_values(
            array_merge($bindings['join'], Arr::flatten($cleanBindings))
        );
    }
971361
private function formatScopes($unformatted = [])
    {
        $scopes = [];
        if (is_array($unformatted)) {
            foreach ($unformatted as $scope) {
                if ($scope instanceof ScopeEntity) {
                    $scopes[$scope->getId()] = $scope;
                }
            }
        }

        return $scopes;
    }
1298376
public function prepareBindingsForUpdate(array $bindings, array $values)
	{
		$index = 0;

		foreach ($values as $column => $value) {
			if ($this->isJsonSelector($column) && is_bool($value)) {
				unset($bindings[$index]);
			}

			$index++;
		}

		return $bindings;
	}
1302686
public function setIgnorePatterns($ignorePatterns)
    {
        $this->_ignorePatterns = array();
        $token                 = ' ,;';
        $pattern               = strtok($ignorePatterns, $token);

        while ($pattern !== false) {
            $this->_ignorePatterns[] = $pattern;
            $pattern                 = strtok($token);
        }

    }