Helper function to figure out which array to use

@param string $fieldName Field name
@param string $key       filters or sorts

@throws InvalidArgumentException

@return array
505757
protected function getArrayAndKeyName(string $fieldName, string $key): array
    {
        if (!in_array($key, ['filters', 'sorts'], true)) {
            throw new InvalidArgumentException('Key must be one of [filters, sorts]');
        }
        if (str_contains($fieldName, '.')) {
            $path         = explode('.', $fieldName);
            $name         = array_pop($path);
            $relationPath = implode('.', $path);
            $array        = array_get($this->relations, "$relationPath.$key", []);
        } else {
            $name  = $fieldName;
            $array = ($key === 'filters') ? $this->filters : $this->sorts;
        }
        return [$name, $array];
    }
424099
private static function getField($fieldName)
    {
        $agentDetails = self::getAgentDetails();
        $values       = [];

        foreach ($agentDetails as $agent) {
            if (!isset($agent[$fieldName])) {
                throw new \Exception("Field name \"$fieldName\" not found, can't continue");
            }

            $values[] = $agent[$fieldName];
        }

        return array_values(array_unique($values));
    }
336073
public function getMetaTags($tagName, array $params = array())
    {
        if (!isset($params[0])) {
            throw new InvalidArgumentException(
                '$params[0]',
                'Field type handlers require at least a field identifier.'
            );
        }

        $fieldIdentifiers = is_array($params[0]) ? $params[0] : array($params[0]);
        $fieldValue = $this->getFallbackValue($tagName, $params);

        foreach ($fieldIdentifiers as $fieldIdentifier) {
            $field = $this->validateField($fieldIdentifier);

            try {
                $fieldValue = $this->getFieldValue($field, $tagName, $params);
                break;
            } catch (FieldEmptyException $e) {
                // do nothing
            }
        }

        return array(
            new Item(
                $tagName,
                $fieldValue
            ),
        );
    }
64083
protected function createArray(string $fieldName, array $aggregation): array
    {
        $return = [];
        $buckets = $aggregation['buckets'] ?? $aggregation[$fieldName]['buckets'] ?? null;
        if (!$buckets) {
            return $return;
        }
        $attributeId = $this->isAttribute($fieldName);
        foreach ($buckets as $key => $bucket) {
            $return[$key]['count'] = $bucket['doc_count'];
            $return[$key][($attributeId === false ? $fieldName : 'attributeValueId')] = $bucket['key'];
            if ($attributeId !== false) {
                $return[$key]['attributeId'] = $attributeId;
            }
        }

        return array_values($return);
    }
922964
protected function explodeFieldNameArray($fieldName)
    {
        $name = str_replace('][', '.', $fieldName);
        $name = str_replace(array('[', ']'), '.', $name);

        $name = rtrim($name, '.');

        return explode('.', $name);
    }
1214596
public function keys(?string $key = null) : array
    {
        $value = $this->get($key);

        if (!is_array($value)) {
            throw new InvalidArgumentException(
                'method keys() should be called on array'
            );
        }

        return array_keys($value);
    }
995237
private function flattenKey($storageName, $key)
    {
        $finalKey = $storageName . '-';

        if (is_string($key)) {
            return $finalKey . $key;
        }

        if (! is_array($key)) {
            throw new \InvalidArgumentException('The key should be a string or a flat array.');
        }

        foreach ($key as $property => $value) {
            $finalKey .= sprintf('%s:%s-', $property, $value);
        }

        return $finalKey;
    }
770983
public function getFilter(string $fieldName): ?Condition
    {
        [$name, $filters] = $this->getArrayAndKeyName($fieldName, 'filters');

        return array_first($filters, function ($filter) use ($name) {
            return $filter->getName() === $name;
        });
    }
486131
public function getInvalidInputExceptionFor(string $fieldName)
    {
        return isset($this->invalidInputExceptions[$fieldName])
                ? $this->invalidInputExceptions[$fieldName]
                : null;
    }
