standardize the datum format
@param array $data - return data fields
@param array $metaData - meta data
@return ['_data'=>[], '_meta'=[]]
962886
public static function getSuccessDatum($meta = [], $data = null, $html = false) {
        $defaultMeta = array(
            'result' => OperationResult::SUCCESS,
            'type' => OperationResult::getType(OperationResult::SUCCESS),
            'time' => date('Y-m-d H:i:s'),
            'message' => Yii::t('cza', 'Operation completed.')
        );
        
        if (isset($meta['message']) && is_array($meta['message'])) {
            $meta['message'] = self::formatMsg($meta['message']);
        }

        $result = array(
            '_data' => $data, '_meta' => array_merge($defaultMeta, $meta),
        );

        if ($html)
            $result['_meta']['message'] = '<div class=\'alert-box done\'><i class=\'fa-check-circle\'></i> ' . $result['_meta']['message'] . '</div>';
        return $result;
    }
129492
protected function prepareOptions(Metadata $metadata)
	{
		$options = array(
			'tags'  => array_merge_recursive($metadata->getTags(), array(
				'releaseStage' => $metadata->getStage(),
				'appVersion'   => $metadata->getAppVersion(),
			)),
			'extra' => array_merge_recursive($metadata->getMetadata(), array(
				'appRootDir'   => $metadata->getAppRootDir(),
				'releaseStage' => $metadata->getStage(),
				'appVersion'   => $metadata->getAppVersion(),
			)),
			'level' => self::$SEVERITY_MAP[$metadata->getSeverity()],
		);

		$groupingHash = $this->calculateGroupingHash($metadata);
		if ($groupingHash)
		{
			$options['checksum'] = $groupingHash;
		}

		return $options;
	}
458572
protected function parseMetadata(array $metadata): void
    {
        if (isset($metadata['arrayGroups'])) {
            foreach ($metadata['arrayGroups'] as $name => $values) {
                if (!isset($this->arrayGroups[$name])) {
                    $this->arrayGroups[$name] = array();
                }
                
                foreach ($values as $locale => $keyName) {
                    $this->arrayGroups[$name][$locale] = $keyName;
                }
            }
        }
    }
259400
protected function splitContentMeta($data)
    {
        // Remove Byte Order Mark (BOM)
        $data = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $data);

        // Pattern for detecting a metadata separator (---)
        // Using ^ and $ in this way requires the PCRE_MULTILINE modifier
        $pattern = '/' // Pattern start
            . '^'       // Beginning of line
            . '---'     // Literal ---
            . '\\s*'    // Zero or more whitespace characters
            . '$'       // End of line
            . '/m';     // Pattern end, PCRE_MULTILINE modifier

        // Separate the meta-data from the content
        $data = trim($data);

        if (
            (substr($data, 0, 3) === '---') &&
            (preg_match($pattern, $data, $matches, PREG_OFFSET_CAPTURE, 3))
        ) {
            $pos = $matches[0][1];
            $len = strlen($matches[0][0]);

            $meta = trim(substr($data, 3, $pos - 3));
            $content = trim(substr($data, $pos + $len));
        }
        else {
            $content = $data;
            $meta = null;
        }

        return [$content, $meta];
    }
1321773
public function merge(array $metadata): array
	{
		$tables = [];
		foreach ($metadata as $entity) {
			$tables[$entity->getTableName()][] = $entity;
		}

		$merged = [];
		foreach ($tables as $table => $metadata) {

			if (count($metadata) === 1) {
				$merged[] = array_shift($metadata);
				continue;
			}

			$primary = $this->resolvePrimaryMetadata($metadata);
			foreach ($metadata as $secondary) {
				$primary = $this->mergeMetadata($primary, $secondary);
			}

			$primary->fieldMappings = $this->mappingCleanup($primary->fieldMappings);
			$primary->associationMappings = $this->mappingCleanup($primary->associationMappings);
			$merged[] = $primary;
		}

		return $merged;
	}
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;
    }
