@param array $toFlat
@param int $preserveKeys

@return array
514769
public function flatten(array $toFlat, $preserveKeys = self::NO_PRESERVE_KEYS)
    {
        if ($preserveKeys === self::PRESERVE_KEYS) {
            $flatten = $this->flattenPreservingKeys($toFlat);
        } elseif ($preserveKeys === self::PRESERVE_ASSOCIATIVE_KEYS) {
            $flatten = $this->flattenPreservingAssociativeKeys($toFlat);
        } else {
            $flatten = $this->flattenNotPreservingKeys($toFlat);
        }

        return $flatten;
    }
723295
public static function arrExclude(array $arr, array $excludeKeys)
    {
        $result = [];
        foreach ($arr as $key => $val) {
            if (!in_array($key, $excludeKeys)) {
                $result[$key] = $val;
            }
        }
        return $result;
    }
408321
public static function chunk(array $array, int $chunkSize, bool $preserveKeys = false): array
    {
        if (empty($array)) {
            return [];
        }

        return \array_chunk($array, $chunkSize, $preserveKeys);
    }
440923
public function normalizeKeys($keys)
    {
        if ($keys === true) {
            $keys = $this->keys();
        }

        if (empty($keys)) {
            return [];
        }

        return $this->_normalizeAssociations($keys);
    }
293126
public static function keyFlattening($array, $keys = []) {
		if (is_array($array)) {
			$result = [];
			foreach ($array as $key => $value) {
				$tmp_keys = $keys;
				$tmp_keys [] = $key;
				$result = array_merge($result, static::keyFlattening($value,$tmp_keys));
			}
			return $result;
		}

		$key = array_shift($keys);
		return [
			empty($keys) ? $key : sprintf('%s[%s]', $key, implode ('][', $keys)) => $array,
		];
	}
916116
protected function _getPortableTableForeignKeysList($tableForeignKeys)
    {
        $list = [];

        foreach ($tableForeignKeys as $value) {
            $list[] = $this->_getPortableTableForeignKeyDefinition($value);
        }

        return $list;
    }
843444
private function fromFlattenedSerializationRecipientToSerialization($input)
    {
        $recipient = [];
        foreach (['header', 'encrypted_key'] as $key) {
            if (array_key_exists($key, $input)) {
                $recipient[$key] = $input[$key];
            }
        }
        $recipients = [
            'ciphertext' => $input['ciphertext'],
            'recipients' => [$recipient],
        ];
        foreach (['protected', 'unprotected', 'iv', 'aad', 'tag'] as $key) {
            if (array_key_exists($key, $input)) {
                $recipients[$key] = $input[$key];
            }
        }

        $this->log(LogLevel::INFO, 'JWE in Flattened JSON Serialization mode loaded.');

        return $recipients;
    }
814201
public function flatten( array $array, $preserve_keys = false ) {
		$return = [];
		array_walk_recursive( $array, function ( $v, $k ) use ( &$return, $preserve_keys ) {
			if ( $preserve_keys ) {
				$return[ $k ] = $v;
			} else {
				$return[] = $v;
			}
		} );

		return $return;
	}
825560
public function reverse($preserveKeys = false) : self
    {
        $clone = clone $this;
        $clone->elements = array_reverse($this->elements, $preserveKeys);

        return $clone;
    }
125396
private function getMappedSettings(array $settings, $fromIndex, $toIndex)
    {
        $mappedSettings = ['sourceOrder' => [], 'sources' => []];

        if (isset($settings['sourceOrder'])) {
            foreach ($settings['sourceOrder'] as $row) {
                if ('key' == $row[0]) {
                    $row[1] = $this->getSource('', $row[1], $fromIndex, $toIndex);
                }
                $mappedSettings['sourceOrder'][] = $row;
            }
        }

        if (isset($settings['sources'])) {
            foreach ($settings['sources'] as $source => $sourceSettings) {
                $mappedSource = $this->getSource('', $source, $fromIndex, $toIndex);
                $mappedSettings['sources'][$mappedSource] = [
                  'tableAttributes' => $this->getSources('', $sourceSettings['tableAttributes'], $fromIndex, $toIndex),
                ];
            }
        }

        return $mappedSettings;
    }
