Format the sync list so that it is keyed by ID.

@param  array  $records
@return array
187427
protected function formatSyncList(array $records)
    {
        $results = array();

        foreach ($records as $id => $attributes)
        {
            if ( ! is_array($attributes))
            {
                list($id, $attributes) = array($attributes, array());
            }

            $results[$id] = $attributes;
        }

        return $results;
    }
1213295
private function excludeFields(array $record): array
    {
        foreach ($this->excludeFields as $field) {
            $keys = explode('.', $field);
            $node = &$record;
            $lastKey = end($keys);
            foreach ($keys as $key) {
                if (!isset($node[$key])) {
                    break;
                }
                if ($lastKey === $key) {
                    unset($node[$key]);
                    break;
                }
                $node = &$node[$key];
            }
        }

        return $record;
    }
135314
public function transformRecords($records)
    {
        if (method_exists($this->class, 'laratablesModifyCollection')) {
            $records = $this->class::laratablesModifyCollection($records)->values();
        }

        return $records->map(function ($item) {
            return $this->transformRecord($item);
        });
    }
920255
public function groupRecords($records)
    {
        if (!is_array($records) || empty($records)) {
            return;
        }

        $groups = array($this->get('element_name') => array());

        foreach ($records as $r) {
            $data = $r->getData($this->get('id'));
            $author_id = !isset($data['author_id']) ? 0 : $data['author_id'];

            if (!isset($groups[$this->get('element_name')][$author_id])) {
                $author = AuthorManager::fetchByID($author_id);
                // If there is an author, use those values, otherwise just blank it.
                if ($author instanceof Author) {
                    $username = $author->get('username');
                    $full_name = $author->getFullName();
                } else {
                    $username = '';
                    $full_name = '';
                }

                $groups[$this->get('element_name')][$author_id] = array(
                    'attr' => array('author-id' => $author_id, 'username' => $username, 'full-name' => $full_name),
                    'records' => array(),
                    'groups' => array()
                );
            }

            $groups[$this->get('element_name')][$author_id]['records'][] = $r;
        }

        return $groups;
    }
791222
public function format(array $record)
    {
        $jsonString = json_encode($this->getOutputRecord($record));

        if ($jsonString === false) {
            throw new \RuntimeException('Error happened during the log format process! (json encode error)');
        }

        return $jsonString . PHP_EOL;
    }
205621
public static function withKeys($records, $keys)
    {
        if (!self::iterable($records)) {
            return array();
        }
        
        $out = array();
        foreach ($records as $n => $record) {
            if (!self::iterable($record)) {
                $out[$n] = $record;
                continue;
            }
            $out[$n] = array();
            
            foreach ($record as $k => $v) {
                if (!in_array($k, $keys)) {
                    continue;
                }
                $out[$n][$k] = $v;
            }
        }
        return $out;
    }
67892
public function sync($ids, $detaching = true)
    {
        $changes = [
            'attached' => [],
            'detached' => [],
            'updated'  => [],
        ];

        $pk = $this->parent->getPk();

        $current = $this->pivot
            ->where($this->localKey, $this->parent->$pk)
            ->column($this->foreignKey);

        $records = [];

        foreach ($ids as $key => $value) {
            if (!is_array($value)) {
                $records[$value] = [];
            } else {
                $records[$key] = $value;
            }
        }

        $detach = array_diff($current, array_keys($records));

        if ($detaching && count($detach) > 0) {
            $this->detach($detach);
            $changes['detached'] = $detach;
        }

        foreach ($records as $id => $attributes) {
            if (!in_array($id, $current)) {
                $this->attach($id, $attributes);
                $changes['attached'][] = $id;
            } elseif (count($attributes) > 0 && $this->attach($id, $attributes)) {
                $changes['updated'][] = $id;
            }
        }

        return $changes;
    }
378409
public function saveRecords(array $records, DataDimensions $dataDimensions = null)
    {
        if (count($records) > 0)
        {
            $record          = reset($records);
            $contentTypeName = $record->getContentTypeName();

            if (!$dataDimensions)
            {
                $dataDimensions = $this->getCurrentDataDimensions();
            }

            $recordIds  = [ ];
            $allRecords = $this->getAllRecords($contentTypeName, $dataDimensions);

            foreach ($records as $record)
            {
                $record = $this->finalizeRecord($record, $dataDimensions);

                if ($record->getID() == '')
                {
                    $nextId = 1;
                    if (count($allRecords) > 0)
                    {

                        $nextId = max(array_keys($allRecords)) + 1;
                    }
                    $record->setID($nextId);
                    $record->setRevision(0);
                }

                $mergedRecord = $this->mergeExistingRecord($record, $dataDimensions);

                $mergedRecord->setRevision($mergedRecord->getRevision() + 1);
                $record->setRevision($mergedRecord->getRevision());
                $mergedRecord->setLastChangeUserInfo($this->userInfo);
                $record->setLastChangeUserInfo($this->userInfo);

                $allRecords[$mergedRecord->getID()] = $mergedRecord;
                $recordIds[]                        = $mergedRecord->getID();
            }

            $data = json_encode([ 'records' => $allRecords ], JSON_PRETTY_PRINT);

            if ($this->writeData($this->getConfiguration()->getUriRecords($contentTypeName), $data))
            {
                $this->stashAllRecords($allRecords, $dataDimensions);

                return $recordIds;

            }
            throw new AnyContentClientException('Error when saving records of content type ' . $this->getCurrentContentTypeName());
        }

        return [ ];
    }
