Converts the give HAL Resource to a plain text representation that can be returned in the response.

@param string        $format
@param \Hal\Resource $resource

@throws NotAcceptableHttpException

@return string
6995
protected function convertResourceToPlainText($format, Resource $resource)
    {
        switch ($format) {
            case 'xml':
                return (string)$resource->getXML()->asXml();
            case 'json':
                return (string)$resource;
            default:
                throw new NotAcceptableHttpException();
        }
    }
374890
protected function buildOEmbedRequestUrl($resource, $endPoint, $format = self::FORMAT_DEFAULT)
    {
        $parameters = [
            'url' => $resource,
            'format' => $format,
            'version' => self::VERSION
        ];

        if ($this->getRequestParameters() !== null) {
            $parameters = Arrays::arrayMergeRecursiveOverrule($this->getRequestParameters()->toArray(), $parameters);
        }

        $urlParams = http_build_query($parameters, '', '&');
        $url = $endPoint . ((strpos($endPoint, '?') !== false) ? '&' : '?') . $urlParams;

        return $url;
    }
817179
protected function generateImage(string $format): string
    {
        $url = $this->generateUrl($format);

        $content = file_get_contents($url);

        if ($content === false) {
            $content = '';
        }

        return $content;
    }
292055
protected function getFormat($format)
    {
        if ($format === false) {
            $format = 'none';
        }
        
        $types = [
            'none' => \IntlDateFormatter::NONE,
            'short' => \IntlDateFormatter::SHORT,
            'medium' => \IntlDateFormatter::MEDIUM,
            'long' => \IntlDateFormatter::LONG,
            'full' => \IntlDateFormatter::FULL
        ];
        
        return isset($types[$format]) ? $types[$format] : null;
    }
1317111
private function assertValidResource($resource)
    {
        $resource = (string) $resource;
        // All resources are basic ASCII, so we can ignore the fact that `strtolower` doesn't handle UTF-8 well.
        $resource = strtolower($resource);

        if (!in_array($resource, static::VALID_RESOURCES)) {
            throw new InvalidResourceException($resource);
        }

        return $resource;
    }
419749
public function getImage(string $format = null) : string
    {
        if (!$format) {
            $format = $this->instance->getImageFormat();
        }
        switch (strtolower($format)) {
            case 'jpg':
            case 'jpeg':
                $this->instance->setImageFormat('jpg');
                break;
            case 'bitmap':
            case 'bmp':
                $this->instance->setImageFormat('bmp');
                break;
            case 'png':
                $this->instance->setImageFormat('png');
                break;
            case 'gif':
                $this->instance->setImageFormat('gif');
                break;
            case 'webp':
                $this->instance->setImageFormat('webp');
                break;
            default:
                throw new ImageException('Unsupported format');
        }
        return $this->instance->getImageBlob();
    }
962685
public function setFormat($format)
    {
        $result = true;
        if (($this->debug === true) && !empty($this->evidence) && isset(Formats::$$this->evidence)) {
            if (array_key_exists($format, array_flip(Formats::$$this->evidence))
                === false) {
                $result = false;
            }
        }
        if ($result === true) {
            $this->format = $format;
            $this->updateApiURL();
        }
        return $result;
    }
829783
private function decode($format)
    {
        $data = $this->decoder->decode((string) $this->apiContext->getResponse()->getBody(), $format);

        if ($format === 'json' && isset($data['_embedded']['items'])) {
            $data = $data['_embedded']['items'];
        }

        if ($format === 'xml') {
            if (!empty($data) && isset($data['entry'])) {
                if (is_int(key($data['entry']))) {
                    $data = $data['entry'];
                } elseif (isset($data['entry']['@rel'])) {
                    $data = array_pop($data['entry']);
                } else {
                    $data = [$data['entry']];
                }
            } else {
                $data = [];
            }
        }

        return $data;
    }
459994
private function getFormat(array $params, ResponseInterface $response)
    {
        if ($response->hasHeader('content-type')) {
            $header = $response->getHeaderLine('content-type');
            $format = $this->negotiator->getFormat($header);
        }

        if (isset($params['format'])) {
            $format = $params['format'];
        }

        if (!isset($format)) {
            throw new UnknownFormatException('Unable to figure out the format');
        }

        return $format;
    }
58616
function parseResponse($response, $format) {
		if (isset ( $format )) {
			switch ($format) {
				case "pdf" :
					$theResponse = $response;
					break;
				case "json" :
					$theResponse = json_decode ( $response, true );
					break;
				default :
					$theResponse = simplexml_load_string ( $response );
					break;
			}
		}
		return $theResponse;
	}
1163438
public static function fromString(string $format)
    {
        if (preg_match('/^(([^-]|--)+)-(([^-]|--)+)-(([^-]|--)+)\.(svg|png|gif|jpg)$/', $format, $match) === false && (7 != count($match))) {
            throw new InvalidArgumentException('The given format string is invalid: '.$format);
        }

        $subject = $match[1];
        $status = $match[3];
        $color = $match[5];
        $format = $match[7];

        return new self($subject, $status, $color, $format);
    }
871100
public static function encode( $data, $format )
    {
        if(!in_array($format, self::$supported)) return null;
        $formatter = self::$formatMap[$format];
        return forward_static_call(array($formatter, 'encode'), $data);
    }
285980
public function out($format = null)
    {
        if (0 == count($this->url)) {
            throw new Exception('No URL is set');
        }
        if (! is_null($format)) {
            $this->format($format);
        }
        if (is_null($this->response)) {
            $this->call();
        }

        return $this->parseResponse();
    }
453079
public function serialize($data, $format = 'json')
    {
        $jsonContent = $this->getJmsSerializer()->serialize($data, $format);

        return $jsonContent;
    }
676705
private function contentFromData($data, $format)
	{
		$type = gettype($data);
		if($type === 'string')
		{
			$content = $data;
		}
		else if($type === 'array')
		{
			switch ($format) 
			{
				case 'json':
				case 'jsonp':
					$content = json_encode($data);
					break;
				default:
					$content = serialize($data);
					break;
			}
			if($format === 'jsonp')
			{
				$customData = ('string' === gettype($this->customData)) ? $this->customData : 'data';
				if(!empty($_GET))
				{
					$getKeys = array_keys($_GET);
					$customData = $getKeys[0];
				}
				$customData = trim($customData);
				$content = $customData . '(' . $content . ');';
			}
		}
		else 
		{
			$content = serialize($data);
		}
		return $content;
	}
466522
protected function applyCustomFormat($format, $data)
    {
        $aClassFunc = $this->getFuncParams($format);

        $params = array_key_exists(
            'params',
            $format
        ) ? $format['params'] : [];

        array_unshift($params, $data);

        $object = (new \ReflectionClass($aClassFunc['class']))->newInstance();

        $data = call_user_func_array([$object, $aClassFunc['method']], $params);

        return $data;
    }
743180
public function format($format, $value)
    {
        switch ($format) {
            case 'date-time':
                return $this->formatDateTime($value);
            case 'date-time-http':
                return $this->formatDateTimeHttp($value);
            case 'date':
                return $this->formatDate($value);
            case 'time':
                return $this->formatTime($value);
            case 'timestamp':
                return $this->formatTimestamp($value);
            case 'boolean-string':
                return $this->formatBooleanAsString($value);
            default:
                return $value;
        }
    }