Normalize a Dropbox File Response.

@param object $obj

@return array
557189
protected function normalizeResponse($obj) {
        $result = ['path' => ltrim($this->removePathPrefix($obj->getPathDisplay()), '/')];

        $objClass = get_class($obj);
        switch ($objClass) {
            case 'Kunnu\Dropbox\Models\FolderMetadata':
                $result['type'] = 'dir';
                break;
            
            case 'Kunnu\Dropbox\Models\FileMetadata':
            default:
                $result['type'] = 'file';
                $result['size'] = $obj->getSize();
                $result['mimetype'] = MimeType::detectByFilename($obj->getName());
                $result['timestamp'] = strtotime($obj->getServerModified());
                break;
        }
        return $result;
    }
989686
function normalize(obj) {
  if (obj === null || typeof obj !== 'object') {
    return JSON.stringify(obj);
  }
  if (obj instanceof Array) {
    return '[' + obj.map(normalize).join(', ') + ']';
  }
  var answer = '{';
  for (var key of Object.keys(obj).sort()) {
    answer += key + ': ';
    answer += normalize(obj[key]);
    answer += ', ';
  }
  answer += '}';
  return answer;
}
1326077
public function formatObject($oObj)
    {
        return [
            'id'         => $oObj->id,
            'first_name' => $oObj->first_name,
            'last_name'  => $oObj->last_name,
            'email'      => $oObj->email,
        ];
    }
156928
public static function validateoperation(&$obj){
		$rules    = $obj->rules;
		$data     = array();
		foreach($rules as $key=>$val){
			$data[$key] = $obj->$key;
		}
		$validator = Validator::make($data,$rules);
		return $validator;
	}
349394
function init($obj)
	{
		static $is_loaded = false;
		if($is_loaded)
			return;

		if(!file_exists($obj->file_name()))
			return;

		$delimiter = $obj->get('delimiter', ',');

		$fh = fopen($obj->file_name(), 'rt');
		if($obj->first_line_header())
			$fields = fgetcsv($fh, 0, $delimiter);
		else
			$fields = $obj->fields();

		while($row = fgetcsv($fh, 0, $delimiter))
		{
			$x = array();
			foreach($fields as $id => $title)
				$x[$title] = $row[$id];
			$this->data[] = $x;
		}
		fclose($fh);

		$is_loaded = true;
	}
84246
public function exportToObj($obj) {
		foreach($this->properties as $k=>$v) {
			if (!is_array($v) && !is_object($v))
			$obj->$k = $v;
		}
	}
1033940
function normalizeOptions(obj) {
  for (var key in obj) {
    if (utils.optsKeys.indexOf(key) > -1) {
      obj.options = obj.options || {};
      obj.options[key] = obj[key];
      delete obj[key];
    }
  }
  return obj;
}
586844
public function equals($obj)
    {
        if ($obj instanceof QtiFile) {
            if ($this->getFilename() !== $obj->getFilename()) {
                return false;
            } elseif ($this->getMimeType() !== $obj->getMimeType()) {
                return false;
            } else {
                // We have to check the content of the file.
                $myStream = $this->getStream();
                $objStream = $obj->getStream();

                while (feof($myStream) === false && feof($objStream) === false) {
                    $myChunk = fread($myStream, self::CHUNK_SIZE);
                    $objChjunk = fread($objStream, self::CHUNK_SIZE);

                    if ($myChunk !== $objChjunk) {
                        @fclose($myStream);
                        @fclose($objStream);

                        return false;
                    }
                }

                @fclose($myStream);
                @fclose($objStream);

                return true;
            }
        }

        return false;
    }
