Format a DataObject keys and values
ready to be turned into JSON

@param  DataObject $dataObject The data object to format
@return array|null             The formatted array map representation of the DataObject or null
is permission denied
554565
protected function formatDataObject(DataObject $dataObject)
    {
        // api access control
        if (!RESTfulAPI::api_access_control($dataObject, 'GET')) {
            return null;
        }

        if (method_exists($dataObject, 'onBeforeSerialize')) {
            $dataObject->onBeforeSerialize();
        }
        $dataObject->extend('onBeforeSerialize');

        // setup
        $formattedDataObjectMap = array();

        // get DataObject config
        $class = get_class($dataObject);
        $db = Config::inst()->get($class, 'db');
        $has_one = Config::inst()->get($class, 'has_one');
        $has_many = Config::inst()->get($class, 'has_many');
        $many_many = Config::inst()->get($class, 'many_many');
        $belongs_many_many = Config::inst()->get($class, 'belongs_many_many');

        // Get a possibly defined list of "api_fields" for this DataObject. If defined, they will be the only fields
        // for this DataObject that will be returned, including related models.
        $apiFields = (array) Config::inst()->get($class, 'api_fields');

        //$many_many_extraFields = $dataObject->many_many_extraFields();
        $many_many_extraFields = $dataObject->stat('many_many_extraFields');

        // setup ID (not included in $db!!)
        $serializedColumnName = $this->serializeColumnName('ID');
        $formattedDataObjectMap[$serializedColumnName] = $dataObject->getField('ID');

        // iterate over simple DB fields
        if (!$db) {
            $db = array();
        }

        foreach ($db as $columnName => $fieldClassName) {
            // Check whether this field has been specified as allowed via api_fields
            if (!empty($apiFields) && !in_array($columnName, $apiFields)) {
                continue;
            }

            $serializedColumnName = $this->serializeColumnName($columnName);
            $formattedDataObjectMap[$serializedColumnName] = $dataObject->getField($columnName);
        }

        // iterate over has_one relations
        if (!$has_one) {
            $has_one = array();
        }
        foreach ($has_one as $columnName => $fieldClassName) {
            // Skip if api_fields is set for the parent, and this column is not in it
            if (!empty($apiFields) && !in_array($columnName, $apiFields)) {
                continue;
            }

            $serializedColumnName = $this->serializeColumnName($columnName);

            // convert foreign ID to integer
            $relationID = intVal($dataObject->{$columnName . 'ID'});
            // skip empty relations
            if ($relationID === 0) {
                continue;
            }

            // check if this should be embedded
            if ($this->isEmbeddable($dataObject->ClassName, $columnName)) {
                // get the relation's record ready to embed
                $embedData = $this->getEmbedData($dataObject, $columnName);
                // embed the data if any
                if ($embedData !== null) {
                    $formattedDataObjectMap[$serializedColumnName] = $embedData;
                }
            } else {
                // save foreign ID
                $formattedDataObjectMap[$serializedColumnName] = $relationID;
            }
        }

        // combine defined '_many' relations into 1 array
        $many_relations = array();
        if (is_array($has_many)) {
            $many_relations = array_merge($many_relations, $has_many);
        }
        if (is_array($many_many)) {
            $many_relations = array_merge($many_relations, $many_many);
        }
        if (is_array($belongs_many_many)) {
            $many_relations = array_merge($many_relations, $belongs_many_many);
        }

        // iterate '_many' relations
        foreach ($many_relations as $relationName => $relationClassname) {
            // Skip if api_fields is set for the parent, and this column is not in it
            if (!empty($apiFields) && !in_array($relationName, $apiFields)) {
                continue;
            }

            //get the DataList for this realtion's name
            $dataList = $dataObject->{$relationName}();

            //if there actually are objects in the relation
            if ($dataList->count()) {
                // check if this relation should be embedded
                if ($this->isEmbeddable($dataObject->ClassName, $relationName)) {
                    // get the relation's record(s) ready to embed
                    $embedData = $this->getEmbedData($dataObject, $relationName);
                    // embed the data if any
                    if ($embedData !== null) {
                        $serializedColumnName = $this->serializeColumnName($relationName);
                        $formattedDataObjectMap[$serializedColumnName] = $embedData;
                    }
                } else {
                    // set column value to ID list
                    $idList = $dataList->map('ID', 'ID')->keys();

                    $serializedColumnName = $this->serializeColumnName($relationName);
                    $formattedDataObjectMap[$serializedColumnName] = $idList;
                }
            }
        }

        if ($many_many_extraFields) {
            $extraFieldsData = array();

            // loop through extra fields config
            foreach ($many_many_extraFields as $relation => $fields) {
                $manyManyDataObjects = $dataObject->$relation();
                $relationData = array();

                // get the extra data for each object in the relation
                foreach ($manyManyDataObjects as $manyManyDataObject) {
                    $data = $manyManyDataObjects->getExtraData($relation, $manyManyDataObject->ID);

                    // format data
                    foreach ($data as $key => $value) {
                        // clear empty data
                        if (!$value) {
                            unset($data[$key]);
                            continue;
                        }

                        $newKey = $this->serializeColumnName($key);
                        if ($newKey != $key) {
                            unset($data[$key]);
                            $data[$newKey] = $value;
                        }
                    }

                    // store if there is any real data
                    if ($data) {
                        $relationData[$manyManyDataObject->ID] = $data;
                    }
                }

                // add individual DO extra data to the relation's extra data
                if ($relationData) {
                    $key = $this->serializeColumnName($relation);
                    $extraFieldsData[$key] = $relationData;
                }
            }

            // save the extrafields data
            if ($extraFieldsData) {
                $key = $this->serializeColumnName('ManyManyExtraFields');
                $formattedDataObjectMap[$key] = $extraFieldsData;
            }
        }

        if (method_exists($dataObject, 'onAfterSerialize')) {
            $dataObject->onAfterSerialize($formattedDataObjectMap);
        }
        $dataObject->extend('onAfterSerialize', $formattedDataObjectMap);

        return $formattedDataObjectMap;
    }