777342
public function transformRecordsToObjects($records)
    {
        if ($this->recordClass) {
            $recordClass = $this->recordClass;
            foreach ($records as &$record) {
                $record = (new $recordClass($record));
            }
        }

        return $records;
    }
1003474
protected function processSearchResults($records)
    {
        $results = [];
        foreach ($records as $record) {
            foreach ($record as $attribute => $value) {
                // if the value is an array with a single value, e.g. 'samaccountname' => array(0 => 'myusername')
                // then make sure it's just set in the results as 'samaccountname' => 'myusername' so that it
                // can be used directly by ArrayData
                if (is_array($value) && count($value) == 1) {
                    $value = $value[0];
                }

                // ObjectGUID and ObjectSID attributes are in binary, we need to convert those to strings
                if ($attribute == 'objectguid') {
                    $value = LDAPUtil::bin_to_str_guid($value);
                }
                if ($attribute == 'objectsid') {
                    $value = LDAPUtil::bin_to_str_sid($value);
                }

                $record[$attribute] = $value;
            }

            $results[] = $record;
        }

        return $results;
    }
373412
public function format(array $record): string
    {
        if (!empty($this->hostname)) {
            $record["hostname"] = $this->hostname;
        }
        if (!empty($this->appname)) {
            $record["appname"] = $this->appname;
        }

        $record["@marker"] = static::MARKERS;

        return parent::format($record);
    }
511406
public function format(array $record)
    {
        $formattedRecord = $this->formatter->format($record);

        if (is_array($formattedRecord)) {
            list($channel, $message, $backtrace, $loglevel) = $formattedRecord;

            return [
                $channel,
                $this->formatterPrefix . $message,
                $backtrace,
                $loglevel,
            ];
        }

        return $this->formatterPrefix . $formattedRecord;
    }
429042
public function format(array $record): string
    {
        $normalized = $this->normalize($record);
        if (isset($normalized['context']) && $normalized['context'] === []) {
            $normalized['context'] = new \stdClass;
        }
        if (isset($normalized['extra']) && $normalized['extra'] === []) {
            $normalized['extra'] = new \stdClass;
        }

        return $this->toJson($normalized, true) . ($this->appendNewline ? "\n" : '');
    }
1318143
def format_references(references)
      return {record_references: references, id_references: []} if references.is_a?(Array)

      references[:record_references] ||= []
      references[:id_references] ||= []
      references
    end
851619
private function formatContext(array $record)
    {
        $context = $this->filterVariablesUsedAsPlaceholders($record['message'], $record['context']);
        $context = $this->formatDateTimeObjects($context);
        $context = $this->formatThrowableObjects($context);

        $contextAsString = Yaml::dump($context, $this->getInlineLevel($record), $this->prefixLength, Yaml::DUMP_OBJECT);

        if (substr($contextAsString, strpos($contextAsString, self::PHP_SERIALIZED_OBJECT_PREFIX), strlen(self::PHP_SERIALIZED_OBJECT_PREFIX)) === self::PHP_SERIALIZED_OBJECT_PREFIX) {
            $contextAsString = $this->formatSerializedObject($contextAsString);
        }

        $contextAsString = $this->formatTextBlock($contextAsString, '--> ');
        $contextAsString = rtrim($contextAsString, PHP_EOL);

        return $contextAsString;
    }
818331
public function groupRecords($records)
    {
        if (!is_array($records) || empty($records)) {
            return;
        }

        $groups = array($this->get('element_name') => array());

        foreach ($records as $r) {
            $data = $r->getData($this->get('id'));
            $value = General::sanitize($data['value']);

            if (!isset($groups[$this->get('element_name')][$data['handle']])) {
                $groups[$this->get('element_name')][$data['handle']] = array(
                    'attr' => array('handle' => $data['handle'], 'value' => $value),
                    'records' => array(),
                    'groups' => array()
                );
            }

            $groups[$this->get('element_name')][$data['handle']]['records'][] = $r;
        }

        return $groups;
    }
1336071
public function getLocalizableForeignKeys(Record $record)
    {
        return [
            $this->localizableLocaleField => $this->localizableLocale->getCode(),
            $this->primary                => $record->{$this->primary},
        ];
    }