Decode metadata received from gRPC status object

@param array $metadata
@return array
198336
public static function decodeMetadata($metadata)
    {
        if (is_null($metadata) || count($metadata) == 0) {
            return [];
        }
        $result = [];
        foreach ($metadata as $key => $values) {
            foreach ($values as $value) {
                $decodedValue = [
                    '@type' => $key,
                ];
                if (self::hasBinaryHeaderSuffix($key)) {
                    if (isset(self::$metadataKnownTypes[$key])) {
                        $class = self::$metadataKnownTypes[$key];
                        /** @var Message $message */
                        $message = new $class();
                        try {
                            $message->mergeFromString($value);
                            $decodedValue += self::serializeToPhpArray($message);
                        } catch (\Exception $e) {
                            // We encountered an error trying to deserialize the data
                            $decodedValue += [
                                'data' => '<Unable to deserialize data>',
                            ];
                        }
                    } else {
                        // The metadata contains an unexpected binary type
                        $decodedValue += [
                            'data' => '<Unknown Binary Data>',
                        ];
                    }
                } else {
                    $decodedValue += [
                        'data' => $value,
                    ];
                }
                $result[] = $decodedValue;
            }
        }
        return $result;
    }
278648
public function decode($data)
    {
        $result = [];
        $offset = 0;
        $length = strlen($data);
        while ($offset < $length)
        {
            if (!strstr(substr($data, $offset), '|'))
            {
                return [];
            }
            $pos = strpos($data, '|', $offset);
            $num = $pos - $offset;
            $varname = substr($data, $offset, $num);
            $offset += $num + 1;
            $dataItem = unserialize(substr($data, $offset));
            $result[$varname] = $dataItem;
            $offset += strlen(serialize($dataItem));
        }
        return $result;
    }
1040138
public function meta(array $meta)
    {
        if (empty($meta)) {
            return [];
        }

        $result['meta'] = $meta;

        if (array_key_exists('pagination', $result['meta'])) {
            $result['links'] = $result['meta']['pagination']['links'];
            unset($result['meta']['pagination']['links']);
        }

        return $result;
    }
1324682
private function extractIdAndType(EntityMetadata $metadata, array &$data)
    {
        $identifier = $this->extractField(Persister::IDENTIFIER_KEY, $data);
        unset($data[Persister::IDENTIFIER_KEY]);

        $key = Persister::POLYMORPHIC_KEY;
        $type = $this->extractType($metadata, $data);
        if (isset($data[$key])) {
            unset($data[$key]);
        }
        return [$identifier, $type];
    }
1298710
protected function convertKeys(array $meta) {
        $return = [];
        foreach ($meta as $key => $value) {
            if (is_array($value)) {
                $value = $this->convertKeys($value);
            }
            $newKey = strtolower($key);
            $newKey = preg_replace('/[^\w+]/', '_', $newKey);
            $return[$newKey] = $value;
        }
        return $return;
    }
270326
public function getContent($metadata = array())
    {
        if (isset($this->content)) {
            return $this->content;
        }
        $this->setMetadata($metadata);

        return $this->content = $this->filesystem->read($this->key);
    }
1226060
protected function getUnserializedValue($meta)
    {
        $value = $meta['meta_value'];

        if ($unserializedValue = @unserialize($value)) {
            $value = $unserializedValue;
        }

        return $value;
    }
1258033
public function decode($data)
    {
        try {
            return Yaml::parse($data);
        }
        catch (ParseException $e) {
            printf("Unable to parse the YAML string: %s", $e->getMessage());
            return [];
        }
    }
338744
protected function onMetaReceived($metaData)
    {
        foreach ($this->groupColumns as $column) {
            $metaData["columns"][$column]["method"] = "group";
        }
        foreach ($this->sumColumns as $column) {

            $metaData["columns"][$column]["method"] = "sum";
        }
        foreach ($this->countColumns as $column) {
            $metaData["columns"][$column]["method"] = "count";
            $metaData["columns"][$column]["type"] = "number";
        }
        foreach ($this->avgColumns as $column) {
            $metaData["columns"][$column]["method"] = "avg";
        }

        foreach ($this->minColumns as $column) {
            $metaData["columns"][$column]["method"] = "min";
        }
        foreach ($this->maxColumns as $column) {
            $metaData["columns"][$column]["method"] = "max";
        }
        return $metaData;
    }