897924
public static function ddp($obj = NULL)
	{
		try
		{
			$json_str = json_encode($obj, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
			echo $json_str;
			die();
		}
		catch(SangriaException $e)
		{
			/**
			 * Default to dd if there is an exception while encoding to JSON
			 */
			var_dump($obj);
			die();	
		}
	}
1136107
protected function getBlobMeta($obj)
    {
        $date = $obj->uploadDate->toDateTime();
        $return = [
            'oid'            => (string)$obj->_id,
            'name'           => $obj->filename,
            'content_type'   => (isset($obj->contentType)) ? $obj->contentType : '',
            'content_length' => $obj->length,
            'last_modified'  => $date->format(\DateTime::ATOM),
            'path'           => $obj->filename,
        ];

        return $return;
    }
953288
protected function objectToArray($obj) : array
    {
        if ($obj instanceof \stdClass) {
            $obj = json_decode(json_encode($obj), true);
        }

        return (array)$obj;
    }
922393
public function objectToDom($obj)
    {
        $doc = new DomDocument('1.0', 'utf-8');

        foreach ($obj as $k => &$v) {
            $node = $this->objectToDomElement($v, $doc->createElement($k), $doc);
            break;
        }

        $doc->appendChild($node);

        return $doc;
    }
1260397
public function normalize($object, $format = null, array $context = [])
    {
        $normalized = [
            'developer' => [],
        ];
        /** @var \Apigee\Edge\Api\Management\Structure\CompanyMembership $object */
        foreach ($object->getMembers() as $member => $role) {
            $normalized['developer'][] = (object) ['email' => $member, 'role' => $role];
        }

        return (object) $normalized;
    }
936312
protected function getPackageVersions($obj)
    {
        $result = [];
        if ($obj instanceof PackageVersionEntity) {
            $result[] = $obj;
        } elseif (is_array($obj)) {
            $app = Application::getFacadeApplication();
            if (isset($obj['handle']) && isset($obj['version'])) {
                $pv = $app->make(PackageVersionRepository::class)->findByHandleAndVersion(
                    $obj['handle'],
                    $obj['version']
                );
                if ($pv === null) {
                    throw new UserMessageException(t('Invalid translated package specified'));
                }
                $result[] = $pv;
            } elseif (isset($obj[0]) && is_string($obj[1]) && isset($obj[1]) && is_string($obj[1])) {
                $pv = $app->make(PackageVersionRepository::class)->findByHandleAndVersion(
                    $obj[0],
                    $obj[1]
                );
                if ($pv === null) {
                    throw new UserMessageException(t('Invalid translated package specified'));
                }
                $result[] = $pv;
            } else {
                foreach ($obj as $item) {
                    $result = array_merge($result, $this->getPackageVersions($item));
                }
            }
        }
        if (empty($result)) {
            throw new UserMessageException(t('Invalid translated package specified'));
        }

        return $result;
    }
567940
protected function formatObject(&$oObj)
    {
        $oObj->id          = (int) $oObj->id;
        $oObj->img_width   = (int) $oObj->img_width;
        $oObj->img_height  = (int) $oObj->img_height;
        $oObj->is_animated = (bool) $oObj->is_animated;
        $oObj->serves      = (int) $oObj->serves;
        $oObj->downloads   = (int) $oObj->downloads;
        $oObj->thumbs      = (int) $oObj->thumbs;
        $oObj->scales      = (int) $oObj->scales;
        $oObj->modified_by = (int) $oObj->modified_by ?: null;

        // --------------------------------------------------------------------------

        $sFileNameDisk  = $oObj->filename;
        $sFileNameHuman = $oObj->filename_display;
        $iFileSize      = (int) $oObj->filesize;

        $oObj->file = (object) [
            'name' => (object) [
                'disk'  => $sFileNameDisk,
                'human' => $sFileNameHuman,
            ],
            'mime' => $oObj->mime,
            'ext'  => strtolower(pathinfo($sFileNameDisk, PATHINFO_EXTENSION)),
            'size' => (object) [
                'bytes'     => $iFileSize,
                'kilobytes' => round($iFileSize / self::BYTE_MULTIPLIER_KB, self::FILE_SIZE_PRECISION),
                'megabytes' => round($iFileSize / self::BYTE_MULTIPLIER_MB, self::FILE_SIZE_PRECISION),
                'gigabytes' => round($iFileSize / self::BYTE_MULTIPLIER_GB, self::FILE_SIZE_PRECISION),
                'human'     => static::formatBytes($iFileSize),
            ],
            'hash' => (object) [
                'md5' => $oObj->md5_hash,
            ],
        ];

        unset($oObj->filename);
        unset($oObj->filename_display);
        unset($oObj->mime);
        unset($oObj->filesize);

        // --------------------------------------------------------------------------

        $oObj->bucket = (object) [
            'id'    => (int) $oObj->bucket_id,
            'label' => $oObj->bucket_label,
            'slug'  => $oObj->bucket_slug,
        ];

        unset($oObj->bucket_id);
        unset($oObj->bucket_label);
        unset($oObj->bucket_slug);

        // --------------------------------------------------------------------------

        //  Quick flag for detecting images
        $oObj->is_img = false;

        switch ($oObj->file->mime) {
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/gif':
            case 'image/png':
                $oObj->is_img = true;
                break;
        }
    }
421066
protected function normalizeObject(StorageObject $object)
    {
        $name = $this->removePathPrefix($object->name);
        $mimetype = explode('; ', $object->contentType);

        if ($object->lastModified instanceof \DateTimeInterface) {
            $timestamp = $object->lastModified->getTimestamp();
        } else {
            $timestamp = strtotime($object->lastModified);
        }

        return [
            'type'      => 'file',
            'dirname'   => Util::dirname($name),
            'path'      => $name,
            'timestamp' => $timestamp,
            'mimetype'  => reset($mimetype),
            'size'      => $object->contentLength,
        ];
    }
1020479
public static function ObjectToArray($obj,$fields=[])
    {
        if(is_object($obj)){
            if(empty($fields)){
                return get_object_vars($obj);
            }else{
                $array=[];
                foreach ($fields as $fd){
                    if(property_exists($obj, $fd)){
                        $array[$fd]=$obj->$fd;
                    }
                }
                return $array;
            }
        }
        return [];
    }