152736
protected function getAllSettingsFlat()
    {
        return $this->getAllSettings()->flatMap(function (Model $model) {
            return [$model->key => json_decode($model->value)[0]];
        });
    }
265095
public function getInfos($asFlat = false)
    {
        $iterator = true === $asFlat
            ? $this->getRecursiveIterator()
            : $this;

	    $infos = array();
	    foreach ($iterator as $element) {
	        if ($element->getType() == self::TYPE_INFO) {
	            $infos[] = $element;
	        }
	    }
	    return $infos;
	}
542721
final protected function bulkUpdateForeignKeys(PersistenceContext $context, array $modifiedColumns, array $children) : array
    {
        $primaryKey     = $this->mapper->getPrimaryTable()->getPrimaryKeyColumn();
        $primaryKeyName = $primaryKey->getName();

        $columnsToPersist = array_merge([$primaryKey], $modifiedColumns);

        $rowSet = new RowSet($this->mapper->getPrimaryTable()->withColumnsButIgnoringConstraints($columnsToPersist));
        $rows   = [];

        foreach ($children as $key => $childId) {
            if ($childId !== null) {
                $row = $rowSet->createRow([$primaryKeyName => $childId]);
                $rowSet->add($row);
                $rows[$key] = $row;
            }
        }

        if ($modifiedColumns) {
            if ($rowSet->count() > 0) {
                $context->bulkUpdate($rowSet);
            }
        }

        return $rows;
    }
1117809
private function validate_validators( \SplObjectStorage $validators, $to_validate, $key ) {

		$valid = TRUE;

		$validators->rewind();
		while ( $validators->valid() ) {

			/** @var ExtendedValidatorInterface $validator */
			$validator = $validators->current();
			/** @var string|null $message */
			$message = $validators->getInfo();

			$valid = $this->validate_validator( $to_validate, $validator, $key, $message ) && $valid;

			$validators->next();
		}

		return $valid;

	}
899020
private function fromCompactSerializationRecipientToSerialization(array $parts)
    {
        $recipient = [];
        if (!empty($parts[1])) {
            $recipient['encrypted_key'] = $parts[1];
        }

        $recipients = [
            'recipients' => [$recipient],
        ];
        foreach ([0 => 'protected', 2 => 'iv', 3 => 'ciphertext', 4 => 'tag'] as $part => $key) {
            if (!empty($parts[$part])) {
                $recipients[$key] = $parts[$part];
            }
        }

        return $recipients;
    }
293325
public function optimize(array $policiesAndSets): array
    {
        assert(empty($policiesAndSets) === false);

        $index              = 0;
        $rawTargets         = [];
        $serializedPolicies = [];
        foreach ($policiesAndSets as $policyOrSet) {
            /** @var PolicyInterface|PolicySetInterface $policyOrSet */
            $rawTargets[$index]         = $policyOrSet->getTarget();
            $serializedPolicies[$index] = $policyOrSet instanceof PolicyInterface ?
                Encoder::encodePolicy($policyOrSet) : Encoder::encodePolicySet($policyOrSet);
            $index++;
        }

        $callable         = static::METHOD;
        $optimizedTargets = $this->optimizeTargets($rawTargets);

        /** @var callable|array $callable */
        assert($callable !== null && is_array($callable) === true &&
            is_callable($callable) === true && count($callable) === 2 &&
            is_string($callable[0]) === true && is_string($callable[1]) === true);

        return [
            static::INDEX_TARGETS           => $optimizedTargets,
            static::INDEX_POLICIES_AND_SETS => $serializedPolicies,
            static::INDEX_CALLABLE          => $callable,
        ];
    }
1060755
public function groupBy($groupBy, $preserveKeys = false)
    {
        $groupBy = $this->valueRetriever($groupBy);

        $results = [];

        foreach ($this->items as $key => $value) {
            $groupKeys = $groupBy($value, $key);

            if (!is_array($groupKeys)) {
                $groupKeys = [$groupKeys];
            }

            foreach ($groupKeys as $groupKey) {
                $groupKey = is_bool($groupKey) ? (int) $groupKey : $groupKey;

                if (!array_key_exists($groupKey, $results)) {
                    $results[$groupKey] = new static;
                }

                $results[$groupKey]->offsetSet($preserveKeys ? $key : null, $value);
            }
        }

        return new static($results);
    }