1340779
public function validateMetadata(array $metadata = null)
    {
        if (!is_null($metadata)) {
            Validate::isArray($metadata, 'metadata');
        } else {
            $metadata = [];
        }

        foreach ($metadata as $key => $value) {
            Validate::isString($key, 'metadata key');
            Validate::isString($value, 'metadata value');
        }
    }
365120
public function formatToItems(string $data): array
    {
        $this->checkDependencies();

        $data = Yaml::parse($data);
        $header = $data['header'];
        unset($data['header']);
        $items = [];
        foreach ($data as $itemAsArray) {
            $items[] = Item::createFromArray(
                [
                    'uuid' => [
                        'id' => $itemAsArray['id'],
                        'type' => $itemAsArray['type'] ?? 'item',
                    ],
                    'suggest' => ($itemAsArray['suggest'] ?? []),
                    'exact_matching_metadata' => ($itemAsArray['exact_matching'] ?? []),
                    'coordinate' => ($itemAsArray['coordinate'] ?? null),
                ] +
                $this->parseFieldsFromHeaderAndItemAsArray(
                    $header,
                    $itemAsArray
                )
            );
        }

        return $items;
    }
706167
private function generateAttachmentFields(array $data): array
    {
        $fields = array();
        foreach ($this->normalizerFormatter->format($data) as $key => $value) {
            $fields[] = $this->generateAttachmentField($key, $value);
        }

        return $fields;
    }
113026
public function process(array $data)
    {
        $processedData = [
            'meta' => Hash::get($data, 'meta'),
            'data' => []
        ];
        $processedData['meta']['type'] = 'Module';
        $processedData['meta']['title'] = $this->name();
        unset($data['meta']);
        foreach ($data as $attr => $value) {
            $processedData['data'][$attr] = $value;
        }
        return $processedData;
    }
151746
private function normalizeTreeMetadata($metadata)
    {
        $result = [];

        if (is_array(current($metadata)) === false) {
            $metadata = [$metadata];
        }

        foreach ($metadata as $entry) {
            $this->setEntryName($entry);
            $this->setEntryType($entry);
            $this->setEntryVisibility($entry);

            $this->setDefaultValue($entry, self::KEY_CONTENTS);
            $this->setDefaultValue($entry, self::KEY_STREAM);
            $this->setDefaultValue($entry, self::KEY_TIMESTAMP);


            $result[] = $entry;
        }

        return $result;
    }
166208
public function normalizeFormData(array $data)
    {
        if (empty($data)) {
            return $data;
        }

        $renameMap = array_flip($this->renamemap);

        foreach ($renameMap as $customName => $defaultName) {
            if (array_key_exists($customName, $data)) {
                $value = $data[$customName];
                unset($data[$customName]);
                $data[$defaultName] = $value;
            }
        }

        return $data;
    }
605309
private function normalizeData($data)
    {
        $normalizedData = [];

        foreach ($data as $key => $value) {
            if ('#text' === $key) {
                $key = 'direction';
            }

            $normalizedData[trim($key, '_')] = $value;
        }

        return $normalizedData;
    }
955210
protected function _setData(array $data)
    {
        $pmk = $this->getPrimaryKey();
        if (!empty($data)) {
            if (!isset($data[$pmk]) && !is_null($this->$pmk)) {
                $data[$pmk] = $this->$pmk;
            }
            return $data;
        }
        $columns = Manager::getInstance()->get($this)->getColumns();
        foreach (array_keys($columns) as $property) {
            $key = trim($property, '_');
            if ($key == $pmk && !$this->$pmk) {
                continue;
            }
            $data[$key] = $this->$property;
        }

        return $data;
    }
474131
private function getFieldsFromEntityMetadata(ClassMetadataInfo $metadata)
    {
        $fields = (array) $metadata->fieldNames;

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

        return $fields;
    }
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;
    }
364382
private function sanitizeMetadata(array $metadata)
    {
        array_walk_recursive(
            $metadata,
            function ($value) {
                if (is_object($value) || is_resource($value)) {
                    throw new Exception('Metadata cannot contain objects or resources');
                }
            }
        );

        return $metadata;
    }