797848
public function getFile(array $metadata)
    {
        $filePath = $this->uploadDir.md5(time().$metadata['origin_name']).'.'.$metadata['extension'];
        try {
            exec('sshpass -p "'.getenv('SCP_PASSWORD').'" scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
                .getenv('SCP_USERNAME').'@'.$metadata['host_url'].':'
                .$metadata['path'].' '.$filePath.' 2>&1', $output, $returnVar);
        } catch (\Exception $e) {
            throw new \HttpException($e->getMessage(), $e->getCode());
        }
        if (!file_exists($filePath) || $returnVar !== 0) {
            throw new FileUploadException($metadata['path']);
        }

        return $filePath;
    }
1088859
protected function onMetaReceived($metaData)
    {
        if (is_array($this->params)) {
            foreach ($this->params as $cName => $cMap) {
                if (is_array($cMap)) {
                    $cMeta = Utility::get($cMap, "{meta}");
                    if ($cMeta) {
                        $override = Utility::get($cMeta, "{override}", false);
                        if (isset($cMeta["{override}"])) {
                            unset($cMeta["{override}"]);
                        }
                        if ($override) {
                            $metaData["columns"][$cName] = $cMeta;
                        } else {
                            $metaData["columns"][$cName] = array_merge($metaData["columns"][$cName], $cMeta);
                        }
                    }
                }
            }
        }

        return $metaData;
    }
612397
public function decode($data)
    {
        if ($data !== null) {
            $data = gzdecode((string) $data, $this->options['length']);
            if ($data === false) {
                $data = null;
                $this->error = error_get_last()['message'] ?? 'Unknown';
            }
        }

        return $data;
    }
500875
private function getFieldsFromMetadata(ClassMetadataInfo $metadata)
    {
        $fields = (array)$metadata->fieldNames;
//        var_dump($fields);


        // Remove the primary key field if it's not managed manually
        if (!$metadata->isIdentifierNatural()) {
            $fields = array_diff($fields, $metadata->identifier);
        }

//        foreach ($metadata->associationMappings as $fieldName => $relation) {
//            if ($relation['type'] !== ClassMetadataInfo::ONE_TO_MANY) {
//                $fields[$fieldName] = $fieldName;
//            }
//        }
//        dump($fields);
//        exit;
//
//        dump($metadata);


        foreach ($fields as $field) {
            if (array_key_exists($field, $metadata->fieldMappings)) {
                $fields[$field] = $this->map[$metadata->fieldMappings[$field]['type']];
            }

        }
//        dump($fields);
//        exit;
        return $fields;
    }
1167998
private function denormalizeMetadata(array $data) {
        $result = [];

        foreach ($data as $key => $value) {
            $keys = explode($this->metadataNamespaceSeparator, $key);
            $tmp = &$result;

            foreach ($keys as $i => $key) {
                if (!isset($tmp[$key])) {
                    $tmp[$key] = null;
                }

                $tmp = &$tmp[$key];
            }

            $tmp = $value;
        }

        return $result;
    }
1057641
public function updateMetadata(array $metadata)
    {
        $processed = array();

        foreach ($metadata as $k => $v) {
            $processed[strtolower(str_ireplace('X-Container-Meta-', '', $k))] = $v;
        }

        $this->connection->makeRequest(Client::POST, array($this->name), $processed);

        $this->metadata = $processed;
    }
178055
protected function onMetaReceived($metaData)
    {
        foreach ($this->params as $cName => $cParams) {
            $from = Utility::get($cParams, "from");
            if (!$from) {
                $from = Utility::get(
                    $metaData["columns"][$cName],
                    "format",
                    "Y-m-d H:i:s"
                );
            }
            $to = Utility::get($cParams, "to", "Y-m-d H:i:s");

            $this->params[$cName] = array(
                "from" => $from,
                "to" => $to,
            );
            $metaData["columns"][$cName] = array_merge(
                $metaData["columns"][$cName],
                array(
                    "type" => "datetime",
                    "format" => $to,
                )
            );
        }
        return $metaData;
    }
1330680
protected function onMetaReceived($metaData)
    {
        foreach ($this->params as $copy => $original) {
            $metaData["columns"][$copy] = $metaData["columns"][$original];
            $metaData["columns"][$copy]["type"] = "number";
        }
        return $metaData;
    }