340707
public function getUnmappedArray(DataObject $object)
    {
        $output = [];

        foreach ($this->mapping as $unmappedField => $mappedField) {
            if (strpos($mappedField, ':') !== false) {
                list($mappedField, $modifier) = explode(':', $mappedField);
            }

            $output[$unmappedField] = $object->{$mappedField};
        }

        return $output;
    }
246905
public static function serialize($object)
	{
		if (is_array($object)) {
			$result = [];
			foreach ($object as $record) {
				$result[] = $record->toArray();
				$record = null;
			}
			$object = null;
			return $result;
		} else {
			return $object != null ? $object->toArray() : null;
		}
	}
692783
public function create(GeneratorDataObject $dataObject)
    {
        $dto = $dataObject->getDto();

        if (null === $dto) {
            throw new \InvalidArgumentException('DTO cant be empty');
        }

        $metadata = $dto->getMetaData();

        if (null === $metadata) {
            throw new \InvalidArgumentException('Metadata cant be empty');
        }

        $fileName = $metadata->getName() . self::FILE_EXTENSION;

        if ($this->fileManager->isFile(Installer::BASE_PATH . self::HISTORY_PATH . $fileName) === true) {
            $this->fileManager->unlink(Installer::BASE_PATH . self::HISTORY_PATH . $fileName);
        }

        $this->fileManager->filePutsContent(
            Installer::BASE_PATH . self::HISTORY_PATH . $fileName,
            $this->historyHydrator->dtoToJson($dataObject)
        );
    }
36532
public function handleStorage($fieldObject)
    {
        $type = $fieldObject->getStorageType();
        $typeName = $type->getName();
        if ($typeName === 'json') {
            /** @deprecated since 3.3 to be renamed in v4. */
            $typeName = 'json_array';
        }
        $typeCol = 'value_' . $typeName;
        $this->$typeCol = $this->getValue();
    }
257323
public function loadJSONObject($jsonObject)
    {
        foreach ($jsonObject as $key => $values) {
            switch ($key) {
                case 'psr-4':
                    foreach ($values as $namespace => $path) {
                        $this->addPsr4($namespace, $path);
                    }
                    break;
                case 'psr-0':
                    foreach ($values as $namespace => $path) {
                        $this->addPsr0($namespace, $path);
                    }
                    break;
                case 'classmap':
                    foreach ($values as $path) {
                        $this->addClassmap($path);
                    }
                    break;
                case 'exclude-from-classmap':
                    foreach ($values as $path) {
                        $this->addExcludeFromClassmap($path);
                    }
                    break;
                case 'files':
                    foreach ($values as $path) {
                        $this->addFile($path);
                    }
                    break;
            }
        }

        return $this;
    }
467682
function formatObject(o) {
		var s = String(o);
		if(s === '[object Object]' && typeof JSON !== 'undefined') {
			s = tryStringify(o, s);
		}
		return s;
	}
341926
public function getPropertyValuesArray($object)
    {
        $values = [];
        foreach ($this->entityPropertiesMetadata as $entityPropertyMetadata) {
            $v = $entityPropertyMetadata->getValue($object);
            if (is_object($v)) {
                switch (get_class($v)) {
                    case \DateTime::class:
                        $v = $v->getTimestamp();
                        break;
                }
            }
            $values[$entityPropertyMetadata->getPropertyName()] = $v;
        }

        return $values;
    }
599551
public function convertDataObject(DataObjectInterface $obj, $fields = null)
    {
        $response = Controller::curr()->getResponse();
        if ($response) {
            $response->addHeader("Content-Type", "text/xml");
        }

        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $this->convertDataObjectWithoutHeader($obj, $fields);
    }
