Returns default format automatically detected from headers and content.

@return string|null format name, 'null' - if detection failed
421906
public function detectFormat()
    {
        $format = $this->detectFormatByHeader();
        if ($format === null) {
            $format = $this->detectFormatByContent((string) $this->getBody());
        }

        return $format;
    }
668001
public function getEncoding()
    {
        $content = $this->getHeaderLine('content-type');
        if (!$content) {
            return null;
        }
        preg_match('/charset\s?=\s?[\'"]?([a-z0-9-_]+)[\'"]?/i', $content, $matches);
        if (empty($matches[1])) {
            return null;
        }

        return $matches[1];
    }
1193367
private function getBaseFormat()
    {
        if ($this->parentCommand) {
            return $this->parentCommand->getArgsFormat();
        }

        if ($this->application) {
            return $this->application->getGlobalArgsFormat();
        }

        return null;
    }
916133
protected function detectFormatByHeaders(HeaderCollection $headers)
    {
        $contentTypeHeaders = $headers->get('content-type', null, false);

        if (!empty($contentTypeHeaders)) {
            $contentType = end($contentTypeHeaders);
            if (stripos($contentType, 'json') !== false) {
                return Client::FORMAT_JSON;
            }
            if (stripos($contentType, 'urlencoded') !== false) {
                return Client::FORMAT_URLENCODED;
            }
            if (stripos($contentType, 'xml') !== false) {
                return Client::FORMAT_XML;
            }
        }

        return null;
    }
39545
private function parseHeadersFormat()
    {
        $headers = array();
        foreach($this->request->getHeaders() as $name => $value)
        {
            $headers[] = $name . ':' . implode(',', $value);
        }
        return $headers;
    }
1268720
public function getFormat()
    {
        $result = null;

        foreach (static::$_formats as $value => $media_types)
        {
            $media_type = $this->getContentType();

            if (in_array($media_type, (array)$media_types))
            {
                $result = $value;
                break;
            }
        }

        return $result;
    }
1002309
public function determine_format() {
        return new text_attribute(
            $this->get_name(),
            $this->get_value(),
            $this->get_label(),
            $this->is_disabled()
        );
    }
430701
public function getMetaDateFormat()
    {
        if ($format = $this->owner->config()->meta_date_format) {
            return $format;
        }
        
        return Config::inst()->get(self::class, 'default_meta_date_format');
    }
244924
public function getFormat() : ?string 
    {
        if ( ! $this->hasFormat()) {
            $this->setFormat($this->getDefaultFormat());
        }
        return $this->format;
    }
278898
protected function getHeadersAsText()
    {
        $headers = '';

        foreach ($this->headers as $header) {
            foreach ($header[1] as $headerValue) {
                $headers .= $header[0] . ': ' . $headerValue . "\r\n";
            }
        }

        return $headers;
    }
450787
protected function getDefaultSubscription()
    {
        if (!$this->defaultSubscription) {
            $this->defaultSubscription = $this->app->make(StandardSubscription::class,
                [self::IDENTIFIER, t('User Deactivated')]);
        }

        return $this->defaultSubscription;
    }
887126
public function getHeader()
    {
        if ($this->hasHeader) {
            return $this->header;
        }

        $this->updateConversion();

        if (!$this->getFilePath()) {
            return $this->header;
        }

        $detectorException = null;

        try {
            $header = $this->detector->header(
                $this->firstLines(),
                $this->getSeparator(),
                $this->getDelimiter()
            );
        } catch (DetectionFailedException $detectorException) {
            $header = [];
        }

        $this->headerWasDetected = $header && !$this->isNumericHeader($header);


        if ($this->headerWasDetected) {
            $this->setHeader($header);
            return $this->header;
        }

        // If the header could not be detected, check for encoding errors
        // These will be thrown also if the header is not forced
        $this->getCharsetGuard()->forceCharset($this->firstLinesRaw(), $this->convertFrom);

        // If we can get here the charsetGuard did not throw an exception
        if ($detectorException) {
            throw $detectorException;
        }

        $this->setHeader([]);

        return $this->header;
    }
256519
public function getDefaultValue()
    {
        if (1 != $this->parameters->get('defaultValueIsNull')) {
            $defaultValue = $this->parameters->get('defaultValue');
            if (strlen($defaultValue) && 'NULL' != $defaultValue) {
                return trim($defaultValue, '\'"');
            }
        }
    }
537132
public function getContentType(): string
    {
        // If the response hasn't been prepared yet, go with what the formatter is going to set
        if (!$this->_isPrepared) {
            switch ($this->format) {
                case self::FORMAT_HTML:
                    return 'text/html';
                case self::FORMAT_XML:
                    return 'application/xml';
                case self::FORMAT_JSON:
                    return 'application/json';
                case self::FORMAT_JSONP:
                    return 'application/javascript';
            }
        }

        // Otherwise check the Content-Type header
        if (($header = $this->getHeaders()->get('content-type')) === null) {
            return null;
        }

        if (($pos = strpos($header, ';')) !== false) {
            $header = substr($header, 0, $pos);
        }

        return strtolower(trim($header));
    }
731701
public function dumpString(): string
    {
        if ($this->header === null) {
            $this->header = new PoHeader;
            $this->header->buildDefaultHeader();
        }
        $output = '';

        $output .= $this->header->dumpEntry();
        foreach ($this->entries as $entry) {
            $output .= $entry->dumpEntry();
        }
        foreach ($this->unkeyedEntries as $entry) {
            $output .= $entry->dumpEntry();
        }
        $output .= "\n";

        return $output;
    }
1333012
public function auto()
    {
        if (strtoupper($this->encoding) === self::ENCODING) {
            return $this->string;
        }
        $errorHandler = new ErrorHandler();
        set_error_handler([$errorHandler, 'callback'], E_NOTICE | E_WARNING);
        foreach ([
                     'intl',
                     'iconv',
                     'xml',
                     'mbstring',
                 ] as $extension) {
            $last = $errorHandler->getLast();
            if (extension_loaded($extension) &&
                ($result = call_user_func([$this, $extension])) !== false &&
                $last === $errorHandler->getLast()
            ) {
                restore_error_handler();
                return $result;
            }
        }
        restore_error_handler();
        return false;
    }
400798
private function prepareDefaultHeaders()
    {
        // Set a default content-disposition header if one was no provided
        if (!$this->hasHeader('Content-Disposition')) {
            $this->headers['Content-Disposition'] = sprintf(
                'form-data; name="%s"; filename="%s"',
                $this->name,
                basename($this->filename)
            );
        }

        // Set a default Content-Type if one was not supplied
        if (!$this->hasHeader('Content-Type')) {
            $this->headers['Content-Type'] = Mimetypes::getInstance()
                ->fromFilename($this->filename) ?: 'text/plain';
        }
    }