This is the same as isIndexed but it does not check if
array is zero-indexed and has sequential keys.
public static isIndexedArray ( array $arr ) : boolean | ||
$arr | array | |
Résultat | boolean | True if indexed, false if associative |
/** * Get the return value from the callable. * * Parameters can be can handled in three ways: * - null - Nothing passed to the callback * - Indexed array - Value of each element will be passed to function in order * - Associative array - Key names will attempt to match to the callable function variable names */ protected function invokeCallable(callable $callback, $callbackArguments) { if ($callbackArguments === null) { return call_user_func($callback); } if (Arr::isIndexedArray($callbackArguments)) { return call_user_func_array($callback, (array) $callbackArguments); } $orderedArgs = $this->getArguments($callback, $callbackArguments); return call_user_func_array($callback, $orderedArgs); }
/** * Call this in register method. * * @internal */ protected final function extendRepositoryMapping() { $app = $this->getContainer(); $app['storage'] = $app->share($app->extend('storage', function ($entityManager) use($app) { foreach ($this->registerRepositoryMappings() as $alias => $map) { if (Arr::isIndexedArray($map)) { // Usually caused by [entity, repo] instead of [entity => repo] throw new \RuntimeException(sprintf('Repository mapping for %s `%s` is not an associative array.', __CLASS__, $alias)); } $app['storage.repositories'] += $map; $app['storage.metadata']->setDefaultAlias($app['schema.prefix'] . $alias, key($map)); $entityManager->setRepository(key($map), current($map)); } return $entityManager; })); }
/** * Build a GET query if required. * * @param array $redirect * @param FormData $formData * * @return string */ protected function getRedirectQuery(array $redirect, FormData $formData) { if (!isset($redirect['query']) || empty($redirect['query'])) { return ''; } $query = array(); if (is_array($redirect['query'])) { if (Arr::isIndexedArray($redirect['query'])) { foreach ($redirect['query'] as $param) { $query[$param] = $formData->get($param); } } else { foreach ($redirect['query'] as $id => $param) { $query[$id] = $formData->get($param); } } } else { $param = $redirect['query']; $query[$param] = $formData->get($param); } return '?' . http_build_query($query); }
/** * Import each migration file * * @return \Bolt\Storage\Migration\Import */ public function importMigrationFiles() { if ($this->getError()) { return $this; } foreach ($this->files as $file) { // Read the file data in if (!$file['handler']->readFile()) { continue; } // Get the file name $filename = (string) $file['file']; // Our import arrays should be indexed, if not we have a problem if (!Arr::isIndexedArray($this->data)) { $this->setError(true)->setErrorMessage("File '{$filename}' has an invalid import format!"); continue; } // Import the records from the given file $this->importRecords($filename); } return $this; }
/** * Build an OR group that is added to the AND. * * @param QueryBuilder $qb * @param string $parentColumnName * @param array $options * * @return CompositeExpression */ protected function buildWhereOr(QueryBuilder $qb, $parentColumnName, array $options) { $orX = $qb->expr()->orX(); foreach ($options as $columnName => $option) { if (empty($options[$columnName])) { continue; } elseif (Arr::isIndexedArray($options)) { $key = $parentColumnName . '_' . $columnName; $orX->add("{$parentColumnName} = :{$key}"); $qb->setParameter($key, $option); } else { $orX->add("{$columnName} = :{$columnName}"); $qb->setParameter($columnName, $option); } } return $orX; }
/** * Parse a Contenttype's filed and determine the grouping * * @param array $fields * @param array $generalConfig * * @return array */ protected function parseFieldsAndGroups(array $fields, array $generalConfig) { $acceptableFileTypes = $generalConfig['accept_file_types']; $currentGroup = 'ungrouped'; $groups = []; $hasGroups = false; foreach ($fields as $key => $field) { unset($fields[$key]); $key = str_replace('-', '_', strtolower(Str::makeSafe($key, true))); // If field is a "file" type, make sure the 'extensions' are set, and it's an array. if ($field['type'] == 'file' || $field['type'] == 'filelist') { if (empty($field['extensions'])) { $field['extensions'] = $acceptableFileTypes; } $field['extensions'] = (array) $field['extensions']; } // If field is an "image" type, make sure the 'extensions' are set, and it's an array. if ($field['type'] == 'image' || $field['type'] == 'imagelist') { if (empty($field['extensions'])) { $field['extensions'] = array_intersect(['gif', 'jpg', 'jpeg', 'png'], $acceptableFileTypes); } $field['extensions'] = (array) $field['extensions']; } // Make indexed arrays into associative for select fields // e.g.: [ 'yes', 'no' ] => { 'yes': 'yes', 'no': 'no' } if ($field['type'] === 'select' && isset($field['values']) && is_array($field['values']) && Arr::isIndexedArray($field['values'])) { $field['values'] = array_combine($field['values'], $field['values']); } if (!empty($field['group'])) { $hasGroups = true; } // Make sure we have these keys and every field has a group set. $field = array_replace(['class' => '', 'default' => '', 'group' => $currentGroup, 'label' => '', 'variant' => ''], $field); // Collect group data for rendering. // Make sure that once you started with group all following have that group, too. $currentGroup = $field['group']; $groups[$currentGroup] = 1; $fields[$key] = $field; // Repeating fields checks if ($field['type'] === 'repeater') { $fields[$key] = $this->parseFieldRepeaters($fields, $key); if ($fields[$key] === null) { unset($fields[$key]); } } } // Make sure the 'uses' of the slug is an array. if (isset($fields['slug']) && isset($fields['slug']['uses'])) { $fields['slug']['uses'] = (array) $fields['slug']['uses']; } return [$fields, $hasGroups ? array_keys($groups) : []]; }
/** * Properly handle grouped taxonomy with ordering. * * @see https://github.com/bolt/bolt/issues/3908 * * @param Content $content * @param array $taxonomy * * @return array */ private function getIndexedTaxonomy($content, $taxonomy) { if (Arr::isIndexedArray($taxonomy)) { return $taxonomy; } $ret = array(); foreach ($taxonomy as $key) { if ($content->group !== null) { $ret[] = $content->group['slug'] . '#' . $content->group['order']; } else { $ret[] = $key; } } return $ret; }
/** * Build a GET query if required. * * @param array $redirect * @param array $formdata */ private function getRedirectQuery(array $redirect, $formdata) { $query = array(); if (Arr::isIndexedArray($redirect['query'])) { foreach ($redirect['query'] as $param) { $query[$param] = $this->getNormalisedData($formdata[$param]); } } else { $query = $redirect['query']; } return '?' . http_build_query($query); }
/** * Properly handle grouped taxonomy with ordering. * * @see https://github.com/bolt/bolt/issues/3908 * * @param Content $content * @param string $taxonomytype * @param array $taxonomy * * @return array */ private function getIndexedTaxonomy($content, $taxonomytype, $taxonomy) { $configTaxonomies = $this->app['config']->get('taxonomy'); if (Arr::isIndexedArray($taxonomy)) { return $taxonomy; } $ret = array(); foreach ($taxonomy as $key) { if ($configTaxonomies[$taxonomytype]['behaves_like'] == 'grouping' && $content->group !== null) { $ret[] = $content->group['slug'] . '#' . $content->group['order']; } else { $ret[] = $key; } } return $ret; }