895095
public function getField($fieldName) {
        if(empty($fieldName)) {
            throw new \InvalidArgumentException('Please provide a fieldname');
        }
        
        $values = array();
        foreach($this->fields as $field) {
            if($field['name'] == $fieldName) {
                $values[] = $field['value'];
            }
        }
        
        return $values;
    }
912750
private function getFields($field)
    {
        if ($field instanceof Group || $field instanceof Fieldset) {
            $elements = $field->getFields();
        } elseif ($field instanceof AbstractField) {
            $elements = [$field];
        } else {
            throw new \InvalidArgumentException(sprintf(
                "Invalid type '%s'",
                is_object($field) ? get_class($field) : gettype($field)
            ));
        }

        return $elements;
    }
1310812
private function parseFieldRepeaters(array $fields, $key)
    {
        $blacklist = ['repeater', 'slug', 'templatefield'];
        $repeater = $fields[$key];

        if (!isset($repeater['fields']) || !is_array($repeater['fields'])) {
            return;
        }

        foreach ($repeater['fields'] as $repeaterKey => $repeaterField) {
            if (!isset($repeaterField['type']) || in_array($repeaterField['type'], $blacklist)) {
                unset($repeater['fields'][$repeaterKey]);
            }
        }

        return $repeater;
    }
537811
public function prepareFieldName(string $fieldName) : string
    {
        $fieldNames = $this->prepareQueryElement($fieldName, null, null, false);

        return $fieldNames[0][0];
    }
691138
private function getIndex(string $indexedFieldName): array
    {
        // build index
        if ($this->index === null) {
            // init empty index
            $this->index = [];

            // get index definition
            $indexedFields = $this->getIndexDefinition();

            // build index for database
            if (!empty($indexedFields)) {
                // init all defined indexes
                foreach ($this->clusterIndex as $entryArray) {
                    $entry = $this->arrayToEntry($entryArray);
                    foreach ($indexedFields as $indexName => $indexDefinition) {
                        if (is_array($indexDefinition)) {
                            // compound index
                            $reference = &$this->index[$indexName];
                            foreach ($indexDefinition as $indexDefinitionPart) {
                                // limited length of field
                                if (is_array($indexDefinitionPart)) {
                                    $indexDefinitionPartValue = substr(
                                        $entryArray[$indexDefinitionPart[0]],
                                        0,
                                        $indexDefinitionPart[1]
                                    );
                                } else {
                                    $indexDefinitionPartValue = $entryArray[$indexDefinitionPart];
                                }
                                if (!isset($reference[$indexDefinitionPartValue])) {
                                    $reference[$indexDefinitionPartValue] = [];
                                }
                                $reference = &$reference[$indexDefinitionPartValue];
                            }

                            $reference = $entry;
                        } else {
                            // single index
                            $indexName = $indexDefinition;
                            // skip empty field
                            if (empty($entryArray[$indexDefinition])) {
                                continue;
                            }
                            // add to index
                            $this->index[$indexName][$entryArray[$indexDefinition]] = $entry;
                        }
                    }
                }
            }
        }

        // get index
        if (!isset($this->index[$indexedFieldName])) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Unknown index "%s" in database "%s"',
                    $indexedFieldName,
                    get_class()
                )
            );
        }

        return $this->index[$indexedFieldName];
    }
1028244
public function getFiles( $fieldKey )
	{
		$allFiles = $this->getAllFiles();

		if ( isset($allFiles[ $fieldKey ]) )
		{
			return $allFiles[ $fieldKey ];
		}
		else
		{
			return [ ];
		}
	}
830206
public function get($key)
    {
        if (!array_key_exists($key, $this->options)) {
            throw new InvalidArgumentException(sprintf('The key %s does not exist.', $key));
        }

        return $this->options[$key];
    }
722031
public function fieldsByKey($key)
	{
		$keys = array();

		if ($this->rows && $this->count())
		{
			foreach ($this->rows as $row)
			{
				$keys[] = $row->$key;
			}
		}

		return $keys;
	}