284773
public static function populateResponseData(IResponse $response, &$dataObject): void
    {
        foreach (array_keys($response->data()) as $key) {
            $method = 'set';
            $method .= ucfirst(Str::camel($key));
            if (!method_exists($dataObject, $method)) {
                continue;
            }

            $dataObject->{$method}($response->{$key});
        }
    }
569832
public function publishObject(DataObject $object)
    {
        // Detect Versioned Extension:
        
        if ($object->hasExtension(Versioned::class)) {
            
            // Copy Draft to Live:
            
            $object->copyVersionToStage(
                Versioned::DRAFT,
                Versioned::LIVE
            );
            
            // Clear Cache:
            
            $object->flushCache();
            
        }
        
        // Answer Object:
        
        return $object;
    }
302110
protected function objectToFields($dataObject) {
		$ret = array();

		$fields = Config::inst()->get($dataObject->ClassName, 'db');
		$fields['Created'] = 'SS_Datetime';
		$fields['LastEdited'] = 'SS_Datetime';

		$ret['ClassName'] = array('Type' => 'Varchar', 'Value' => $dataObject->class);
		$ret['SS_ID'] = array('Type' => 'Int', 'Value' => $dataObject->ID);

		foreach ($fields as $name => $type) {
			if (preg_match('/^(\w+)\(/', $type, $match)) {
				$type = $match[1];
			}

			// Just index everything; the query can figure out what to exclude... !
			$value = $dataObject->$name;

			if ($type == 'MultiValueField' && $value instanceof MultiValueField) {
				$value = $value->getValues();
			}

			$ret[$name] = array('Type' => $type, 'Value' => $value);
		}

		$rels = Config::inst()->get($dataObject->ClassName, 'has_one');

		if($rels) foreach(array_keys($rels) as $rel) {
			$ret["{$rel}ID"] = array(
				'Type'  => 'ForeignKey',
				'Value' => $dataObject->{$rel . "ID"}
			);
		}
		
		if ($dataObject->hasMethod('additionalSolrValues')) {
			$extras = $dataObject->invokeWithExtensions('additionalSolrValues');
			if ($extras && is_array($extras)) {
				foreach ($extras as $add) {
					foreach ($add as $k => $v) {
						$ret[$k] = array(
							'Type'		=> $this->mapper->mapValueToType($k, $v),
							'Value'		=> $v,
						);
					}
				}
			}
		}

		return $ret;
	}
802076
protected function formatObject($oObject, $aUrls = [])
    {
        return (object) [
            'id'       => $oObject->id,
            'object'   => (object) [
                'name' => $oObject->file->name->human,
                'mime' => $oObject->file->mime,
                'size' => $oObject->file->size,
            ],
            'bucket'   => $oObject->bucket,
            'is_img'   => $oObject->is_img,
            'img'      => (object) [
                'width'       => $oObject->img_width,
                'height'      => $oObject->img_height,
                'orientation' => $oObject->img_orientation,
                'is_animated' => $oObject->is_animated,
            ],
            'created'  => $oObject->created,
            'modified' => $oObject->modified,
            'url'      => (object) $this->generateUrls($oObject, $aUrls),
        ];
    }
777356
protected function formatAble(&$object)
    {
        if (!is_object($object) || is_array($object)) {
            throw new InvalidArgumentException('The given argument is not an object/array.');
        }

        if (!is_object($object) && $object instanceof FormatAble) {
            return;
        }

        $object = new FormatAbleObject(clone($object));
    }
663614
public function read_array($returnObject = false)
    {
        $this->bitcount = $this->bits = 0;

        // Determine array length and its end position
        $arrayLength = $this->read_php_int();
        $endOffset = $this->offset + $arrayLength;

        $result = $returnObject ? new AMQPArray() : array();

        // Read values until we reach the end of the array
        while ($this->offset < $endOffset) {
            $fieldType = AMQPAbstractCollection::getDataTypeForSymbol($this->rawread(1));
            $fieldValue = $this->read_value($fieldType, $returnObject);
            $returnObject ? $result->push($fieldValue, $fieldType) : $result[] = $fieldValue;
        }

        return $result;
    }
961074
public function values(Interfaces\JavaObject $javaObject)
    {
        try {
            return $this->pjbProxyClient->getValues($javaObject);
        } catch (Pjb62BrokenConnectionException | Exception\InvalidUsageException $e) {
            PjbProxyClient::unregisterInstance();
            throw new BrokenConnectionException($e->getMessage(), $e->getCode(), $e);
        }
    }
1084675
public function getData(bool $asObject = false)
    {
        $data = $this->data['data'] ?? $this->data;
        return $asObject && $data !== null ? (object) $data : $data;
    }