public function getFormat()
    {
        if ($this->format !== null) {
            return $this->format;
        }

        $format = $this->default_format;

        if (isset($_SERVER['HTTP_ACCEPT'])) {
            $accept_header = Utilities::sortByPriority($_SERVER['HTTP_ACCEPT']);

            foreach ($accept_header as $mime_type => $priority) {
                if (Format::isMimeTypeSupported($mime_type)) {
                    $format = $mime_type;
                    break;
                }
            }
        }

        // Check for trailing dot-format syntax like /controller/action.format -> action.json
        $override = '';
        if (isset($_SERVER['REQUEST_URI']) && preg_match('/\.(\w+)($|\?)/i', $_SERVER['REQUEST_URI'], $matches)) {
            $override = $matches[1];
        }

        if (Format::getMimeTypeFromFormatAbbreviation($override)) {
            $format = Format::getMimeTypeFromFormatAbbreviation($override);
        }

        $this->format = $format;

        return $format;
    }