Detects format from headers.

@return null|string format name, 'null' - if detection failed
509161
private function detectFormatByHeader()
    {
        $contentTypeHeaders = $this->getHeader('Content-Type');
        if (! empty($contentTypeHeaders)) {
            $contentType = end($contentTypeHeaders);
            if (stripos($contentType, 'json') !== false) {
                return self::FORMAT_JSON;
            }
            if (stripos($contentType, 'urlencoded') !== false) {
                return self::FORMAT_URLENCODED;
            }
            if (stripos($contentType, 'xml') !== false) {
                return self::FORMAT_XML;
            }
        }
    }
19951
public function format($format = null)
    {
        if (func_num_args()) {
            return parent::format($format);
        }
        if ($this->_format === null) {
            $this->negotiate();
        }
        return $this->_format;
    }
728259
public function format($format = '')
    {
        if ($this->isHollow()) {
            $format = $this->format;
        } else {
            $format = $format ?: $this->format;
        }

        return parent::format($format);
    }
920719
public function formatted($isFormatted=null)
    {
        if (isset($isFormatted)) {
            $this->data['formatted'] = $isFormatted;
            return $this;
        }
        
        return isset($this->data['formatted']) ? $this->data['formatted'] : false;
    }
694506
protected function _detectFormat()
    {
        // prepare separator and pattern list
        $sep      = quotemeta($this->_separator);
        $patterns = array();
        $lengths  = array();

        // check for ISBN-10
        if ($this->_type == self::ISBN10 || $this->_type == self::AUTO) {
            if (empty($sep)) {
                $pattern = '/^[0-9]{9}[0-9X]{1}$/';
                $length  = 10;
            } else {
                $pattern = "/^[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9X]{1}$/";
                $length  = 13;
            }

            $patterns[$pattern] = self::ISBN10;
            $lengths[$pattern]  = $length;
        }

        // check for ISBN-13
        if ($this->_type == self::ISBN13 || $this->_type == self::AUTO) {
            if (empty($sep)) {
                $pattern = '/^[0-9]{13}$/';
                $length  = 13;
            } else {
                $pattern = "/^[0-9]{1,9}[{$sep}]{1}[0-9]{1,5}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1}$/";
                $length  = 17;
            }

            $patterns[$pattern] = self::ISBN13;
            $lengths[$pattern]  = $length;
        }

        // check pattern list
        foreach ($patterns as $pattern => $type) {
            if ((strlen($this->_value) == $lengths[$pattern]) && preg_match($pattern, $this->_value)) {
                return $type;
            }
        }

        return null;
    }
374984
public function determine_format() {
        $decimals = $this->item->get_decimals();

        $min = format_float($this->item->grademin, $decimals);
        $max = format_float($this->item->grademax, $decimals);

        return new empty_element("$min - $max");
    }
906909
public function getFormat()
    {
        if ($this->_format === null) {
            $this->_format = $this->defaultFormat();
        }
        return $this->_format;
    }
1058608
public function format($format = null)
    {
        $media = $this->_classes['media'];

        if (!func_num_args()) {
            if ($this->_format === null) {
                $this->_format = $media::suitable($this);
            }
            return $this->_format;
        }
        if ($format === null) {
            return $this;
        }

        if (!$mime = $media::mime($format)){
            throw new NetException("The `'{$format}'` format is undefined or has no valid Content-Type defined check the `Media` class.");
        }
        $this->_format = $format;
        $this->mime($mime);

        return $this;
    }
817691
public function get_header($name = null)
	{
		if (func_num_args())
		{
			return isset($this->headers[$name]) ? $this->headers[$name] : null;
		}
		else
		{
			return $this->headers;
		}
	}
560629
protected function detectFormatByContent($content)
    {
        if (preg_match('/^(\\{|\\[\\{).*(\\}|\\}\\])$/is', $content)) {
            return Client::FORMAT_JSON;
        }
        if (preg_match('/^([^=&])+=[^=&]+(&[^=&]+=[^=&]+)*$/', $content)) {
            return Client::FORMAT_URLENCODED;
        }
        if (preg_match('/^<\?xml.*>$/s', $content)) {
            return Client::FORMAT_XML;
        }
        return null;
    }
1068704
public function format()
    {
        if (strlen($this->phoneNumber) >= 7)
        {
            return sprintf($this->format,
                $this->getCountryCode(),
                $this->getAreaCode(),
                $this->getPrefix(),
                $this->getLineNumber());
        }

        return null;
    }
1293838
private function getFormattedValue(): string
    {
        return (string) is_numeric($this->value) ?
            $this->value :
            sprintf('"%s"', $this->value);
    }
986897
def autodetect_format(content):
    """"""
    formats = set()
    for impl in FORMAT_IDENTIFIER_TO_FORMAT_CLASS.values():
        guess = impl.guess_format(content)
        if guess is not None:
            formats.add(guess)

    if len(formats) == 1:
        return formats.pop()
    elif not formats:
        raise FormatAutodetectionError("No suitable formats")
    else:
        raise FormatAutodetectionError("Multiple suitable formats (%r)" % formats)
56420
protected function _isValidFormat()
	{
		//	Reading 2048 bytes should be enough to validate that the format is HTML
		$data = fread($this->_fileHandle, 2048);
		if ((strpos($data, '<') !== FALSE) &&
			(strlen($data) !== strlen(strip_tags($data)))) {
			return TRUE;
		}

		return FALSE;
	}
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();
    }
1113138
protected function get_header($header = null, $formatted = true)
	{
		if ($header === null)
		{
			return $this->headers;
		}

		if (array_key_exists($header, $this->headers))
		{
			$prefix = ($formatted) ? $header.': ' : '';
			$suffix = ($formatted) ? $this->config['newline'] : '';
			return $prefix.$this->headers[$header].$suffix;
		}

		return '';
	}
1209695
private function getFromAcceptedLanguagesHeader()
    {
        $matches = $this->getMatchesFromAcceptedLanguages();

        if ($locale = $this->inSupportedLocales($matches)) {
            return $locale;
        }

        // If any (i.e. "*") is acceptable, return the first supported locale
        if (isset($matches['*'])) {
            return $this->supportedLocales->first()->key();
        }

        return null;
    }